IEventReceiver.h

本文介绍了Irrlicht引擎中的事件处理机制,包括GUI事件、鼠标事件、键盘事件等类型。详细解释了不同类型的事件如何在系统中传递,并提供了各种事件的具体结构说明。

/*

* IEventReceiver.h

*

* Created on: 2010-10-11

* Author: Mido

* 事件接收器

* - GUI控件事件、鼠标事件、按键事件、日志事件、用户自定义事件

* - 来自于大哥irrlicht

*/

 

#ifndef IEVENTRECEIVER_H_

#define IEVENTRECEIVER_H_

 

#include "ILogger.h"

#include "KeyCodes.h"

 

namespace irrlight

{

 

//! Enumeration for all event types there are.

enum EEVENT_TYPE

{

//! An event of the graphical user interface.

/** GUI events are created by the GUI environment or the GUI elements in response

to mouse or keyboard events. When a GUI element receives an event it will either

process it and return true, or pass the event to its parent. If an event is not absorbed

before it reaches the root element then it will then be passed to the user receiver. */

EET_GUI_EVENT = 0,

 

//! A mouse input event.

/** Mouse events are created by the device and passed to IrrLightDevice::postEventFromUser

in response to mouse input received from the operating system.

Mouse events are first passed to the user receiver, then to the GUI environment and its elements,

then finally the input receiving scene manager where it is passed to the active camera.

*/

EET_MOUSE_INPUT_EVENT,

 

//! A key input event.

/** Like mouse events, keyboard events are created by the device and passed to

IrrLightDevice::postEventFromUser. They take the same path as mouse events. */

EET_KEY_INPUT_EVENT,

 

//! A joystick (joypad, gamepad) input event.

/** Joystick events are created by polling all connected joysticks once per

device run() and then passing the events to IrrLightDevice::postEventFromUser.

They take the same path as mouse events.

Windows, SDL: Implemented.

Linux: Implemented, with POV hat issues.

MacOS / Other: Not yet implemented.

*/

//EET_JOYSTICK_INPUT_EVENT,

 

//! A log event

/** Log events are only passed to the user receiver if there is one. If they are absorbed by the

user receiver then no text will be sent to the console. */

EET_LOG_TEXT_EVENT,

 

//! A user event with user data.

/** This is not used by IrrLight and can be used to send user

specific data though the system. The IrrLight 'window handle'

can be obtained from IrrLightDevice::getExposedVideoData()

The usage and behaviour depends on the operating system:

Windows: send a WM_USER message to the IrrLight Window; the

wParam and lParam will be used to populate the

UserData1 and UserData2 members of the SUserEvent.

Linux: send a ClientMessage via XSendEvent to the IrrLight

Window; the data.l[0] and data.l[1] members will be

casted to s32 and used as UserData1 and UserData2.

MacOS: Not yet implemented

*/

EET_USER_EVENT,

 

//! This enum is never used, it only forces the compiler to

//! compile these enumeration values to 32 bit.

EGUIET_FOIRRE_32_BIT = 0x7fffffff

 

};

 

//! Enumeration for all mouse input events

enum EMOUSE_INPUT_EVENT

{

//! Left mouse button was pressed down.

EMIE_LMOUSE_PRESSED_DOWN = 0,

 

//! Right mouse button was pressed down.

EMIE_RMOUSE_PRESSED_DOWN,

 

//! Middle mouse button was pressed down.

EMIE_MMOUSE_PRESSED_DOWN,

 

//! Left mouse button was left up.

EMIE_LMOUSE_LEFT_UP,

 

//! Right mouse button was left up.

EMIE_RMOUSE_LEFT_UP,

 

//! Middle mouse button was left up.

EMIE_MMOUSE_LEFT_UP,

 

//! The mouse cursor changed its position.

EMIE_MOUSE_MOVED,

 

//! The mouse wheel was moved. Use Wheel value in event data to find out

//! in what direction and how fast.

EMIE_MOUSE_WHEEL,

 

//! No real event. Just for convenience to get number of events

EMIE_COUNT

};

 

namespace gui

{

 

class IGUIElement;

 

//! Enumeration for all events which are sendable by the gui system

enum EGUI_EVENT_TYPE

{

//! A gui element has lost its focus.

/** GUIEvent.Caller is losing the focus to GUIEvent.Element.

If the event is absorbed then the focus will not be changed. */

EGET_ELEMENT_FOCUS_LOST = 0,

 

//! A gui element has got the focus.

/** If the event is absorbed then the focus will not be changed. */

EGET_ELEMENT_FOCUSED,

 

//! The mouse cursor hovered over a gui element.

EGET_ELEMENT_HOVERED,

 

//! The mouse cursor left the hovered element.

EGET_ELEMENT_LEFT,

 

//! An element would like to close.

/** Windows and context menus use this event when they would like to close,

this can be cancelled by absorbing the event. */

EGET_ELEMENT_CLOSED,

 

//! A button was clicked.

EGET_BUTTON_CLICKED,

 

//! A scrollbar has changed its position.

EGET_SCROLL_BAR_CHANGED,

 

//! A checkbox has changed its check state.

EGET_CHECKBOX_CHANGED,

 

//! A new item in a listbox was seleted.

EGET_LISTBOX_CHANGED,

 

//! An item in the listbox was selected, which was already selected.

EGET_LISTBOX_SELECTED_AGAIN,

 

//! A file has been selected in the file dialog

EGET_FILE_SELECTED,

 

//! A file open dialog has been closed without choosing a file

EGET_FILE_CHOOSE_DIALOG_CANCELLED,

 

//! 'Yes' was clicked on a messagebox

EGET_MESSAGEBOX_YES,

 

//! 'No' was clicked on a messagebox

EGET_MESSAGEBOX_NO,

 

//! 'OK' was clicked on a messagebox

EGET_MESSAGEBOX_OK,

 

//! 'Cancel' was clicked on a messagebox

EGET_MESSAGEBOX_CANCEL,

 

//! In an editbox was pressed 'ENTER'

EGET_EDITBOX_ENTER,

 

//! The tab was changed in an tab control

EGET_TAB_CHANGED,

 

//! A menu item was selected in a (context) menu

EGET_MENU_ITEM_SELECTED,

 

//! The selection in a combo box has been changed

EGET_COMBO_BOX_CHANGED,

 

//! The value of a spin box has changed

EGET_SPINBOX_CHANGED,

//! A table has changed

EGET_TABLE_CHANGED,

EGET_TABLE_HEADER_CHANGED,

EGET_TABLE_SELECTED_AGAIN,

 

//! .Mido.2010.9.28

//! The value of WaitDialog cancel

EGET_WAITDIALOG_CANCEL,

EGET_WAITDIALOG_TIMEOUT

};

 

} // end namespace gui

 

//! SEvents hold information about an event. See IrrLight::IEventReceiver for details on event handling.

struct SEvent

{

//! Any kind of GUI event.

struct SGUIEvent

{

//! IGUIElement who called the event

gui::IGUIElement* Caller;

 

//! If the event has something to do with another element, it will be held here.

gui::IGUIElement* Element;

 

//! Type of GUI Event

gui::EGUI_EVENT_TYPE EventType;

 

};

 

//! Any kind of mouse event.

struct SMouseInput

{

//! X position of mouse cursor

s32 X;

 

//! Y position of mouse cursor

s32 Y;

 

//! mouse wheel delta, usually 1.0 or -1.0.

/** Only valid if event was EMIE_MOUSE_WHEEL */

f32 Wheel;

 

//! Type of mouse event

EMOUSE_INPUT_EVENT Event;

};

 

//! Any kind of keyboard event.

struct SKeyInput

{

//! Character corresponding to the key (0, if not a character)

c16 Char;

 

//! Key which has been pressed or released

EKEY_CODE Key;

 

//! If not true, then the key was left up

b1 PressedDown;

 

//! True if shift was also pressed

b1 Shift;

 

//! True if ctrl was also pressed

b1 Control;

};

 

//! A joystick event.

/** Unlike other events, joystick events represent the result of polling

* each connected joystick once per run() of the device. Joystick events will

* not be generated by default. If joystick support is available for the

* active device, _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ is defined, and

* @ref IrrLightDevice::activateJoysticks() has been called, an event of

* this type will be generated once per joystick per @ref IrrLightDevice::run()

* regardless of whether the state of the joystick has actually changed. */

struct SJoystickEvent

{

enum

{

NUMBER_OF_BUTTONS = 32,

 

AXIS_X = 0, // e.g. analog stick 1 left to right

AXIS_Y, // e.g. analog stick 1 top to bottom

AXIS_Z, // e.g. throttle, or analog 2 stick 2 left to right

AXIS_R, // e.g. rudder, or analog 2 stick 2 top to bottom

AXIS_U,

AXIS_V,

NUMBER_OF_AXES

};

 

/** A bitmap of button states. You can use IsButtonPressed() to

( check the state of each button from 0 to (NUMBER_OF_BUTTONS - 1) */

u32 ButtonStates;

 

/** For AXIS_X, AXIS_Y, AXIS_Z, AXIS_R, AXIS_U and AXIS_V

* Values are in the range -32768 to 32767, with 0 representing

* the center position. You will receive the raw value from the

* joystick, and so will usually want to implement a dead zone around

* the center of the range. Axes not supported by this joystick will

* always have a value of 0. On Linux, POV hats are represented as axes,

* usually the last two active axis.

*/

s16 Axis[NUMBER_OF_AXES];

 

/** The POV represents the angle of the POV hat in degrees * 100,

* from 0 to 35,900. A value of 65535 indicates that the POV hat

* is centered (or not present).

* This value is only supported on Windows. On Linux, the POV hat

* will be sent as 2 axes instead. */

u16 POV;

 

//! The ID of the joystick which generated this event.

/** This is an internal IrrLight index; it does not map directly

* to any particular hardware joystick. */

u8 Joystick;

 

//! A helper function to check if a button is pressed.

b1 IsButtonPressed(u32 button) const

{

if(button >= (u32)NUMBER_OF_BUTTONS)

return bf;

 

return (ButtonStates & (1 << button)) ? bt : bf;

}

};

 

 

//! Any kind of log event.

struct SLogEvent

{

//! Pointer to text which has been logged

const c8* Text;

 

//! Log level in which the text has been logged

ELOG_LEVEL Level;

};

 

//! Any kind of user event.

struct SUserEvent

{

//! Some user specified data as int

s32 UserData1;

 

//! Another user specified data as int

s32 UserData2;

};

 

EEVENT_TYPE EventType;

union

{

struct SGUIEvent GUIEvent;

struct SMouseInput MouseInput;

struct SKeyInput KeyInput;

struct SJoystickEvent JoystickEvent;

struct SLogEvent LogEvent;

struct SUserEvent UserEvent;

};

 

};

 

//! Interface of an object which can receive events.

/** Many of the engine's classes inherit IEventReceiver so they are able to

process events. Events usually start at a postEventFromUser function and are

passed down through a chain of event receivers until OnEvent returns true. See

IrrLight::EEVENT_TYPE for a description of where each type of event starts, and the

path it takes through the system. */

class IEventReceiver

{

public:

//! Constructor 

IEventReceiver(){}

 

//! Destructor

virtual ~IEventReceiver() {}

 

//! Called if an event happened.

/** /return True if the event was processed. */

virtual b1 OnEvent(const SEvent& e) = 0;

};

 

} // end namespace IrrLight

 

