index ef5ab367e43e2bd11e0d8fe558c20dfb2fca4f52..27f14fd0fd007acfcca858be4f6fff6278e08daa 100644 (file)
--- a/src/flexui/fui_ctls.pas
+++ b/src/flexui/fui_ctls.pas
mFrameColor: array[0..ClrIdxMax] of TGxRGBA;
mFrameTextColor: array[0..ClrIdxMax] of TGxRGBA;
mFrameIconColor: array[0..ClrIdxMax] of TGxRGBA;
+ mSBarFullColor: array[0..ClrIdxMax] of TGxRGBA;
+ mSBarEmptyColor: array[0..ClrIdxMax] of TGxRGBA;
mDarken: array[0..ClrIdxMax] of Integer; // >255: none
protected
//WARNING! do not call scissor functions outside `.draw*()` API!
// set scissor to this rect (in local coords)
procedure setScissor (lx, ly, lw, lh: Integer); // valid only in `draw*()` calls
+ procedure resetScissor (); inline; // only client area, w/o frame
+ procedure resetScissorNC (); inline; // full drawing area, with frame
public
actionCB: TActionCB;
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;
TUITopWindow = class(TUIControl)
private
- type TXMode = (None, Drag, Scroll);
+ type TXMode = (None, Drag, VScroll, HScroll);
private
mTitle: AnsiString;
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;
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;
procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
-
- procedure drawControl (gx, gy: Integer); override;
end;
// ////////////////////////////////////////////////////////////////////// //
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;
procedure cacheStyle (root: TUIStyle); override;
+ procedure blurred (); override;
+
public
procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
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;
// ////////////////////////////////////////////////////////////////////// //
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);
// ////////////////////////////////////////////////////////////////////////// //
-procedure uiMouseEvent (var evt: THMouseEvent);
-procedure uiKeyEvent (var evt: THKeyEvent);
+procedure uiMouseEvent (var evt: TFUIMouseEvent);
+procedure uiKeyEvent (var evt: TFUIKeyEvent);
procedure uiDraw ();
+procedure uiFocus ();
+procedure uiBlur ();
+
// ////////////////////////////////////////////////////////////////////////// //
procedure uiAddWindow (ctl: TUIControl);
procedure uiLayoutCtl (ctl: TUIControl);
+// ////////////////////////////////////////////////////////////////////////// //
+procedure uiInitialize ();
+procedure uiDeinitialize ();
+
+
// ////////////////////////////////////////////////////////////////////////// //
var
fuiRenderScale: Single = 1.0;
utils;
+// ////////////////////////////////////////////////////////////////////////// //
+procedure uiDeinitialize ();
+begin
+ FreeAndNil(uiContext);
+end;
+
+
+procedure uiInitialize ();
+begin
+ if (uiContext <> nil) then raise Exception.Create('FlexUI already initialized');
+ uiContext := TGxContext.Create();
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
var
ctlsToKill: array of TUIControl = nil;
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);
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
begin
if (uiTopList[f].enabled) and (f <> High(uiTopList)) then
begin
- uiTopList[High(uiTopList)].blurred();
+ if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].blurred();
ctmp := uiTopList[f];
uiGrabCtl := nil;
for c := f+1 to High(uiTopList) do uiTopList[c-1] := uiTopList[c];
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);
end;
+procedure uiFocus ();
+begin
+ if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].activated();
+end;
+
+
+procedure uiBlur ();
+begin
+ if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].blurred();
+end;
+
+
procedure uiDraw ();
var
f, cidx: Integer;
begin
if (f <> High(uiTopList)) then
begin
- uiTopList[High(uiTopList)].blurred();
+ if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].blurred();
for c := f+1 to High(uiTopList) do uiTopList[c-1] := uiTopList[c];
uiTopList[High(uiTopList)] := ctl;
ctl.activated();
exit;
end;
end;
- if (Length(uiTopList) > 0) then uiTopList[High(uiTopList)].blurred();
+ if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].blurred();
SetLength(uiTopList, Length(uiTopList)+1);
uiTopList[High(uiTopList)] := ctl;
if (not ctl.mStyleLoaded) then ctl.updateStyle();
ctl.blurred();
for c := f+1 to High(uiTopList) do uiTopList[c-1] := uiTopList[c];
SetLength(uiTopList, Length(uiTopList)-1);
+ if (Length(uiTopList) > 0) and (uiTopList[High(uiTopList)].enabled) then uiTopList[High(uiTopList)].activated();
if (ctl is TUITopWindow) then
begin
try
mFrameColor[ClrIdxActive] := root.get('frame-color', 'active', cst).asRGBADef(TGxRGBA.Create(255, 255, 255));
mFrameTextColor[ClrIdxActive] := root.get('frame-text-color', 'active', cst).asRGBADef(TGxRGBA.Create(255, 255, 255));
mFrameIconColor[ClrIdxActive] := root.get('frame-icon-color', 'active', cst).asRGBADef(TGxRGBA.Create(0, 255, 0));
+ mSBarFullColor[ClrIdxActive] := root.get('scrollbar-full-color', 'active', cst).asRGBADef(TGxRGBA.Create(255, 255, 255));
+ mSBarEmptyColor[ClrIdxActive] := root.get('scrollbar-empty-color', 'active', cst).asRGBADef(TGxRGBA.Create(128, 128, 128));
mDarken[ClrIdxActive] := root.get('darken', 'active', cst).asInt(666);
// disabled
mBackColor[ClrIdxDisabled] := root.get('back-color', 'disabled', cst).asRGBADef(TGxRGBA.Create(0, 0, 128));
mFrameColor[ClrIdxDisabled] := root.get('frame-color', 'disabled', cst).asRGBADef(TGxRGBA.Create(127, 127, 127));
mFrameTextColor[ClrIdxDisabled] := root.get('frame-text-color', 'disabled', cst).asRGBADef(TGxRGBA.Create(127, 127, 127));
mFrameIconColor[ClrIdxDisabled] := root.get('frame-icon-color', 'disabled', cst).asRGBADef(TGxRGBA.Create(0, 127, 0));
+ mSBarFullColor[ClrIdxDisabled] := root.get('scrollbar-full-color', 'disabled', cst).asRGBADef(TGxRGBA.Create(127, 127, 127));
+ mSBarEmptyColor[ClrIdxDisabled] := root.get('scrollbar-empty-color', 'disabled', cst).asRGBADef(TGxRGBA.Create(98, 98, 98));
mDarken[ClrIdxDisabled] := root.get('darken', 'disabled', cst).asInt(666);
// inactive
mBackColor[ClrIdxInactive] := root.get('back-color', 'inactive', cst).asRGBADef(TGxRGBA.Create(0, 0, 128));
mFrameColor[ClrIdxInactive] := root.get('frame-color', 'inactive', cst).asRGBADef(TGxRGBA.Create(255, 255, 255));
mFrameTextColor[ClrIdxInactive] := root.get('frame-text-color', 'inactive', cst).asRGBADef(TGxRGBA.Create(255, 255, 255));
mFrameIconColor[ClrIdxInactive] := root.get('frame-icon-color', 'inactive', cst).asRGBADef(TGxRGBA.Create(0, 255, 0));
+ mSBarFullColor[ClrIdxInactive] := root.get('scrollbar-full-color', 'inactive', cst).asRGBADef(TGxRGBA.Create(255, 255, 255));
+ mSBarEmptyColor[ClrIdxInactive] := root.get('scrollbar-empty-color', 'inactive', cst).asRGBADef(TGxRGBA.Create(128, 128, 128));
mDarken[ClrIdxInactive] := root.get('darken', 'inactive', cst).asInt(666);
end;
//uiContext.clip := TGxRect.Create(gx, gy, wdt, hgt);
end;
+procedure TUIControl.resetScissorNC (); inline;
+begin
+ setScissor(0, 0, mWidth, mHeight);
+end;
+
+procedure TUIControl.resetScissor (); inline;
+begin
+ if ((mFrameWidth <= 0) and (mFrameHeight <= 0)) then
+ begin
+ resetScissorNC();
+ end
+ else
+ begin
+ setScissor(mFrameWidth, mFrameHeight, mWidth-mFrameWidth*2, mHeight-mFrameHeight*2);
+ end;
+end;
// ////////////////////////////////////////////////////////////////////////// //
f: Integer;
gx, gy: Integer;
- procedure resetScissor (fullArea: Boolean); inline;
- begin
- uiContext.clip := savedClip;
- if (fullArea) or ((mFrameWidth = 0) and (mFrameHeight = 0)) then
- begin
- setScissor(0, 0, mWidth, mHeight);
- end
- else
- begin
- //writeln('frm: (', mFrameWidth, 'x', mFrameHeight, ')');
- setScissor(mFrameWidth, mFrameHeight, mWidth-mFrameWidth*2, mHeight-mFrameHeight*2);
- end;
- end;
-
begin
if (mWidth < 1) or (mHeight < 1) or (uiContext = nil) or (not uiContext.active) then exit;
toGlobal(0, 0, gx, gy);
savedClip := uiContext.clip;
try
- resetScissor(true); // full area
+ resetScissorNC();
drawControl(gx, gy);
- resetScissor(false); // client area
+ resetScissor();
for f := 0 to High(mChildren) do mChildren[f].draw();
- resetScissor(true); // full area
- if (self is TUISwitchBox) then
- begin
- uiContext.color := TGxRGBA.Create(255, 0, 0, 255);
- //uiContext.fillRect(gx, gy, mWidth, mHeight);
- //writeln('frm: (', mFrameWidth, 'x', mFrameHeight, '); sz=(', mWidth, 'x', mHeight, '); clip=', uiContext.clip.toString);
- end;
- if false and (mId = 'cbtest') then
- begin
- uiContext.color := TGxRGBA.Create(255, 127, 0, 96);
- uiContext.fillRect(gx, gy, mWidth, mHeight);
- if (mFrameWidth > 0) and (mFrameHeight > 0) then
- begin
- uiContext.color := TGxRGBA.Create(255, 255, 0, 96);
- uiContext.fillRect(gx+mFrameWidth, gy+mFrameHeight, mWidth-mFrameWidth*2, mHeight-mFrameHeight*2);
- end;
- end
- else if false and (self is TUISwitchBox) then
- begin
- uiContext.color := TGxRGBA.Create(255, 0, 0, 255);
- uiContext.fillRect(gx, gy, mWidth, mHeight);
- //writeln('frm: (', mFrameWidth, 'x', mFrameHeight, ')');
- end;
+ resetScissorNC();
drawControlPost(gx, gy);
finally
uiContext.clip := savedClip;
procedure TUIControl.drawControl (gx, gy: Integer);
begin
- //if (mParent = nil) then darkenRect(gx, gy, mWidth, mHeight, 64);
end;
procedure TUIControl.drawControlPost (gx, gy: Integer);
begin
- // shadow
+ // shadow for top-level controls
if (mParent = nil) and (mDrawShadow) and (mWidth > 0) and (mHeight > 0) then
begin
- //setScissorGLInternal(gx+8, gy+8, mWidth, mHeight);
uiContext.resetClip();
uiContext.darkenRect(gx+mWidth, gy+8, 8, mHeight, 128);
uiContext.darkenRect(gx+8, gy+mHeight, mWidth-8, 8, 128);
// ////////////////////////////////////////////////////////////////////////// //
-procedure TUIControl.mouseEvent (var ev: THMouseEvent);
+procedure TUIControl.mouseEvent (var ev: TFUIMouseEvent);
var
ctl: TUIControl;
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
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;
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;
end;
+// ////////////////////////////////////////////////////////////////////////// //
procedure TUITopWindow.drawControl (gx, gy: Integer);
begin
uiContext.color := mBackColor[getColorIndex];
procedure TUITopWindow.drawControlPost (gx, gy: Integer);
var
- cidx: Integer;
- hgt, sbhgt, iwdt, ihgt: Integer;
+ cidx, iwdt, ihgt: Integer;
+ ybot, xend, vhgt, vwdt: Integer;
begin
cidx := getColorIndex;
iwdt := uiContext.iconWinWidth(TGxContext.TWinIcon.Close);
if (mDragScroll = TXMode.Drag) then
begin
- //uiContext.color := mFrameColor[cidx];
drawFrame(gx, gy, iwdt, 0, mTitle, false);
end
else
begin
ihgt := uiContext.iconWinHeight(TGxContext.TWinIcon.Close);
- //uiContext.color := mFrameColor[cidx];
drawFrame(gx, gy, iwdt, 0, mTitle, true);
// vertical scroll bar
- hgt := mHeight-mFrameHeight*2;
- if (hgt > 0) and (mFullSize.h > hgt) then
- begin
- //writeln(mTitle, ': height=', mHeight-mFrameHeight*2, '; fullsize=', mFullSize.toString);
- sbhgt := mHeight-mFrameHeight*2+2;
- uiContext.fillRect(gx+mWidth-mFrameWidth+1, gy+mFrameHeight-1, mFrameWidth-3, sbhgt);
- hgt += mScrollY;
- if (hgt > mFullSize.h) then hgt := mFullSize.h;
- hgt := sbhgt*hgt div mFullSize.h;
- if (hgt > 0) then
- begin
- setScissor(mWidth-mFrameWidth+1, mFrameHeight-1, mFrameWidth-3, sbhgt);
- uiContext.darkenRect(gx+mWidth-mFrameWidth+1, gy+mFrameHeight-1+hgt, mFrameWidth-3, sbhgt, 128);
- end;
+ vhgt := mHeight-mFrameHeight*2;
+ if (mFullSize.h > vhgt) then
+ begin
+ ybot := mScrollY+vhgt;
+ resetScissorNC();
+ uiContext.drawVSBar(gx+mWidth-mFrameWidth+1, gy+mFrameHeight-1, mFrameWidth-3, vhgt+2, ybot, 0, mFullSize.h, mSBarFullColor[cidx], mSBarEmptyColor[cidx]);
+ end;
+ // horizontal scroll bar
+ vwdt := mWidth-mFrameWidth*2;
+ if (mFullSize.w > vwdt) then
+ begin
+ xend := mScrollX+vwdt;
+ resetScissorNC();
+ uiContext.drawHSBar(gx+mFrameWidth+1, gy+mHeight-mFrameHeight+1, vwdt-2, mFrameHeight-3, xend, 0, mFullSize.w, mSBarFullColor[cidx], mSBarEmptyColor[cidx]);
end;
// frame icon
setScissor(mFrameWidth, 0, iwdt, ihgt);
uiContext.color := mFrameIconColor[cidx];
uiContext.drawIconWin(TGxContext.TWinIcon.Close, gx+mFrameWidth, gy, mInClose);
end;
- // shadow
+ // shadow (no need to reset scissor, as draw should do it)
inherited drawControlPost(gx, gy);
end;
+// ////////////////////////////////////////////////////////////////////////// //
procedure TUITopWindow.activated ();
begin
if (mFocused = nil) or (mFocused = self) then
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
end;
-procedure TUITopWindow.mouseEvent (var ev: THMouseEvent);
+procedure TUITopWindow.mouseEvent (var ev: TFUIMouseEvent);
var
lx, ly: Integer;
- hgt, sbhgt: Integer;
+ vhgt, ytop: Integer;
+ vwdt, xend: Integer;
begin
if (not enabled) then exit;
if (mWidth < 1) or (mHeight < 1) then exit;
exit;
end;
- if (mDragScroll = TXMode.Scroll) then
+ if (mDragScroll = TXMode.VScroll) then
begin
- // check for vertical scrollbar
ly := ev.y-mY;
- if (ly < 7) then
- begin
- mScrollY := 0;
- end
- else
- begin
- sbhgt := mHeight-mFrameHeight*2+2;
- hgt := mHeight-mFrameHeight*2;
- if (hgt > 0) and (mFullSize.h > hgt) then
- begin
- hgt := (mFullSize.h*(ly-7) div (sbhgt-1))-(mHeight-mFrameHeight*2);
- mScrollY := nmax(0, hgt);
- hgt := mHeight-mFrameHeight*2;
- if (mScrollY+hgt > mFullSize.h) then mScrollY := nmax(0, mFullSize.h-hgt);
- end;
- end;
+ vhgt := mHeight-mFrameHeight*2;
+ ytop := uiContext.sbarPos(ly, mFrameHeight-1, vhgt+2, 0, mFullSize.h)-vhgt;
+ mScrollY := nmax(0, ytop);
+ if (ev.release) and (ev.but = ev.Left) then mDragScroll := TXMode.None;
+ ev.eat();
+ exit;
+ end;
+
+ if (mDragScroll = TXMode.HScroll) then
+ begin
+ lx := ev.x-mX;
+ vwdt := mWidth-mFrameWidth*2;
+ xend := uiContext.sbarPos(lx, mFrameWidth+1, vwdt-2, 0, mFullSize.w)-vwdt;
+ mScrollX := nmax(0, xend);
if (ev.release) and (ev.but = ev.Left) then mDragScroll := TXMode.None;
ev.eat();
exit;
exit;
end;
// check for vertical scrollbar
- if (lx >= mWidth-mFrameWidth+1) and (ly >= 7) and (ly < mHeight-mFrameHeight+1) then
+ if (lx >= mWidth-mFrameWidth+1) and (ly >= mFrameHeight-1) and (ly < mHeight-mFrameHeight+2) then
+ begin
+ vhgt := mHeight-mFrameHeight*2;
+ if (mFullSize.h > vhgt) then
+ begin
+ uiGrabCtl := self;
+ mDragScroll := TXMode.VScroll;
+ ev.eat();
+ ytop := uiContext.sbarPos(ly, mFrameHeight-1, vhgt+2, 0, mFullSize.h)-vhgt;
+ mScrollY := nmax(0, ytop);
+ exit;
+ end;
+ end;
+ // check for horizontal scrollbar
+ if (ly >= mHeight-mFrameHeight+1) and (lx >= mFrameWidth+1) and (lx < mWidth-mFrameWidth-1) then
begin
- sbhgt := mHeight-mFrameHeight*2+2;
- hgt := mHeight-mFrameHeight*2;
- if (hgt > 0) and (mFullSize.h > hgt) then
+ vwdt := mWidth-mFrameWidth*2;
+ if (mFullSize.w > vwdt) then
begin
- hgt := (mFullSize.h*(ly-7) div (sbhgt-1))-(mHeight-mFrameHeight*2);
- mScrollY := nmax(0, hgt);
uiGrabCtl := self;
- mDragScroll := TXMode.Scroll;
+ mDragScroll := TXMode.HScroll;
ev.eat();
+ xend := uiContext.sbarPos(lx, mFrameWidth+1, vwdt-2, 0, mFullSize.w)-vwdt;
+ mScrollX := nmax(0, xend);
exit;
end;
end;
procedure TUIBox.drawControl (gx, gy: Integer);
var
cidx: Integer;
- xpos: Integer;
+ //xpos: Integer;
begin
cidx := getColorIndex;
uiContext.color := mBackColor[cidx];
if (mHasFrame) then
begin
// draw frame
- drawFrame(gx, gy, 0, -1, mCaption, false);
- //uiContext.color := mFrameColor[cidx];
- //uiContext.rect(gx+3, gy+3, mWidth-6, mHeight-6);
- end
+ drawFrame(gx, gy, 0, mHAlign, mCaption, false);
+ end;
+ // no frame -- no caption
+ {
else if (Length(mCaption) > 0) then
begin
// draw caption
xpos += gx+mFrameWidth;
setScissor(mFrameWidth+1, 0, mWidth-mFrameWidth-2, uiContext.textHeight(mCaption));
- {
- if (mHasFrame) then
- begin
- uiContext.color := mBackColor[cidx];
- uiContext.fillRect(xpos-3, gy, uiContext.textWidth(mCaption)+4, 8);
- end;
- }
uiContext.color := mFrameTextColor[cidx];
uiContext.drawText(xpos, gy, mCaption);
end;
+ }
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
end;
-procedure TUISpan.drawControl (gx, gy: Integer);
-begin
-end;
-
-
// ////////////////////////////////////////////////////////////////////// //
procedure TUILine.AfterConstruction ();
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;
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();
end;
+procedure TUIButton.blurred ();
+begin
+ mPushed := false;
+end;
+
+
procedure TUIButton.drawControl (gx, gy: Integer);
var
wdt, hgt: Integer;
- xpos, ypos, xofsl, xofsr{, sofs}: Integer;
+ xpos, ypos, xofsl, xofsr, sofs: Integer;
cidx: Integer;
lch, rch: AnsiChar;
lstr, rstr: AnsiString;
hgt := mHeight-mShadowSize;
if (mPushed) {or (cidx = ClrIdxActive)} then
begin
- //sofs := mShadowSize;
+ sofs := mShadowSize;
gx += mShadowSize;
gy += mShadowSize;
end
else
begin
- //sofs := 0;
+ sofs := 0;
if (mShadowSize > 0) then
begin
uiContext.darkenRect(gx+mShadowSize, gy+hgt, wdt, mShadowSize, 96);
end;
uiContext.color := mBackColor[cidx];
- //setScissor(sofs, sofs, wdt, hgt);
uiContext.fillRect(gx, gy, wdt, hgt);
if (mVAlign < 0) then ypos := 0
else begin xpos := wdt-xofsl-xofsr-uiContext.textWidth(mText); if (mHAlign = 0) then xpos := xpos div 2; end;
xpos += xofsl;
- //setScissor(xofsl+sofs, sofs, wdt-xofsl-xofsr, hgt);
+ setScissor(sofs+xofsl, sofs, wdt-xofsl-xofsr, hgt);
uiContext.drawText(gx+xpos, ypos, mText);
if (mHotChar <> #0) and (mHotChar <> ' ') then
end;
-procedure TUIButton.mouseEvent (var ev: THMouseEvent);
+procedure TUIButton.mouseEvent (var ev: TFUIMouseEvent);
var
lx, ly: Integer;
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
+ if (ev = '+Enter') or (ev = '+Space') then
begin
+ focused := true;
+ mPushed := true;
ev.eat();
- doAction();
+ exit;
+ end;
+ if (focused) and ((ev = '-Enter') or (ev = '-Space')) then
+ begin
+ if (mPushed) then
+ begin
+ mPushed := false;
+ ev.eat();
+ doAction();
+ end
+ else
+ begin
+ ev.eat();
+ end;
exit;
end;
end;
end;
-procedure TUISwitchBox.mouseEvent (var ev: THMouseEvent);
+procedure TUISwitchBox.mouseEvent (var ev: TFUIMouseEvent);
var
lx, ly: Integer;
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
// ////////////////////////////////////////////////////////////////////////// //
+var
+ oldFocus: procedure () = nil;
+ oldBlur: procedure () = nil;
+
+procedure onWinFocus (); begin uiFocus(); if (assigned(oldFocus)) then oldFocus(); end;
+procedure onWinBlur (); begin fuiResetKMState(true); uiBlur(); if (assigned(oldBlur)) then oldBlur(); end;
+
initialization
registerCtlClass(TUIHBox, 'hbox');
registerCtlClass(TUIVBox, 'vbox');
registerCtlClass(TUICheckBox, 'checkbox');
registerCtlClass(TUIRadioBox, 'radiobox');
- uiContext := TGxContext.Create();
+ oldFocus := winFocusCB;
+ oldBlur := winBlurCB;
+ winFocusCB := onWinFocus;
+ winBlurCB := onWinBlur;
end.