X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fflexui%2Fsdlcarcass.pas;h=247229b88af696d43b157e587f0cdcf09410604d;hb=0ac904293ecfc21bbfc2d944a61dbcf7541ac9bf;hp=33a4664d004d493228af37ce69701a4e04c47cee;hpb=6880f8a491a247a34d6afb5508d0a64196a3d26d;p=d2df-sdl.git diff --git a/src/flexui/sdlcarcass.pas b/src/flexui/sdlcarcass.pas index 33a4664..247229b 100644 --- a/src/flexui/sdlcarcass.pas +++ b/src/flexui/sdlcarcass.pas @@ -1,9 +1,8 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -69,11 +68,13 @@ implementation uses SysUtils, Classes, - GL, GLExt, - {$IF DEFINED(LINUX)} + {$INCLUDE ../nogl/noGLuses.inc} + {$IF DEFINED(LINUX) OR DEFINED(ANDROID)} unixtype, linux {$ELSEIF DEFINED(WINDOWS)} Windows + {$ELSEIF DEFINED(HAIKU) OR DEFINED(UNIX)} + unixtype {$ELSE} {$WARNING You suck!} {$ENDIF} @@ -111,7 +112,7 @@ begin if not mHasHPTimer then raise Exception.Create('profiler error: hires timer is not available'); mFrequency := 1; // just a flag if (r.tv_nsec <> 0) then mFrequency := 1000000000000000000 div r.tv_nsec; -{$ELSE} +{$ELSEIF DEFINED(WINDOWS)} mHasHPTimer := QueryPerformanceFrequency(r); if not mHasHPTimer then raise Exception.Create('profiler error: hires timer is not available'); mFrequency := r; @@ -128,7 +129,7 @@ begin {$IF DEFINED(LINUX)} clock_gettime(CLOCK_MONOTONIC, @r); result := UInt64(r.tv_sec)*1000000+UInt64(r.tv_nsec) div 1000; // microseconds - {$ELSE} + {$ELSEIF DEFINED(WINDOWS)} QueryPerformanceCounter(r); result := UInt64(r)*1000000 div mFrequency; {$ENDIF} @@ -182,8 +183,7 @@ end; // ////////////////////////////////////////////////////////////////////////// // function fuiOnSDLEvent (var ev: TSDL_Event): Boolean; var - mev: THMouseEvent; - kev: THKeyEvent; + fev: TFUIEvent; 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 TFUIEvent.Left; + SDL_BUTTON_MIDDLE: result := result or TFUIEvent.Middle; + SDL_BUTTON_RIGHT: result := result or TFUIEvent.Right; end; end; @@ -226,64 +226,66 @@ begin SDL_KEYDOWN, SDL_KEYUP: 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; - kev.scan := ev.key.keysym.scancode; - //kev.sym := ev.key.keysym.sym; - - if (kev.scan = SDL_SCANCODE_RCTRL) then kev.scan := SDL_SCANCODE_LCTRL; - if (kev.scan = SDL_SCANCODE_RALT) then kev.scan := SDL_SCANCODE_LALT; - if (kev.scan = SDL_SCANCODE_RSHIFT) then kev.scan := SDL_SCANCODE_LSHIFT; - if (kev.scan = SDL_SCANCODE_RGUI) then kev.scan := SDL_SCANCODE_LGUI; - - { - if (kev.sym = SDLK_RCTRL) then kev.sym := SDLK_LCTRL; - if (kev.sym = SDLK_RALT) then kev.sym := SDLK_LALT; - if (kev.sym = SDLK_RSHIFT) then kev.sym := SDLK_LSHIFT; - if (kev.sym = SDLK_RGUI) then kev.sym := SDLK_LGUI; - } - - kev.x := fuiMouseX; - kev.y := fuiMouseY; - kev.bstate := fuiButState; - 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)); + if (ev.type_ = SDL_KEYDOWN) then + begin + fev := TFUIEvent.Create(TFUIEvent.TType.Key, TFUIEvent.TKind.Press); + end + else + begin + fev := TFUIEvent.Create(TFUIEvent.TType.Key, TFUIEvent.TKind.Release); + end; + fev.scan := ev.key.keysym.scancode; + + if (fev.scan = SDL_SCANCODE_RCTRL) then fev.scan := SDL_SCANCODE_LCTRL; + if (fev.scan = SDL_SCANCODE_RALT) then fev.scan := SDL_SCANCODE_LALT; + if (fev.scan = SDL_SCANCODE_RSHIFT) then fev.scan := SDL_SCANCODE_LSHIFT; + if (fev.scan = SDL_SCANCODE_RGUI) then fev.scan := SDL_SCANCODE_LGUI; + + fev.x := fuiMouseX; + fev.y := fuiMouseY; + fev.bstate := fuiButState; + fev.kstate := fuiModState; + + case fev.scan of + SDL_SCANCODE_LCTRL: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModCtrl) else fuiSetModState(fuiModState and (not TFUIEvent.ModCtrl)); + SDL_SCANCODE_LALT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModAlt) else fuiSetModState(fuiModState and (not TFUIEvent.ModAlt)); + SDL_SCANCODE_LSHIFT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModShift) else fuiSetModState(fuiModState and (not TFUIEvent.ModShift)); end; - if assigned(evKeyCB) then + if (assigned(fuiEventCB)) then begin - evKeyCB(kev); - result := kev.eaten; + fuiEventCB(fev); + result := fev.eaten; end; end; SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP: 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; - mev.dx := ev.button.x-fuiMouseX; - mev.dy := ev.button.y-fuiMouseY; + if (ev.type_ = SDL_MOUSEBUTTONDOWN) then + begin + fev := TFUIEvent.Create(TFUIEvent.TType.Mouse, TFUIEvent.TKind.Press); + end + else + begin + fev := TFUIEvent.Create(TFUIEvent.TType.Mouse, TFUIEvent.TKind.Release); + end; + fev.dx := ev.button.x-fuiMouseX; + fev.dy := ev.button.y-fuiMouseY; fuiSetMouseX(ev.button.x); fuiSetMouseY(ev.button.y); - mev.but := buildBut(ev.button.button); - mev.x := fuiMouseX; - mev.y := fuiMouseY; - mev.bstate := fuiButState; - mev.kstate := fuiModState; - if (mev.but <> 0) then + fev.but := buildBut(ev.button.button); + fev.x := fuiMouseX; + fev.y := fuiMouseY; + fev.bstate := fuiButState; + fev.kstate := fuiModState; + if (fev.but <> 0) then begin // ev.button.clicks: Byte - if (ev.type_ = SDL_MOUSEBUTTONDOWN) then fuiSetButState(fuiButState or mev.but) else fuiSetButState(fuiButState and (not mev.but)); - if assigned(evMouseCB) then + if (ev.type_ = SDL_MOUSEBUTTONDOWN) then fuiSetButState(fuiButState or fev.but) else fuiSetButState(fuiButState and (not fev.but)); + if (assigned(fuiEventCB)) then begin - evMouseCB(mev); - result := mev.eaten; + fuiEventCB(fev); + result := fev.eaten; end; end; end; @@ -291,63 +293,56 @@ begin begin if (ev.wheel.y <> 0) then begin - FillChar(mev, sizeof(mev), 0); - mev.intrInit(); - mev.kind := THMouseEvent.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; - mev.x := fuiMouseX; - mev.y := fuiMouseY; - mev.bstate := fuiButState; - mev.kstate := fuiModState; - if assigned(evMouseCB) then + fev := TFUIEvent.Create(TFUIEvent.TType.Mouse, TFUIEvent.TKind.Press); + fev.dx := 0; + fev.dy := ev.wheel.y; + if (ev.wheel.y < 0) then fev.but := TFUIEvent.WheelUp else fev.but := TFUIEvent.WheelDown; + fev.x := fuiMouseX; + fev.y := fuiMouseY; + fev.bstate := fuiButState; + fev.kstate := fuiModState; + if (assigned(fuiEventCB)) then begin - evMouseCB(mev); - result := mev.eaten; + fuiEventCB(fev); + result := fev.eaten; end; end; end; SDL_MOUSEMOTION: begin - FillChar(mev, sizeof(mev), 0); - mev.intrInit(); - mev.kind := THMouseEvent.TKind.Motion; - mev.dx := ev.button.x-fuiMouseX; - mev.dy := ev.button.y-fuiMouseY; + fev := TFUIEvent.Create(TFUIEvent.TType.Mouse, TFUIEvent.TKind.Motion); + fev.dx := ev.button.x-fuiMouseX; + fev.dy := ev.button.y-fuiMouseY; fuiSetMouseX(ev.button.x); fuiSetMouseY(ev.button.y); - mev.but := 0; - mev.x := fuiMouseX; - mev.y := fuiMouseY; - mev.bstate := fuiButState; - mev.kstate := fuiModState; - if assigned(evMouseCB) then + fev.but := 0; + fev.x := fuiMouseX; + fev.y := fuiMouseY; + fev.bstate := fuiButState; + fev.kstate := fuiModState; + if (assigned(fuiEventCB)) then begin - evMouseCB(mev); - result := mev.eaten; + fuiEventCB(fev); + result := fev.eaten; end; end; SDL_TEXTINPUT: - if ((fuiModState and (not THKeyEvent.ModShift)) = 0) then + if ((fuiModState and (not TFUIEvent.ModShift)) = 0) then begin Utf8ToUnicode(@uc, PChar(ev.text.text), 1); keychr := Word(uc); if (keychr > 127) then keychr := Word(wchar2win(WideChar(keychr))); - if (keychr > 0) and assigned(evKeyCB) then + if (keychr > 0) and (assigned(fuiEventCB)) then begin - FillChar(kev, sizeof(kev), 0); - kev.intrInit(); - kev.kind := THKeyEvent.TKind.Press; - kev.scan := 0; - kev.ch := AnsiChar(keychr); - kev.x := fuiMouseX; - kev.y := fuiMouseY; - kev.bstate := fuiButState; - kev.kstate := fuiModState; - evKeyCB(kev); - result := kev.eaten; + fev := TFUIEvent.Create(TFUIEvent.TType.Key, TFUIEvent.TKind.SimpleChar); + fev.ch := AnsiChar(keychr); + fev.x := fuiMouseX; + fev.y := fuiMouseY; + fev.bstate := fuiButState; + fev.kstate := fuiModState; + fuiEventCB(fev); + result := fev.eaten; end; end; end;