From: Ketmar Dark Date: Wed, 4 Oct 2017 13:37:20 +0000 (+0300) Subject: FlexUI: event types renamed from `^TH*` to `TFUI*`; some simplifications in event... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=772128d5e2cfed3d8abbb325573a1c873d4fd912;p=d2df-sdl.git FlexUI: event types renamed from `^TH*` to `TFUI*`; some simplifications in event checking code --- diff --git a/src/flexui/fui_ctls.pas b/src/flexui/fui_ctls.pas index 50a73f1..27f14fd 100644 --- a/src/flexui/fui_ctls.pas +++ b/src/flexui/fui_ctls.pas @@ -230,10 +230,10 @@ type procedure doAction (); virtual; // so user controls can override it - procedure mouseEvent (var ev: THMouseEvent); virtual; // returns `true` if event was eaten - procedure keyEvent (var ev: THKeyEvent); virtual; // returns `true` if event was eaten - procedure keyEventPre (var ev: THKeyEvent); virtual; // will be called before dispatching the event - procedure keyEventPost (var ev: THKeyEvent); virtual; // will be called after if nobody processed the event + procedure mouseEvent (var ev: TFUIMouseEvent); virtual; // returns `true` if event was eaten + procedure keyEvent (var ev: TFUIKeyEvent); virtual; // returns `true` if event was eaten + procedure keyEventPre (var ev: TFUIKeyEvent); virtual; // will be called before dispatching the event + procedure keyEventPost (var ev: TFUIKeyEvent); virtual; // will be called after if nobody processed the event function prevSibling (): TUIControl; function nextSibling (): TUIControl; @@ -306,8 +306,8 @@ type procedure drawControl (gx, gy: Integer); override; procedure drawControlPost (gx, gy: Integer); override; - procedure keyEvent (var ev: THKeyEvent); override; // returns `true` if event was eaten - procedure mouseEvent (var ev: THMouseEvent); override; // returns `true` if event was eaten + procedure keyEvent (var ev: TFUIKeyEvent); override; // returns `true` if event was eaten + procedure mouseEvent (var ev: TFUIMouseEvent); override; // returns `true` if event was eaten public property freeOnClose: Boolean read mFreeOnClose write mFreeOnClose; @@ -334,8 +334,8 @@ type procedure drawControl (gx, gy: Integer); override; - procedure mouseEvent (var ev: THMouseEvent); override; - procedure keyEvent (var ev: THKeyEvent); override; + procedure mouseEvent (var ev: TFUIMouseEvent); override; + procedure keyEvent (var ev: TFUIKeyEvent); override; public property caption: AnsiString read mCaption write setCaption; @@ -429,8 +429,8 @@ type procedure drawControl (gx, gy: Integer); override; - procedure mouseEvent (var ev: THMouseEvent); override; - procedure keyEventPost (var ev: THKeyEvent); override; + procedure mouseEvent (var ev: TFUIMouseEvent); override; + procedure keyEventPost (var ev: TFUIKeyEvent); override; public property text: AnsiString read mText write setText; @@ -461,8 +461,8 @@ type procedure drawControl (gx, gy: Integer); override; - procedure mouseEvent (var ev: THMouseEvent); override; - procedure keyEvent (var ev: THKeyEvent); override; + procedure mouseEvent (var ev: TFUIMouseEvent); override; + procedure keyEvent (var ev: TFUIKeyEvent); override; end; // ////////////////////////////////////////////////////////////////////// // @@ -501,8 +501,8 @@ type procedure drawControl (gx, gy: Integer); override; - procedure mouseEvent (var ev: THMouseEvent); override; - procedure keyEvent (var ev: THKeyEvent); override; + procedure mouseEvent (var ev: TFUIMouseEvent); override; + procedure keyEvent (var ev: TFUIKeyEvent); override; procedure setVar (pvar: PBoolean); @@ -540,8 +540,8 @@ type // ////////////////////////////////////////////////////////////////////////// // -procedure uiMouseEvent (var evt: THMouseEvent); -procedure uiKeyEvent (var evt: THKeyEvent); +procedure uiMouseEvent (var evt: TFUIMouseEvent); +procedure uiKeyEvent (var evt: TFUIKeyEvent); procedure uiDraw (); procedure uiFocus (); @@ -736,15 +736,15 @@ begin end; -procedure uiMouseEvent (var evt: THMouseEvent); +procedure uiMouseEvent (var evt: TFUIMouseEvent); var - ev: THMouseEvent; + ev: TFUIMouseEvent; f, c: Integer; lx, ly: Integer; ctmp: TUIControl; begin processKills(); - if (evt.eaten) or (evt.cancelled) then exit; + if (not evt.alive) then exit; ev := evt; ev.x := trunc(ev.x/fuiRenderScale); ev.y := trunc(ev.y/fuiRenderScale); @@ -759,7 +759,7 @@ begin exit; end; if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].mouseEvent(ev); - if (not ev.eaten) and (not ev.cancelled) and (ev.press) then + if (ev.alive) and (ev.press) then begin for f := High(uiTopList) downto 0 do begin @@ -787,12 +787,12 @@ begin end; -procedure uiKeyEvent (var evt: THKeyEvent); +procedure uiKeyEvent (var evt: TFUIKeyEvent); var - ev: THKeyEvent; + ev: TFUIKeyEvent; begin processKills(); - if (evt.eaten) or (evt.cancelled) then exit; + if (not evt.alive) then exit; ev := evt; ev.x := trunc(ev.x/fuiRenderScale); ev.y := trunc(ev.y/fuiRenderScale); @@ -2050,7 +2050,7 @@ end; // ////////////////////////////////////////////////////////////////////////// // -procedure TUIControl.mouseEvent (var ev: THMouseEvent); +procedure TUIControl.mouseEvent (var ev: TFUIMouseEvent); var ctl: TUIControl; begin @@ -2068,32 +2068,32 @@ begin end; -procedure TUIControl.keyEvent (var ev: THKeyEvent); +procedure TUIControl.keyEvent (var ev: TFUIKeyEvent); function doPreKey (ctl: TUIControl): Boolean; begin if (not ctl.enabled) then begin result := false; exit; end; ctl.keyEventPre(ev); - result := (ev.eaten) or (ev.cancelled); // stop if event was consumed + result := (not ev.alive); // stop if event was consumed end; function doPostKey (ctl: TUIControl): Boolean; begin if (not ctl.enabled) then begin result := false; exit; end; ctl.keyEventPost(ev); - result := (ev.eaten) or (ev.cancelled); // stop if event was consumed + result := (not ev.alive); // stop if event was consumed end; var ctl: TUIControl; begin if (not enabled) then exit; - if (ev.eaten) or (ev.cancelled) then exit; + if (not ev.alive) then exit; // call pre-key if (mParent = nil) then begin forEachControl(doPreKey); - if (ev.eaten) or (ev.cancelled) then exit; + if (not ev.alive) then exit; end; // focused control should process keyboard first if (topLevel.mFocused <> self) and isMyChild(topLevel.mFocused) and (topLevel.mFocused.enabled) then @@ -2103,7 +2103,7 @@ begin while (ctl <> nil) and (ctl <> self) do begin ctl.keyEvent(ev); - if (ev.eaten) or (ev.cancelled) then exit; + if (not ev.alive) then exit; ctl := ctl.mParent; end; end; @@ -2154,18 +2154,18 @@ begin exit; end; // call post-keys - if (ev.eaten) or (ev.cancelled) then exit; + if (not ev.alive) then exit; forEachControl(doPostKey); end; end; -procedure TUIControl.keyEventPre (var ev: THKeyEvent); +procedure TUIControl.keyEventPre (var ev: TFUIKeyEvent); begin end; -procedure TUIControl.keyEventPost (var ev: THKeyEvent); +procedure TUIControl.keyEventPost (var ev: TFUIKeyEvent); begin end; @@ -2324,10 +2324,10 @@ begin end; -procedure TUITopWindow.keyEvent (var ev: THKeyEvent); +procedure TUITopWindow.keyEvent (var ev: TFUIKeyEvent); begin inherited keyEvent(ev); - if (ev.eaten) or (ev.cancelled) or (not enabled) {or (not getFocused)} then exit; + if (not ev.alive) or (not enabled) {or (not getFocused)} then exit; if (ev = 'M-F3') then begin if (not assigned(closeRequestCB)) or (closeRequestCB(self)) then @@ -2340,7 +2340,7 @@ begin end; -procedure TUITopWindow.mouseEvent (var ev: THMouseEvent); +procedure TUITopWindow.mouseEvent (var ev: TFUIMouseEvent); var lx, ly: Integer; vhgt, ytop: Integer; @@ -2583,25 +2583,25 @@ begin end; -procedure TUIBox.mouseEvent (var ev: THMouseEvent); +procedure TUIBox.mouseEvent (var ev: TFUIMouseEvent); var lx, ly: Integer; begin inherited mouseEvent(ev); - if (not ev.eaten) and (not ev.cancelled) and (enabled) and toLocal(ev.x, ev.y, lx, ly) then + if (ev.alive) and (enabled) and toLocal(ev.x, ev.y, lx, ly) then begin ev.eat(); end; end; -procedure TUIBox.keyEvent (var ev: THKeyEvent); +procedure TUIBox.keyEvent (var ev: TFUIKeyEvent); var dir: Integer = 0; cur, ctl: TUIControl; begin inherited keyEvent(ev); - if (ev.eaten) or (ev.cancelled) or (not ev.press) or (not enabled) or (not getActive) then exit; + if (not ev.alive) or (not ev.press) or (not enabled) or (not getActive) then exit; if (Length(mChildren) = 0) then exit; if (mHoriz) and (ev = 'Left') then dir := -1 else if (mHoriz) and (ev = 'Right') then dir := 1 @@ -2934,12 +2934,12 @@ begin end; -procedure TUITextLabel.mouseEvent (var ev: THMouseEvent); +procedure TUITextLabel.mouseEvent (var ev: TFUIMouseEvent); var lx, ly: Integer; begin inherited mouseEvent(ev); - if (not ev.eaten) and (not ev.cancelled) and (enabled) and toLocal(ev.x, ev.y, lx, ly) then + if (ev.alive) and (enabled) and toLocal(ev.x, ev.y, lx, ly) then begin ev.eat(); end; @@ -2965,11 +2965,11 @@ begin end; -procedure TUITextLabel.keyEventPost (var ev: THKeyEvent); +procedure TUITextLabel.keyEventPost (var ev: TFUIKeyEvent); begin if (not enabled) then exit; if (mHotChar = #0) then exit; - if (ev.eaten) or (ev.cancelled) or (not ev.press) then exit; + if (not ev.alive) or (not ev.press) then exit; if (ev.kstate <> ev.ModAlt) then exit; if (not ev.isHot(mHotChar)) then exit; ev.eat(); @@ -3168,7 +3168,7 @@ begin end; -procedure TUIButton.mouseEvent (var ev: THMouseEvent); +procedure TUIButton.mouseEvent (var ev: TFUIMouseEvent); var lx, ly: Integer; begin @@ -3184,16 +3184,16 @@ begin end; exit; end; - if (ev.eaten) or (ev.cancelled) or (not enabled) or not focused then exit; + if (not ev.alive) or (not enabled) or (not focused) then exit; mPushed := true; ev.eat(); end; -procedure TUIButton.keyEvent (var ev: THKeyEvent); +procedure TUIButton.keyEvent (var ev: TFUIKeyEvent); begin inherited keyEvent(ev); - if (not ev.eaten) and (not ev.cancelled) and (enabled) then + if (ev.alive) and (enabled) then begin if (ev = '+Enter') or (ev = '+Space') then begin @@ -3397,7 +3397,7 @@ begin end; -procedure TUISwitchBox.mouseEvent (var ev: THMouseEvent); +procedure TUISwitchBox.mouseEvent (var ev: TFUIMouseEvent); var lx, ly: Integer; begin @@ -3411,15 +3411,15 @@ begin end; exit; end; - if (ev.eaten) or (ev.cancelled) or (not enabled) or not focused then exit; + if (not ev.alive) or (not enabled) or not focused then exit; ev.eat(); end; -procedure TUISwitchBox.keyEvent (var ev: THKeyEvent); +procedure TUISwitchBox.keyEvent (var ev: TFUIKeyEvent); begin inherited keyEvent(ev); - if (not ev.eaten) and (not ev.cancelled) and (enabled) then + if (ev.alive) and (enabled) then begin if (ev = 'Space') then begin diff --git a/src/flexui/fui_events.pas b/src/flexui/fui_events.pas index 919227a..110833f 100644 --- a/src/flexui/fui_events.pas +++ b/src/flexui/fui_events.pas @@ -26,7 +26,7 @@ uses // ////////////////////////////////////////////////////////////////////////// // type - THMouseEvent = record + TFUIMouseEvent = record public const // both for but and for bstate @@ -51,7 +51,7 @@ type dx, dy: Integer; // for wheel this is wheel motion, otherwise this is relative mouse motion but: Word; // current pressed/released button, or 0 for motion bstate: Word; // button state BEFORE event (i.e. press/release modifications aren't done yet) - kstate: Word; // keyboard state (see THKeyEvent); + kstate: Word; // keyboard state (see TFUIKeyEvent); public procedure intrInit (); inline; // init hidden fields @@ -59,15 +59,17 @@ type function press (): Boolean; inline; function release (): Boolean; inline; function motion (): Boolean; inline; + function isAlive (): Boolean; inline; procedure eat (); inline; procedure cancel (); inline; public property eaten: Boolean read mEaten; property cancelled: Boolean read mCancelled; + property alive: Boolean read isAlive; // not eaten and not cancelled end; - THKeyEvent = record + TFUIKeyEvent = record public const // modifiers @@ -98,6 +100,7 @@ type function press (): Boolean; inline; function release (): Boolean; inline; + function isAlive (): Boolean; inline; procedure eat (); inline; procedure cancel (); inline; @@ -106,6 +109,7 @@ type public property eaten: Boolean read mEaten; property cancelled: Boolean read mCancelled; + property alive: Boolean read isAlive; // not eaten and not cancelled end; @@ -117,8 +121,8 @@ procedure fuiResetKMState (sendEvents: Boolean=true); // ////////////////////////////////////////////////////////////////////////// // // event handlers var - evMouseCB: procedure (var ev: THMouseEvent) = nil; - evKeyCB: procedure (var ev: THKeyEvent) = nil; + evMouseCB: procedure (var ev: TFUIMouseEvent) = nil; + evKeyCB: procedure (var ev: TFUIKeyEvent) = nil; // ////////////////////////////////////////////////////////////////////////// // @@ -137,11 +141,11 @@ procedure fuiSetModState (v: Word); inline; // any mods = 255: nothing was defined function parseModKeys (const s: AnsiString; out kmods: Byte; out mbuts: Byte): AnsiString; -operator = (constref ev: THKeyEvent; const s: AnsiString): Boolean; -operator = (const s: AnsiString; constref ev: THKeyEvent): Boolean; +operator = (constref ev: TFUIKeyEvent; const s: AnsiString): Boolean; +operator = (const s: AnsiString; constref ev: TFUIKeyEvent): Boolean; -operator = (constref ev: THMouseEvent; const s: AnsiString): Boolean; -operator = (const s: AnsiString; constref ev: THMouseEvent): Boolean; +operator = (constref ev: TFUIMouseEvent; const s: AnsiString): Boolean; +operator = (const s: AnsiString; constref ev: TFUIMouseEvent): Boolean; implementation @@ -187,20 +191,22 @@ procedure fuiSetModState (v: Word); inline; begin curModState := v; end; // ////////////////////////////////////////////////////////////////////////// // -procedure THMouseEvent.intrInit (); inline; begin mEaten := false; mCancelled := false; end; -function THMouseEvent.press (): Boolean; inline; begin result := (kind = TKind.Press); end; -function THMouseEvent.release (): Boolean; inline; begin result := (kind = TKind.Release); end; -function THMouseEvent.motion (): Boolean; inline; begin result := (kind = TKind.Motion); end; -procedure THMouseEvent.eat (); inline; begin mEaten := true; end; -procedure THMouseEvent.cancel (); inline; begin mCancelled := true; end; - -procedure THKeyEvent.intrInit (); inline; begin mEaten := false; mCancelled := false; ch := #0; scan := 0; end; -function THKeyEvent.press (): Boolean; inline; begin result := (kind = TKind.Press); end; -function THKeyEvent.release (): Boolean; inline; begin result := (kind = TKind.Release); end; -procedure THKeyEvent.eat (); inline; begin mEaten := true; end; -procedure THKeyEvent.cancel (); inline; begin mCancelled := true; end; - -function THKeyEvent.isHot (c: AnsiChar): Boolean; +procedure TFUIMouseEvent.intrInit (); inline; begin mEaten := false; mCancelled := false; end; +function TFUIMouseEvent.press (): Boolean; inline; begin result := (kind = TKind.Press); end; +function TFUIMouseEvent.release (): Boolean; inline; begin result := (kind = TKind.Release); end; +function TFUIMouseEvent.motion (): Boolean; inline; begin result := (kind = TKind.Motion); end; +function TFUIMouseEvent.isAlive (): Boolean; inline; begin result := (not mEaten) and (not mCancelled); end; +procedure TFUIMouseEvent.eat (); inline; begin mEaten := true; end; +procedure TFUIMouseEvent.cancel (); inline; begin mCancelled := true; end; + +procedure TFUIKeyEvent.intrInit (); inline; begin mEaten := false; mCancelled := false; ch := #0; scan := 0; end; +function TFUIKeyEvent.press (): Boolean; inline; begin result := (kind = TKind.Press); end; +function TFUIKeyEvent.release (): Boolean; inline; begin result := (kind = TKind.Release); end; +function TFUIKeyEvent.isAlive (): Boolean; inline; begin result := (not mEaten) and (not mCancelled); end; +procedure TFUIKeyEvent.eat (); inline; begin mEaten := true; end; +procedure TFUIKeyEvent.cancel (); inline; begin mCancelled := true; end; + +function TFUIKeyEvent.isHot (c: AnsiChar): Boolean; begin if (c = #0) or (scan = 0) or (scan = $FFFF) then begin result := false; exit; end; case scan of @@ -281,18 +287,18 @@ begin if (Length(s)-pos >= 1) and (s[pos+1] = '-') then begin case s[pos] of - 'C', 'c': begin if (kmods = 255) then kmods := 0; kmods := kmods or THKeyEvent.ModCtrl; Inc(pos, 2); continue; end; - 'M', 'm': begin if (kmods = 255) then kmods := 0; kmods := kmods or THKeyEvent.ModAlt; Inc(pos, 2); continue; end; - 'S', 's': begin if (kmods = 255) then kmods := 0; kmods := kmods or THKeyEvent.ModShift; Inc(pos, 2); continue; end; + 'C', 'c': begin if (kmods = 255) then kmods := 0; kmods := kmods or TFUIKeyEvent.ModCtrl; Inc(pos, 2); continue; end; + 'M', 'm': begin if (kmods = 255) then kmods := 0; kmods := kmods or TFUIKeyEvent.ModAlt; Inc(pos, 2); continue; end; + 'S', 's': begin if (kmods = 255) then kmods := 0; kmods := kmods or TFUIKeyEvent.ModShift; Inc(pos, 2); continue; end; end; break; end; if (Length(s)-pos >= 3) and (s[pos+3] = '-') and ((s[pos+1] = 'M') or (s[pos+1] = 'm')) and ((s[pos+2] = 'B') or (s[pos+2] = 'b')) then begin case s[pos] of - 'L', 'l': begin if (mbuts = 255) then mbuts := 0; mbuts := mbuts or THMouseEvent.Left; Inc(pos, 4); continue; end; - 'R', 'r': begin if (mbuts = 255) then mbuts := 0; mbuts := mbuts or THMouseEvent.Right; Inc(pos, 4); continue; end; - 'M', 'm': begin if (mbuts = 255) then mbuts := 0; mbuts := mbuts or THMouseEvent.Middle; Inc(pos, 4); continue; end; + 'L', 'l': begin if (mbuts = 255) then mbuts := 0; mbuts := mbuts or TFUIMouseEvent.Left; Inc(pos, 4); continue; end; + 'R', 'r': begin if (mbuts = 255) then mbuts := 0; mbuts := mbuts or TFUIMouseEvent.Right; Inc(pos, 4); continue; end; + 'M', 'm': begin if (mbuts = 255) then mbuts := 0; mbuts := mbuts or TFUIMouseEvent.Middle; Inc(pos, 4); continue; end; end; break; end; @@ -304,7 +310,7 @@ begin end; -operator = (constref ev: THKeyEvent; const s: AnsiString): Boolean; +operator = (constref ev: TFUIKeyEvent; const s: AnsiString): Boolean; var f: Integer; kmods: Byte = 255; @@ -337,13 +343,13 @@ begin end; -operator = (const s: AnsiString; constref ev: THKeyEvent): Boolean; +operator = (const s: AnsiString; constref ev: TFUIKeyEvent): Boolean; begin result := (ev = s); end; -operator = (constref ev: THMouseEvent; const s: AnsiString): Boolean; +operator = (constref ev: TFUIMouseEvent; const s: AnsiString): Boolean; var kmods: Byte = 255; mbuts: Byte = 255; @@ -362,11 +368,11 @@ begin end; kname := parseModKeys(s, kmods, mbuts); - if strEquCI(kname, 'LMB') then but := THMouseEvent.Left - else if strEquCI(kname, 'RMB') then but := THMouseEvent.Right - else if strEquCI(kname, 'MMB') then but := THMouseEvent.Middle - else if strEquCI(kname, 'WheelUp') or strEquCI(kname, 'WUP') then but := THMouseEvent.WheelUp - else if strEquCI(kname, 'WheelDown') or strEquCI(kname, 'WDN') or strEquCI(kname, 'WDOWN') then but := THMouseEvent.WheelDown + if strEquCI(kname, 'LMB') then but := TFUIMouseEvent.Left + else if strEquCI(kname, 'RMB') then but := TFUIMouseEvent.Right + else if strEquCI(kname, 'MMB') then but := TFUIMouseEvent.Middle + else if strEquCI(kname, 'WheelUp') or strEquCI(kname, 'WUP') then but := TFUIMouseEvent.WheelUp + else if strEquCI(kname, 'WheelDown') or strEquCI(kname, 'WDN') or strEquCI(kname, 'WDOWN') then but := TFUIMouseEvent.WheelDown else if strEquCI(kname, 'None') then but := 0 else exit; @@ -379,7 +385,7 @@ begin end; -operator = (const s: AnsiString; constref ev: THMouseEvent): Boolean; +operator = (const s: AnsiString; constref ev: TFUIMouseEvent): Boolean; begin result := (ev = s); end; @@ -389,8 +395,8 @@ end; procedure fuiResetKMState (sendEvents: Boolean=true); var mask: Word; - mev: THMouseEvent; - kev: THKeyEvent; + mev: TFUIMouseEvent; + kev: TFUIKeyEvent; begin // generate mouse release events if (curButState <> 0) then @@ -437,10 +443,10 @@ begin kev.intrInit(); kev.kind := kev.TKind.Release; case mask of - THKeyEvent.ModCtrl: begin kev.scan := SDL_SCANCODE_LCTRL; {kev.sym := SDLK_LCTRL;}{arbitrary} end; - THKeyEvent.ModAlt: begin kev.scan := SDL_SCANCODE_LALT; {kev.sym := SDLK_LALT;}{arbitrary} end; - THKeyEvent.ModShift: begin kev.scan := SDL_SCANCODE_LSHIFT; {kev.sym := SDLK_LSHIFT;}{arbitrary} end; - THKeyEvent.ModHyper: begin kev.scan := SDL_SCANCODE_LGUI; {kev.sym := SDLK_LGUI;}{arbitrary} end; + TFUIKeyEvent.ModCtrl: begin kev.scan := SDL_SCANCODE_LCTRL; {kev.sym := SDLK_LCTRL;}{arbitrary} end; + TFUIKeyEvent.ModAlt: begin kev.scan := SDL_SCANCODE_LALT; {kev.sym := SDLK_LALT;}{arbitrary} end; + TFUIKeyEvent.ModShift: begin kev.scan := SDL_SCANCODE_LSHIFT; {kev.sym := SDLK_LSHIFT;}{arbitrary} end; + TFUIKeyEvent.ModHyper: begin kev.scan := SDL_SCANCODE_LGUI; {kev.sym := SDLK_LGUI;}{arbitrary} end; else assert(false); end; kev.x := curMsX; diff --git a/src/flexui/sdlcarcass.pas b/src/flexui/sdlcarcass.pas index 33a4664..71e7993 100644 --- a/src/flexui/sdlcarcass.pas +++ b/src/flexui/sdlcarcass.pas @@ -182,8 +182,8 @@ end; // ////////////////////////////////////////////////////////////////////////// // function fuiOnSDLEvent (var ev: TSDL_Event): Boolean; var - mev: THMouseEvent; - kev: THKeyEvent; + mev: TFUIMouseEvent; + kev: TFUIKeyEvent; uc: UnicodeChar; keychr: Word; @@ -191,9 +191,9 @@ var begin result := 0; case b of - SDL_BUTTON_LEFT: result := result or THMouseEvent.Left; - SDL_BUTTON_MIDDLE: result := result or THMouseEvent.Middle; - SDL_BUTTON_RIGHT: result := result or THMouseEvent.Right; + SDL_BUTTON_LEFT: result := result or TFUIMouseEvent.Left; + SDL_BUTTON_MIDDLE: result := result or TFUIMouseEvent.Middle; + SDL_BUTTON_RIGHT: result := result or TFUIMouseEvent.Right; end; end; @@ -228,7 +228,7 @@ begin // fix left/right modifiers FillChar(kev, sizeof(kev), 0); kev.intrInit(); - if (ev.type_ = SDL_KEYDOWN) then kev.kind := THKeyEvent.TKind.Press else kev.kind := THKeyEvent.TKind.Release; + if (ev.type_ = SDL_KEYDOWN) then kev.kind := TFUIKeyEvent.TKind.Press else kev.kind := TFUIKeyEvent.TKind.Release; kev.scan := ev.key.keysym.scancode; //kev.sym := ev.key.keysym.sym; @@ -250,9 +250,9 @@ begin kev.kstate := fuiModState; case kev.scan of - SDL_SCANCODE_LCTRL: if (kev.press) then fuiSetModState(fuiModState or THKeyEvent.ModCtrl) else fuiSetModState(fuiModState and (not THKeyEvent.ModCtrl)); - SDL_SCANCODE_LALT: if (kev.press) then fuiSetModState(fuiModState or THKeyEvent.ModAlt) else fuiSetModState(fuiModState and (not THKeyEvent.ModAlt)); - SDL_SCANCODE_LSHIFT: if (kev.press) then fuiSetModState(fuiModState or THKeyEvent.ModShift) else fuiSetModState(fuiModState and (not THKeyEvent.ModShift)); + SDL_SCANCODE_LCTRL: if (kev.press) then fuiSetModState(fuiModState or TFUIKeyEvent.ModCtrl) else fuiSetModState(fuiModState and (not TFUIKeyEvent.ModCtrl)); + SDL_SCANCODE_LALT: if (kev.press) then fuiSetModState(fuiModState or TFUIKeyEvent.ModAlt) else fuiSetModState(fuiModState and (not TFUIKeyEvent.ModAlt)); + SDL_SCANCODE_LSHIFT: if (kev.press) then fuiSetModState(fuiModState or TFUIKeyEvent.ModShift) else fuiSetModState(fuiModState and (not TFUIKeyEvent.ModShift)); end; if assigned(evKeyCB) then @@ -266,7 +266,7 @@ begin begin FillChar(mev, sizeof(mev), 0); mev.intrInit(); - if (ev.type_ = SDL_MOUSEBUTTONDOWN) then mev.kind := THMouseEvent.TKind.Press else mev.kind := THMouseEvent.TKind.Release; + if (ev.type_ = SDL_MOUSEBUTTONDOWN) then mev.kind := TFUIMouseEvent.TKind.Press else mev.kind := TFUIMouseEvent.TKind.Release; mev.dx := ev.button.x-fuiMouseX; mev.dy := ev.button.y-fuiMouseY; fuiSetMouseX(ev.button.x); @@ -293,10 +293,10 @@ begin begin FillChar(mev, sizeof(mev), 0); mev.intrInit(); - mev.kind := THMouseEvent.TKind.Press; + mev.kind := TFUIMouseEvent.TKind.Press; mev.dx := 0; mev.dy := ev.wheel.y; - if (ev.wheel.y < 0) then mev.but := THMouseEvent.WheelUp else mev.but := THMouseEvent.WheelDown; + if (ev.wheel.y < 0) then mev.but := TFUIMouseEvent.WheelUp else mev.but := TFUIMouseEvent.WheelDown; mev.x := fuiMouseX; mev.y := fuiMouseY; mev.bstate := fuiButState; @@ -312,7 +312,7 @@ begin begin FillChar(mev, sizeof(mev), 0); mev.intrInit(); - mev.kind := THMouseEvent.TKind.Motion; + mev.kind := TFUIMouseEvent.TKind.Motion; mev.dx := ev.button.x-fuiMouseX; mev.dy := ev.button.y-fuiMouseY; fuiSetMouseX(ev.button.x); @@ -330,7 +330,7 @@ begin end; SDL_TEXTINPUT: - if ((fuiModState and (not THKeyEvent.ModShift)) = 0) then + if ((fuiModState and (not TFUIKeyEvent.ModShift)) = 0) then begin Utf8ToUnicode(@uc, PChar(ev.text.text), 1); keychr := Word(uc); @@ -339,7 +339,7 @@ begin begin FillChar(kev, sizeof(kev), 0); kev.intrInit(); - kev.kind := THKeyEvent.TKind.Press; + kev.kind := TFUIKeyEvent.TKind.Press; kev.scan := 0; kev.ch := AnsiChar(keychr); kev.x := fuiMouseX; diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 5f1cb3e..0b5c00d 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -32,8 +32,8 @@ uses procedure g_Holmes_Draw (); procedure g_Holmes_DrawUI (); -procedure g_Holmes_MouseEvent (var ev: THMouseEvent); -procedure g_Holmes_KeyEvent (var ev: THKeyEvent); +procedure g_Holmes_MouseEvent (var ev: TFUIMouseEvent); +procedure g_Holmes_KeyEvent (var ev: TFUIKeyEvent); // hooks for player procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer); @@ -543,11 +543,11 @@ function pmsCurMapX (): Integer; inline; begin result := round(msX/g_dbg_scale)+ function pmsCurMapY (): Integer; inline; begin result := round(msY/g_dbg_scale)+vpy; end; -procedure plrDebugMouse (var ev: THMouseEvent); +procedure plrDebugMouse (var ev: TFUIMouseEvent); begin //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY); if (gPlayer1 = nil) or not vpSet then exit; - //if (ev.kind <> THMouseEvent.Press) then exit; + //if (ev.kind <> TFUIMouseEvent.Press) then exit; //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY); msbindExecute(ev); end; @@ -1317,9 +1317,9 @@ end; // ////////////////////////////////////////////////////////////////////////// // -procedure g_Holmes_MouseEvent (var ev: THMouseEvent); +procedure g_Holmes_MouseEvent (var ev: TFUIMouseEvent); var - he: THMouseEvent; + he: TFUIMouseEvent; begin if g_Game_IsNet then exit; if not g_holmes_enabled then exit; @@ -1336,13 +1336,13 @@ begin he.x := he.x; he.y := he.y; uiMouseEvent(he); - if (not he.eaten) then plrDebugMouse(he); + if (he.alive) then plrDebugMouse(he); ev.eat(); end; // ////////////////////////////////////////////////////////////////////////// // -procedure g_Holmes_KeyEvent (var ev: THKeyEvent); +procedure g_Holmes_KeyEvent (var ev: TFUIKeyEvent); var doeat: Boolean = false; {$IF DEFINED(D2F_DEBUG)} @@ -1373,7 +1373,7 @@ begin end; uiKeyEvent(ev); - if (ev.eaten) then exit; + if (not ev.alive) then exit; if keybindExecute(ev) then begin ev.eat(); exit; end; // press if (ev.press) then @@ -1381,7 +1381,7 @@ begin {$IF DEFINED(D2F_DEBUG)} // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction if ((ev.scan = SDL_SCANCODE_UP) or (ev.scan = SDL_SCANCODE_DOWN) or (ev.scan = SDL_SCANCODE_LEFT) or (ev.scan = SDL_SCANCODE_RIGHT)) and - ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then + ((ev.kstate and TFUIKeyEvent.ModCtrl) <> 0) then begin ev.eat(); dx := pmsCurMapX; @@ -1715,14 +1715,14 @@ begin end; -procedure onMouseEvent (var ev: THMouseEvent); +procedure onMouseEvent (var ev: TFUIMouseEvent); begin if not g_holmes_enabled then exit; if g_holmes_imfunctional then exit; g_Holmes_MouseEvent(ev); end; -procedure onKeyEvent (var ev: THKeyEvent); +procedure onKeyEvent (var ev: TFUIKeyEvent); begin if not g_holmes_enabled then exit; if g_holmes_imfunctional then exit; diff --git a/src/game/g_holmes_cmd.inc b/src/game/g_holmes_cmd.inc index e76b7f2..dfa4930 100644 --- a/src/game/g_holmes_cmd.inc +++ b/src/game/g_holmes_cmd.inc @@ -280,7 +280,7 @@ begin end; -function keybindExecute (var ev: THKeyEvent): Boolean; +function keybindExecute (var ev: TFUIKeyEvent): Boolean; var f: Integer; begin @@ -298,7 +298,7 @@ begin end; -function msbindExecute (var ev: THMouseEvent): Boolean; +function msbindExecute (var ev: TFUIMouseEvent): Boolean; var f: Integer; begin