Skyline基本操作模式封装
skyline基本操作模式
项目中基于skyline的浏览器插件进行二次开发,基本的业务操作模式如下:
- 工具栏:点击工具栏某个功能,开启操作模式。
- onFrame:鼠标移动预选对象,在能够拾取或者选定操作的Fature对象上,改变渲染色彩。
- OnLButtonUp:左键单击选定对象,在onFrame渲染对象的基础上,选定某个对象,并用不同于OnFrame的渲染色彩,再次渲染。同时,执行业务操作,查询数据并弹出窗口或者其他。
- OnRButtonUp:右击结束当前操作模式,取消事件监听、取消对象渲染、移除业务窗口等。
其中涉及到很多重复性的代码:
- 事件绑定与取消绑定
/**
* 事件绑定
* @returns {}
*/
mouseModel.Attach = function () {
mouseModel.sgworld.AttachEvent("OnFrame", mouseModel.onPointSelectOnFrame);
mouseModel.sgworld.AttachEvent("OnLButtonUp", mouseModel.onPointSelectLButtonUp);
mouseModel.sgworld.AttachEvent("OnRButtonUp", mouseModel.onPointSelectRButtonUp);
mouseModel.sgworld.Window.SetInputMode(1);
}
/**
* 解除绑定
* @returns {}
*/
mouseModel.Detach = function() {
mouseModel.sgworld.DetachEvent("OnLButtonUp", mouseModel.onPointSelectLButtonUp);
mouseModel.sgworld.DetachEvent("OnRButtonUp", mouseModel.onPointSelectRButtonUp);
mouseModel.sgworld.DetachEvent("OnFrame", mouseModel.onPointSelectOnFrame);
mouseModel.sgworld.Window.SetInputMode(0);
}
- OnRButtonUp事件处理逻辑基本一致
mouseModel.onPointSelectRButtonUp = function () {
mouseModel.Detach();
if (mouseModel.lButtonFeature != null && mouseModel.lButtonFeature.Tint != null) {
mouseModel.lButtonFeature.Tint.SetAlpha(0);
mouseModel.lButtonFeature = null;
}
if (mouseModel.frameFeature != null && mouseModel.frameFeature.Tint != null) {
mouseModel.frameFeature.Tint.SetAlpha(0);
mouseModel.frameFeature = null;
}
//可能的业务处理逻辑
...
return true;
}
- OnFrame事件处理逻辑基本一致
mouseModel.onPointSelectOnFrame = function () {
var mouseInfo = mouseModel.sgworld.Window.GetMouseInfo();
var position = mouseModel.sgworld.Window.PixelToWorld(mouseInfo.X, mouseInfo.Y);
if (position.Type === 8192 || position.Type === 4 || position.Type === 1) {
try {
if (mouseModel.frameFeature != null && (mouseModel.frameFeature.ObjectType === 33 || mouseModel.frameFeature.ObjectType === 38)) {
mouseModel.frameFeature.Tint.SetAlpha(0);
}
//标记元素不再渲染
if (mouseModel.lButtonFeature == null || position.ObjectID !== mouseModel.lButtonFeature.ID) {
mouseModel.frameFeature = sgworld.Creator.GetObject(position.ObjectID);
mouseModel.frameFeature.Tint.abgrColor = 0x8f0000f0;
}
} catch (e) {
}
}
}
- OnLButtonUp事件Feature判断处理逻辑一致
mouseModel.onPointSelectLButtonUp = function () {
var mouseInfo = mouseModel.sgworld.Window.GetMouseInfo();
var position = mouseModel.sgworld.Window.PixelToWorld(mouseInfo.X, mouseInfo.Y);
if (position.Type === 8192 || position.Type === 4 || position.Type === 1 || position.Type === 1228
|| position.Type === 12288) {
try {
if (!mouseModel.frameFeature) return true;
if (mouseModel.lButtonFeature != null && (mouseModel.lButtonFeature.ObjectType === 33 || mouseModel.lButtonFeature.ObjectType === 38)) {
mouseModel.lButtonFeature.Tint.SetAlpha(0);
}
mouseModel.lButtonFeature = mouseModel.frameFeature;
mouseModel.frameFeature = null;
//设置16进制颜色值
mouseModel.lButtonFeature.Tint.abgrColor = 0x8f00f0f0;
//业务处理
...
} catch (e) {
return false;
}
}
return true;
}
操作模式封装
因此基于项目中已经存在的大量重复代码的共性,对这种操作模式进行封装,方便部分操作逻辑的统一,以后后续扩展的便捷。
function MouseMode(args) {
var mouseModel = {};
mouseModel.sgworld = args.sgworld;
//左键处理逻辑回调
mouseModel.lButtonUpCallback = args.lButtonUpCallback;
//右键处理逻辑回调
mouseModel.rButtonUpCallback = args.rButtonUpCallback;
//左键选定Feature
mouseModel.lButtonFeature = null;
//frame预选Feature
mouseModel.frameFeature = null;
/**
* 事件绑定
* @returns {}
*/
mouseModel.Attach = function () {
mouseModel.sgworld.AttachEvent("OnFrame", mouseModel.onPointSelectOnFrame);
mouseModel.sgworld.AttachEvent("OnLButtonUp", mouseModel.onPointSelectLButtonUp);
mouseModel.sgworld.AttachEvent("OnRButtonUp", mouseModel.onPointSelectRButtonUp);
mouseModel.sgworld.Window.SetInputMode(1);
}
/**
* 解除绑定
* @returns {}
*/
mouseModel.Detach = function() {
mouseModel.sgworld.DetachEvent("OnLButtonUp", mouseModel.onPointSelectLButtonUp);
mouseModel.sgworld.DetachEvent("OnRButtonUp", mouseModel.onPointSelectRButtonUp);
mouseModel.sgworld.DetachEvent("OnFrame", mouseModel.onPointSelectOnFrame);
mouseModel.sgworld.Window.SetInputMode(0);
}
/**
* 右键处理
* @returns {}
*/
mouseModel.onPointSelectRButtonUp = function () {
mouseModel.Detach();
if (mouseModel.lButtonFeature != null && mouseModel.lButtonFeature.Tint != null) {
mouseModel.lButtonFeature.Tint.SetAlpha(0);
mouseModel.lButtonFeature = null;
}
if (mouseModel.frameFeature != null && mouseModel.frameFeature.Tint != null) {
mouseModel.frameFeature.Tint.SetAlpha(0);
mouseModel.frameFeature = null;
}
//可能的业务回调
if (mouseModel.rButtonUpCallback) {
mouseModel.rButtonUpCallback();
}
return true;
}
/**
* 左键处理
* @returns {}
*/
mouseModel.onPointSelectLButtonUp = function () {
var mouseInfo = mouseModel.sgworld.Window.GetMouseInfo();
var position = mouseModel.sgworld.Window.PixelToWorld(mouseInfo.X, mouseInfo.Y);
if (position.Type === 8192 || position.Type === 4 || position.Type === 1 || position.Type === 1228
|| position.Type === 12288) {
try {
if (!mouseModel.frameFeature) return true;
if (mouseModel.lButtonFeature != null && (mouseModel.lButtonFeature.ObjectType === 33 || mouseModel.lButtonFeature.ObjectType === 38)) {
mouseModel.lButtonFeature.Tint.SetAlpha(0);
}
mouseModel.lButtonFeature = mouseModel.frameFeature;
mouseModel.frameFeature = null;
//设置16进制颜色值
mouseModel.lButtonFeature.Tint.abgrColor = 0x8f00f0f0;
//业务回调
if (mouseModel.lButtonUpCallback) {
mouseModel.lButtonUpCallback(mouseModel.sgworld, mouseModel.lButtonFeature, mouseModel.frameFeature);
}
} catch (e) {
return false;
}
}
return true;
}
mouseModel.onPointSelectOnFrame = function () {
var mouseInfo = mouseModel.sgworld.Window.GetMouseInfo();
var position = mouseModel.sgworld.Window.PixelToWorld(mouseInfo.X, mouseInfo.Y);
if (position.Type === 8192 || position.Type === 4 || position.Type === 1) {
try {
if (mouseModel.frameFeature != null && (mouseModel.frameFeature.ObjectType === 33 || mouseModel.frameFeature.ObjectType === 38)) {
mouseModel.frameFeature.Tint.SetAlpha(0);
}
//左键选定元素不再渲染
if (mouseModel.lButtonFeature == null || position.ObjectID !== mouseModel.lButtonFeature.ID) {
mouseModel.frameFeature = sgworld.Creator.GetObject(position.ObjectID);
mouseModel.frameFeature.Tint.abgrColor = 0x8f0000f0;
}
} catch (e) {
}
}
}
mouseModel.Attach();
return mouseModel;
}
使用方式
var mouseMode = new MouseMode({
sgworld: sgworld,
lButtonUpCallback: function (sgworld, feature, lastFeature) {
//业务处理代码
},
rButtonUpCallback: function () {
//业务处理代码
}
});
这样是不是简单了许多,这里统一了onFrame和LButtonUp时Feature渲染色彩,开放了LButtonUp和RButtonUp时业务处理逻辑。
其实,这个封装之前就写好了,但是奈何skyline调试的复杂性,有几个问题一直没有解决,今天再次翻出来,一一搞定,真的是时间是解决一切问题的利器呀,还是凉拌好。终于删除一大堆我讨厌的代码了!!!
Skyline基本操作模式封装的更多相关文章
- HeadFirst设计模式笔记:(六)命令模式 —— 封装调用
1.概念 将来自客户端的请求传入一个对象,从而使你可用不同的请求对客户进行参数化.用于“行为请求者”与“行为实现者”解耦,可实现二者之间的松耦合,以便适应变化.分离变化与不变的因素. 在面向对象的程序 ...
- 【Android】策略模式封装百度地图路线规划模块
百度地图的Demo里有个路线规划的功能,但是,这个功能和Activity耦合性太高,所以需要单独抽离出路径规划功能,进行"解耦". 注:由于项目原因,本文只针对驾车路线规划进行封装 ...
- js原生设计模式——9外观模式封装
1.事件处理程序兼容性封装 <!DOCTYPE html><html lang="en"><head> <meta charset= ...
- js原生设计模式——3简单工厂模式\简单工厂模式封装简单对象
1.Factory基本写法 <!DOCTYPE html><html lang="en"><head> <meta charset= ...
- PO页面对象模式封装
PO的主要价值体现在对界面交互细节的封装,这样可以使测试案例可以更关注与业务而非界面细节,提高测试案例的可读性. 以传统的登陆页面为例實現PO模式,因为每个用例中都需要登陆. 其中需要使用Page ...
- Facade 门面模式 封装 MD
门面模式 简介 作用:封装系统功能,简化系统调用 门面模式要求一个系统的外部与其内部的通信必须通过一个统一的门面(Facade)对象进行.门面模式提供一个高层次的接口,使得系统更易于使用. 门面模式的 ...
- 使用.net中的API网关模式封装微服务
在本文中,我们将了解如何使用API网关模式来封装微服务并抽象出底层实现细节,从而允许使用者拥有进入我们系统的一致入口点. 为了构建和测试我们的应用程序,我们需要: 1.Visual Studio 20 ...
- js原生设计模式——9外观模式封装2(小型代码库YJ)
<script type="text/javascript"> //小型代码库YJ封装 var YJ = { //根据id获取元素 ...
- Wpf+数据库代码封装+策略模式封装
运行界面: 数据库保存的题: 数据库封装代码: using System; using System.Collections.Generic; using System.Linq; using Sys ...
随机推荐
- asp.net core系列 48 Identity 身份模型自定义
一.概述 ASP.NET Core Identity提供了一个框架,用于管理和存储在 ASP.NET Core 应用中的用户帐户. Identity添加到项目时单个用户帐户选择作为身份验证机制. 默认 ...
- SpringBoot进阶教程(二十九)整合Redis 发布订阅
SUBSCRIBE, UNSUBSCRIBE 和 PUBLISH 实现了 发布/订阅消息范例,发送者 (publishers) 不用编程就可以向特定的接受者发送消息 (subscribers). Ra ...
- Cenots7下安装运行.NET Core、MicroSoft SQL Server 2019 preview 的基础实践
一:概要 适应人群:.Net初学者.想了解.Net Core在Linux系统中的运行环境搭建者.初次且想在linux上应用.Net Core开发应用程序者: 基础技能:了解.NET基础开发技能者.有一 ...
- xss攻击和csrf攻击的定义及区别
1.CSRF的基本概念.缩写.全称 CSRF(Cross-site request forgery):跨站请求伪造. PS:中文名一定要记住.英文全称,如果记不住也拉倒. 2.CSRF的攻击原理 用户 ...
- 只用最适合的!全面对比主流 .NET 报表控件
本文由葡萄城技术团队于博客园原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 随着 .NET 平台的出现,报表相关的开发控件随着而来,已经有 ...
- 【转载】Sqlserver数据库备份的几种方式
在实际的数据库Sqlserver的运维的过程中,很多时候我们需要做到数据的备份操作,可以做到定时备份,也可以进行手动数据库备份.在实际的过程中,有时候因业务需要备份出完整数据库,而有时候又因为实际业务 ...
- 有人WIFI模块使用详解
补充 模块在连接路由器时如果希望模块固定IP 不过发现固定IP之后好像连接路由器的等待时间增加了 用的这一款 看一下现在可能用到了引脚 这个模块也有三种模式AP,STA,AP+STA 先说一下模块在A ...
- 机器学习 ML.NET 发布 1.0 RC
ML.NET 是面向.NET开发人员的开源和跨平台机器学习框架(Windows,Linux,macOS),通过使用ML.NET,.NET开发人员可以利用他们现有的工具和技能组,为情感分析,推荐,图像分 ...
- 广州 office365的开发者训练营交流活动简报
2018年10月13日,在 微软广州办公室(广州市天河区太古汇1座28层微软广州办公室) 成功举办了office365的开发者训练营,本活动在微软官网的地址: https://www.microsof ...
- 基于python语言的tensorflow的‘端到端’的字符型验证码识别源码整理(github源码分享)
基于python语言的tensorflow的‘端到端’的字符型验证码识别 1 Abstract 验证码(CAPTCHA)的诞生本身是为了自动区分 自然人 和 机器人 的一套公开方法, 但是近几年的 ...