+ inherited AfterConstruction();
+ mHAlign := -1;
+ mVAlign := 0;
+ mCanFocus := true;
+ mDefSize := TLaySize.Create(Length(mText)*8+8, 8);
+ mCtl4Style := 'button';
+end;
+
+
+function TUIButton.parseProperty (const prname: AnsiString; par: TTextParser): Boolean;
+begin
+ result := inherited parseProperty(prname, par);
+ if result then
+ begin
+ mDefSize := TLaySize.Create(Length(mText)*8+8*2, 8);
+ end;
+end;
+
+
+procedure TUIButton.drawControl (gx, gy: Integer);
+var
+ xpos, ypos: Integer;
+ cidx: Integer;
+ lch, rch: AnsiChar;
+begin
+ cidx := getColorIndex;
+ fillRect(gx, gy, mWidth, mHeight, mBackColor[cidx]);
+
+ if (mDefault) then begin lch := '<'; rch := '>'; end
+ else if (mCancel) then begin lch := '{'; rch := '}'; end
+ else begin lch := '['; rch := ']'; end;
+
+ if (mVAlign < 0) then ypos := 0
+ else if (mVAlign > 0) then ypos := mHeight-8
+ else ypos := (mHeight-8) div 2;
+
+ drawText8(gx, gy+ypos, lch, mTextColor[cidx]);
+ drawText8(gx+mWidth-8, gy+ypos, rch, mTextColor[cidx]);
+
+ if (Length(mText) > 0) then
+ begin
+ if (mHAlign < 0) then xpos := 0
+ else if (mHAlign > 0) then xpos := mWidth-Length(mText)*8
+ else xpos := (mWidth-Length(mText)*8) div 2;
+
+ setScissor(8, 0, mWidth-16, mHeight);
+ drawText8(gx+xpos+8, gy+ypos, mText, mTextColor[cidx]);
+ end;
+end;
+
+
+procedure TUIButton.mouseEvent (var ev: THMouseEvent);
+var
+ lx, ly: Integer;
+begin
+ inherited mouseEvent(ev);
+ if (uiGrabCtl = self) then
+ begin
+ ev.eat();
+ if (ev = '-lmb') and focused and toLocal(ev.x, ev.y, lx, ly) then
+ begin
+ doAction();
+ end;
+ exit;
+ end;
+ if (ev.eaten) or (ev.cancelled) or (not mEnabled) or not focused then exit;
+ ev.eat();
+end;
+
+
+procedure TUIButton.keyEvent (var ev: THKeyEvent);
+begin
+ inherited keyEvent(ev);
+ if (not ev.eaten) and (not ev.cancelled) and (mEnabled) then
+ begin
+ if (ev = 'Enter') or (ev = 'Space') then
+ begin
+ ev.eat();
+ doAction();
+ exit;
+ end;
+ end;