From 726931d294c69c8dc279f16f49c5aaa63441a047 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Sat, 1 Aug 2015 06:28:38 +0000 Subject: [PATCH] cocoa: Implements basic TSpeedButton look git-svn-id: trunk@49580 - --- lcl/customdrawn_android.pas | 4 ++-- lcl/customdrawn_common.pas | 8 ++++---- lcl/customdrawn_mac.pas | 25 ++++++++++++++----------- lcl/customdrawn_winxp.pas | 4 ++-- lcl/customdrawncontrols.pas | 2 +- lcl/customdrawndrawers.pas | 12 ++++++------ 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/lcl/customdrawn_android.pas b/lcl/customdrawn_android.pas index 0a71d4a563..8a39627468 100644 --- a/lcl/customdrawn_android.pas +++ b/lcl/customdrawn_android.pas @@ -67,7 +67,7 @@ type // Standard Tab // =================================== // TCDButton - procedure DrawButton(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override; // TCDEdit procedure DrawEditBackground(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; @@ -572,7 +572,7 @@ begin end; -procedure TCDDrawerAndroid.DrawButton(ADest: TFPCustomCanvas; ASize: TSize; +procedure TCDDrawerAndroid.DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); var lDest: TCanvas absolute ADest; diff --git a/lcl/customdrawn_common.pas b/lcl/customdrawn_common.pas index 8e06d6871d..7ddb8e921c 100644 --- a/lcl/customdrawn_common.pas +++ b/lcl/customdrawn_common.pas @@ -55,7 +55,7 @@ type // Standard Tab // =================================== // TCDButton - procedure DrawButton(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override; // TCDEdit procedure DrawEditBackground(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; @@ -83,7 +83,7 @@ type procedure DrawScrollBar(ADest: TCanvas; ASize: TSize; AState: TCDControlState; AStateEx: TCDPositionedCStateEx); override; // TCDGroupBox - procedure DrawGroupBox(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawGroupBox(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); override; // TCDPanel procedure DrawPanel(ADest: TCanvas; ASize: TSize; @@ -702,7 +702,7 @@ begin end; procedure TCDDrawerCommon.DrawButton(ADest: TFPCustomCanvas; - ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); + ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); var Str: string; lGlyphLeftSpacing: Integer = 0; @@ -1275,7 +1275,7 @@ begin end; procedure TCDDrawerCommon.DrawGroupBox(ADest: TFPCustomCanvas; - ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); + ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); var FCaptionMiddle: integer = 0; lTextSize: TSize; diff --git a/lcl/customdrawn_mac.pas b/lcl/customdrawn_mac.pas index 9ded893776..72ba2baa36 100644 --- a/lcl/customdrawn_mac.pas +++ b/lcl/customdrawn_mac.pas @@ -21,7 +21,7 @@ type procedure DrawExpandTriangle(ADest: TCanvas; ASize: TSize; AX, AY: Integer; AFacing: TCDControlStateFlag); // - procedure DrawMacSquareButton(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawMacSquareButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); public function GetMeasures(AMeasureID: Integer): Integer; override; @@ -29,7 +29,7 @@ type // Standard Tab // =================================== // TCDButton - procedure DrawButton(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override; // =================================== // Common Controls Tab @@ -108,7 +108,7 @@ begin end; procedure TCDDrawerMac.DrawMacSquareButton(ADest: TFPCustomCanvas; - ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); + ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); var lDest: TCanvas absolute ADest; Str: string; @@ -117,6 +117,7 @@ var lFrameDark, lFrameMedDark, lFrameMedium, lFrameLight: TColor; lSelTop, lSelTopGrad, lSelBottomGrad, lSelBottom: TColor; lGradientTop, lGradientBottom: TColor; + lPosX, lPosY: Integer; begin // Main body with gradient if csfSunken in AState then @@ -129,7 +130,7 @@ begin lGradientTop := MAC_SQUARE_BUTTON_FOCUS_GRADIENT_TOP; lGradientBottom := MAC_SQUARE_BUTTON_FOCUS_GRADIENT_BOTTOM; end; - lRect := Bounds(0, 0, ASize.cx, ASize.cy); + lRect := Bounds(ADestPos.X, ADestPos.Y, ASize.cx, ASize.cy); lDest.GradientFill(lRect, lGradientTop, lGradientBottom, gdVertical); // outter rectangle @@ -139,27 +140,29 @@ begin lDest.Pen.Color := MAC_SQUARE_BUTTON_FOCUS_FRAME_OUTTER else lDest.Pen.Color := MAC_SQUARE_BUTTON_FRAME; - ADest.Rectangle(0, 0, ASize.cx, ASize.cy); + ADest.Rectangle(Bounds(ADestPos.X, ADestPos.Y, ASize.cx, ASize.cy)); //ADest.Rectangle(1, 1, ASize.cx-1, ASize.cy-1); // inner rectangle (only for focused) if (csfHasFocus in AState) and not (csfSunken in AState) then begin lDest.Pen.Color := MAC_SQUARE_BUTTON_FOCUS_FRAME_INNER; - ADest.Rectangle(1, 1, ASize.cx-1, ASize.cy-1); + ADest.Rectangle(Bounds(ADestPos.X+1, ADestPos.Y+1, ASize.cx-1, ASize.cy-1)); //ADest.Rectangle(2, 2, ASize.cx-2, ASize.cy-2); //ADest.Rectangle(3, 3, ASize.cx-3, ASize.cy-3); end; // Button text - ADest.Font.Assign(AStateEx.Font); + if AStateEx.Font <> nil then + ADest.Font.Assign(AStateEx.Font); ADest.Brush.Style := bsClear; ADest.Pen.Style := psSolid; if (csfSunken in AState) then ADest.Font.FPColor := colWhite; Str := AStateEx.Caption; - lDest.TextOut((ASize.cx - lDest.TextWidth(Str)) div 2, - (ASize.cy - lDest.TextHeight(Str)) div 2, Str); + lPosX := ADestPos.X + (ASize.cx - lDest.TextWidth(Str)) div 2; + lPosX := ADestPos.Y + (ASize.cy - lDest.TextHeight(Str)) div 2; + lDest.TextOut(lPosX, lPosY, Str); end; function TCDDrawerMac.GetMeasures(AMeasureID: Integer): Integer; @@ -172,10 +175,10 @@ begin end; end; -procedure TCDDrawerMac.DrawButton(ADest: TFPCustomCanvas; ASize: TSize; +procedure TCDDrawerMac.DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); begin - DrawMacSquareButton(ADest, ASize, AState, AStateEx); + DrawMacSquareButton(ADest, ADestPos, ASize, AState, AStateEx); end; procedure TCDDrawerMac.DrawToolBarItem(ADest: TCanvas; ASize: TSize; diff --git a/lcl/customdrawn_winxp.pas b/lcl/customdrawn_winxp.pas index e37efa46be..56d020d272 100644 --- a/lcl/customdrawn_winxp.pas +++ b/lcl/customdrawn_winxp.pas @@ -37,7 +37,7 @@ type // Standard Tab // =================================== // TCDButton - procedure DrawButton(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override; // TCDEdit procedure DrawEditFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; @@ -184,7 +184,7 @@ begin end; procedure TCDDrawerWinXP.DrawButton(ADest: TFPCustomCanvas; - ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); + ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); var lDest: TCanvas absolute ADest; Str: string; diff --git a/lcl/customdrawncontrols.pas b/lcl/customdrawncontrols.pas index b8032f86a6..2202b6f333 100644 --- a/lcl/customdrawncontrols.pas +++ b/lcl/customdrawncontrols.pas @@ -927,7 +927,7 @@ begin lControlId := GetControlId(); PrepareControlState; PrepareControlStateEx; - FDrawer.DrawControl(ACanvas, lSize, lControlId, FState, FStateEx); + FDrawer.DrawControl(ACanvas, Point(0, 0), lSize, lControlId, FState, FStateEx); end; procedure TCDControl.MouseEnter; diff --git a/lcl/customdrawndrawers.pas b/lcl/customdrawndrawers.pas index 4207ff7c22..59e8c7d03e 100644 --- a/lcl/customdrawndrawers.pas +++ b/lcl/customdrawndrawers.pas @@ -336,7 +336,7 @@ type function GetClientArea(ADest: TCanvas; ASize: TSize; AControlId: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx): TRect; virtual; abstract; // To set a different position to draw the control then (0, 0) use the window org of the canvas - procedure DrawControl(ADest: TCanvas; ASize: TSize; + procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); // General drawing routines. The ones using TFPCustomCanvas are reusable in LCL-CustomDrawn procedure DrawFocusRect(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize); virtual; abstract; @@ -355,7 +355,7 @@ type procedure DrawControl(ADest: TCanvas; ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; // TCDButton - procedure DrawButton(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); virtual; abstract; // TCDEdit procedure DrawEditBackground(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; @@ -383,7 +383,7 @@ type procedure DrawScrollBar(ADest: TCanvas; ASize: TSize; AState: TCDControlState; AStateEx: TCDPositionedCStateEx); virtual; abstract; // TCDGroupBox - procedure DrawGroupBox(ADest: TFPCustomCanvas; ASize: TSize; + procedure DrawGroupBox(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; // TCDPanel procedure DrawPanel(ADest: TCanvas; ASize: TSize; @@ -703,20 +703,20 @@ begin end; end; -procedure TCDDrawer.DrawControl(ADest: TCanvas; ASize: TSize; +procedure TCDDrawer.DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx ); begin case AControl of cidControl: DrawControl(ADest, ASize, AState, AStateEx); // - cidButton: DrawButton(ADest, ASize, AState, TCDButtonStateEx(AStateEx)); + cidButton: DrawButton(ADest, ADestPos, ASize, AState, TCDButtonStateEx(AStateEx)); cidEdit: DrawEdit(ADest, ASize, AState, TCDEditStateEx(AStateEx)); cidCheckBox: DrawCheckBox(ADest, ASize, AState, AStateEx); cidRadioButton:DrawRadioButton(ADest, ASize, AState, AStateEx); cidComboBox: DrawComboBox(ADest, ASize, AState, TCDEditStateEx(AStateEx)); cidScrollBar: DrawScrollBar(ADest, ASize, AState, TCDPositionedCStateEx(AStateEx)); - cidGroupBox: DrawGroupBox(ADest, ASize, AState, AStateEx); + cidGroupBox: DrawGroupBox(ADest, ADestPos, ASize, AState, AStateEx); cidPanel: DrawPanel(ADest, ASize, AState, TCDPanelStateEx(AStateEx)); // cidStaticText: DrawStaticText(ADest, ASize, AState, AStateEx);