#endif /* IEVENTRECEIVER_H_ */

 

 

 

本文来自:鬼火神灯- irrlight.com

内容概要:本文介绍了ENVI Deep Learning V1.0的操作教程,重点讲解了如何利用ENVI软件进行深度学习模型的训练与应用,以实现遥感图像中特定目标(如集装箱)的自动提取。教程涵盖了从数据准备、标签图像创建、模型初始化与训练,到执行分类及结果优化的完整流程,并介绍了精度评价与通过ENVI Modeler实现一键化建模的方法。系统基于TensorFlow框架,采用ENVINet5(U-Net变体)架构,支持通过点、线、面ROI或分类图生成标签数据,适用于多/高光谱影像的单一类别特征提取。; 适合人群:具备遥感图像处理基础,熟悉ENVI软件操作,从事地理信息、测绘、环境监测等相关领域的技术人员或研究人员,尤其是希望将深度学习技术应用于遥感目标识别的初学者与实践者。; 使用场景及目标:①在遥感影像中自动识别和提取特定地物目标(如车辆、建筑、道路、集装箱等);②掌握ENVI环境下深度学习模型的训练流程与关键参数设置(如Patch Size、Epochs、Class Weight等);③通过模型调优与结果反馈提升分类精度,实现高效自动化信息提取。; 阅读建议:建议结合实际遥感项目边学边练,重点关注标签数据制作、模型参数配置与结果后处理环节,充分利用ENVI Modeler进行自动化建模与参数优化,同时注意软硬件环境(特别是NVIDIA GPU)的配置要求以保障训练效率。
内容概要:本文系统阐述了企业新闻发稿在生成式引擎优化(GEO)时代下的全渠道策略与效果评估体系,涵盖当前企业传播面临的预算、资源、内容与效果评估四大挑战,并深入分析2025年新闻发稿行业五大趋势,包括AI驱动的智能化转型、精准化传播、首发内容价值提升、内容资产化及数据可视化。文章重点解析央媒、地方官媒、综合门户和自媒体四类媒体资源的特性、传播优势与发稿策略,提出基于内容适配性、时间节奏、话题设计的策略制定方法,并构建涵盖品牌价值、销售转化与GEO优化的多维评估框架。此外,结合“传声港”工具实操指南,提供AI智能投放、效果监测、自媒体管理与舆情应对的全流程解决方案,并针对科技、消费、B2B、区域品牌四大行业推出定制化发稿方案。; 适合人群:企业市场/公关负责人、品牌传播管理者、数字营销从业者及中小企业决策者,具备一定媒体传播经验并希望提升发稿效率与ROI的专业人士。; 使用场景及目标:①制定科学的新闻发稿策略,实现从“流量思维”向“价值思维”转型;②构建央媒定调、门户扩散、自媒体互动的立体化传播矩阵;③利用AI工具实现精准投放与GEO优化,提升品牌在AI搜索中的权威性与可见性;④通过数据驱动评估体系量化品牌影响力与销售转化效果。; 阅读建议:建议结合文中提供的实操清单、案例分析与工具指南进行系统学习,重点关注媒体适配性策略与GEO评估指标,在实际发稿中分阶段试点“AI+全渠道”组合策略,并定期复盘优化,以实现品牌传播的长期复利效应。
要实现网页利用鼠标键盘事件操作后台 WinForm,可采用以下几种方法: ### 1. 使用 WebSocket 通信 WebSocket 能在网页和 WinForm 应用程序间建立实时双向通信连接。在网页端,可监听鼠标和键盘事件,将事件信息通过 WebSocket 发送到 WinForm 应用程序。WinForm 应用程序接收这些信息后,执行相应操作。 #### 网页端代码示例(JavaScript) ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> const socket = new WebSocket('ws://localhost:8080'); document.addEventListener('keydown', function (event) { const message = { type: 'keyboard', key: event.key }; socket.send(JSON.stringify(message)); }); document.addEventListener('mousedown', function (event) { const message = { type: 'mouse', action: 'down', x: event.clientX, y: event.clientY }; socket.send(JSON.stringify(message)); }); </script> </body> </html> ``` #### WinForm 端代码示例(C#) ```csharp using System; using System.Net; using System.Net.WebSockets; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormWebSocketServer { public partial class Form1 : Form { private HttpListener listener; private CancellationTokenSource cts; public Form1() { InitializeComponent(); StartWebSocketServer(); } private async void StartWebSocketServer() { listener = new HttpListener(); listener.Prefixes.Add("http://localhost:8080/"); listener.Start(); cts = new CancellationTokenSource(); while (!cts.IsCancellationRequested) { var context = await listener.GetContextAsync(); if (context.Request.IsWebSocketRequest) { var webSocketContext = await context.AcceptWebSocketAsync(null); await HandleWebSocketConnection(webSocketContext.WebSocket); } else { context.Response.StatusCode = 400; context.Response.Close(); } } } private async Task HandleWebSocketConnection(WebSocket webSocket) { var buffer = new byte[1024]; var receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None); while (!receiveResult.CloseStatus.HasValue) { var message = Encoding.UTF8.GetString(buffer, 0, receiveResult.Count); // 解析消息并执行相应操作 // 这里只是简单示例,可根据实际需求扩展 Console.WriteLine($"Received: {message}"); receiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None); } await webSocket.CloseAsync(receiveResult.CloseStatus.Value, receiveResult.CloseStatusDescription, CancellationToken.None); } } } ``` ### 2. 使用 HTTP 请求 网页可通过发送 HTTP 请求到 WinForm 应用程序提供的 Web API 接口,将鼠标和键盘事件信息传递给 WinForm 应用程序。WinForm 应用程序接收到请求后,解析信息并执行相应操作。 #### 网页端代码示例(JavaScript) ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> document.addEventListener('keydown', function (event) { const data = { type: 'keyboard', key: event.key }; fetch('http://localhost:5000/api/events', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); }); document.addEventListener('mousedown', function (event) { const data = { type: 'mouse', action: 'down', x: event.clientX, y: event.clientY }; fetch('http://localhost:5000/api/events', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); }); </script> </body> </html> ``` #### WinForm 端代码示例(C#,使用 ASP.NET Core Web API) ```csharp using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; using System; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormWebAPI { public partial class Form1 : Form { private IHost host; public Form1() { InitializeComponent(); StartWebAPI(); } private void StartWebAPI() { host = Host.CreateDefaultBuilder() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseUrls("http://localhost:5000"); webBuilder.Configure(app => { app.Run(async context => { if (context.Request.Path == "/api/events" && context.Request.Method == "POST") { var requestBody = await new System.IO.StreamReader(context.Request.Body).ReadToEndAsync(); var eventData = JsonConvert.DeserializeObject<dynamic>(requestBody); // 解析事件数据并执行相应操作 // 这里只是简单示例,可根据实际需求扩展 Console.WriteLine($"Received event: {eventData.type}"); context.Response.StatusCode = 200; } else { context.Response.StatusCode = 404; } }); }); }) .Build(); host.Start(); } } } ``` ### 3. 使用 COM 组件 WinForm 应用程序可创建 COM 组件,网页通过 JavaScript 调用 COM 组件的方法,将鼠标和键盘事件信息传递给 WinForm 应用程序。不过,这种方法需要用户在浏览器中启用 ActiveX 控件,存在一定安全风险,且只支持特定浏览器。 #### WinForm 端创建 COM 组件示例(C#) ```csharp using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WinFormCOMComponent { [ComVisible(true)] [Guid("12345678-1234-5678-1234-56789ABCDEFG")] public interface IEventReceiver { void HandleKeyboardEvent(string key); void HandleMouseEvent(string action, int x, int y); } [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] [Guid("87654321-4321-8765-4321-ABCDEFG12345")] public class EventReceiver : IEventReceiver { public void HandleKeyboardEvent(string key) { // 处理键盘事件 MessageBox.Show($"Received keyboard event: {key}"); } public void HandleMouseEvent(string action, int x, int y) { // 处理鼠标事件 MessageBox.Show($"Received mouse event: {action} at ({x}, {y})"); } } } ``` #### 网页端调用 COM 组件示例(JavaScript) ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> try { var eventReceiver = new ActiveXObject("WinFormCOMComponent.EventReceiver"); document.addEventListener('keydown', function (event) { eventReceiver.HandleKeyboardEvent(event.key); }); document.addEventListener('mousedown', function (event) { eventReceiver.HandleMouseEvent('down', event.clientX, event.clientY); }); } catch (error) { console.error('Failed to create ActiveXObject: ' + error.message); } </script> </body> </html> ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值