From 09dd6a700927a12733e810ac5dfcd5e86fbaa52c Mon Sep 17 00:00:00 2001 From: gambas Date: Wed, 16 Jun 2021 01:51:54 +0200 Subject: [PATCH] MenuButton: The background color is now used for coloring the button background. [GB.FORM] * NEW: MenuButton: The background color is now used for coloring the button background. * BUG: MenuButton: Fix how style flags are used for drawing the control. --- comp/src/gb.form/.icon.png | Bin 5356 -> 5356 bytes comp/src/gb.form/.project | 2 +- comp/src/gb.form/.src/Button/MenuButton.class | 43 ++++++++++++------ .../.src/File/Chooser/FDirChooser.class | 2 +- comp/src/gb.form/.src/Test/FMain.class | 2 +- .../gb.form/.src/Test/FTestMenuButton.form | 2 + comp/src/gb.form/map/icon.map | 1 + 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/comp/src/gb.form/.icon.png b/comp/src/gb.form/.icon.png index 6a1ac5b9c356953582c27085825b4b4a5e2f1974..47885d02a1fcbcef1b0499d5074bcabb4bf69130 100644 GIT binary patch delta 25 hcmaE(`9^a>0^{+CiAy<(ZkV+!mUrL0nUC?FFaVgR3iSX0 delta 25 hcmaE(`9^a>0^{L{iAy;O6U>_LR?Rox%*S|77yy?F3g`d; diff --git a/comp/src/gb.form/.project b/comp/src/gb.form/.project index 1b548c77c..3ae64608b 100644 --- a/comp/src/gb.form/.project +++ b/comp/src/gb.form/.project @@ -1,6 +1,6 @@ # Gambas Project File 3.0 Title=More controls for graphical components -Startup=FMain +Startup=FTestMenuButton Icon=.hidden/icon.png Version=3.16.90 VersionFile=1 diff --git a/comp/src/gb.form/.src/Button/MenuButton.class b/comp/src/gb.form/.src/Button/MenuButton.class index 931f85914..53e2293c5 100644 --- a/comp/src/gb.form/.src/Button/MenuButton.class +++ b/comp/src/gb.form/.src/Button/MenuButton.class @@ -25,6 +25,7 @@ Property MenuOnly As Boolean Property Value As Boolean Property AutoResize As Boolean Property Border As Boolean +Property Background As Integer Private $hDrawingArea As DrawingArea Private $hPicture As Picture @@ -42,6 +43,7 @@ Private $bArrow As Boolean Private $bAutoResize As Boolean Private $bMenuOnly As Boolean Private $hLastFocus As Control +Private $iBg As Integer = Color.Default Static Private $hCurrent As MenuButton Static Private $hCurrentMenu As Menu @@ -415,13 +417,11 @@ Public Sub DrawingArea_Draw() iFlag = Style.StateOf($hDrawingArea) If $hCurrent Then - If $hCurrent = Me Then iFlag = iFlag Or Draw.Hover + If $hCurrent = Me Then iFlag = iFlag Or Style.Hovered Else - If $bInside Then iFlag = iFlag Or Draw.Hover + If $bInside And If $hDrawingArea.HasFocus Then iFlag = iFlag Or Style.Hovered Endif - 'If $bInside And If Me.Enabled And If Not Me.Design Then iFlag += Draw.Hover - 'If Not Me.Enabled Then iFlag += Draw.Disabled - If $hDrawingArea.HasFocus Then iFlag += Draw.Hover + If $hDrawingArea.HasFocus Then iFlag = iFlag Or Style.HasFocus bDrawArrow = $bArrow And (Me.W > DS * 4) @@ -433,14 +433,17 @@ Public Sub DrawingArea_Draw() If bMenu Then Paint.FillRect(1, 1, Me.W - 2, Me.H - 2, Color.SelectedBackground) Else - 'Paint.FillRect(1, 1, Me.W - 2, Me.H - 2, Style.BackgroundOf(Me)) If $bInsideArrow Or If $bMenuOnly Then - Style.PaintButton(0, 0, Me.W, Me.H, False, iFlag, bFlat) + Style.PaintButton(0, 0, Me.W, Me.H, False, iFlag, bFlat, $iBg) Else - Style.PaintButton(0, 0, Me.W, Me.H, $bPressed, iFlag, bFlat) + Style.PaintButton(0, 0, Me.W, Me.H, $bPressed, iFlag, bFlat, $iBg) Endif Endif + If $bPressed And If Not bMenu Then + Paint.Translate(1, 1) + Endif + If $hPicture Then If System.RightToLeft Then @@ -459,15 +462,15 @@ Public Sub DrawingArea_Draw() If bDrawArrow Then If System.RightToLeft Then - Style.PaintArrow(DS, 0, DS, Me.H, Align.Bottom, iFlag) + Style.PaintArrow(DS, 0, DS, Me.H, Align.Bottom) Else - Style.PaintArrow(Me.W - DS * 2, 0, DS, Me.H, Align.Bottom, iFlag) + Style.PaintArrow(Me.W - DS * 2, 0, DS, Me.H, Align.Bottom) Endif Endif If $sActualText Then - iFg = Style.ForegroundOf(Me) + iFg = Style.ForegroundOf($hDrawingArea) If Not Me.Enabled Then iFg = Color.Merge(Color.ButtonBackground, iFg) If bMenu Then iFg = Color.SelectedForeground Paint.Background = iFg @@ -475,6 +478,7 @@ Public Sub DrawingArea_Draw() sText = $sActualText X = DS + Y = 0 W = Me.W - DS * 2 If Not $hPicture And If Not bDrawArrow Then @@ -491,8 +495,8 @@ Public Sub DrawingArea_Draw() Endif Endif - Paint.ClipRect = Rect(X, 0, W, Me.H) - Paint.DrawText(sText, X, 0, W, Me.H, iAlign) + Paint.ClipRect = Rect(X, Y, W, Me.H) + Paint.DrawText(sText, X, Y, W, Me.H, iAlign) If $iShortcutPos Then hFont = Paint.Font @@ -582,3 +586,16 @@ Public Sub _RestoreLastFocus() Endif End + +Private Function Background_Read() As Integer + + Return $iBg + +End + +Private Sub Background_Write(Value As Integer) + + $iBg = Value + $hDrawingArea.Refresh + +End diff --git a/comp/src/gb.form/.src/File/Chooser/FDirChooser.class b/comp/src/gb.form/.src/File/Chooser/FDirChooser.class index a8a53e177..47d92ca31 100644 --- a/comp/src/gb.form/.src/File/Chooser/FDirChooser.class +++ b/comp/src/gb.form/.src/File/Chooser/FDirChooser.class @@ -868,7 +868,7 @@ Public Sub IsDialogButtonVisible() As Boolean End - Private Sub CheckFile() As Boolean ' FIXME: If 'As Boolean' is forgotten, and 'Return True' is removed, we can get an interpreter crash +Private Sub CheckFile() As Boolean ' FIXME: If 'As Boolean' is forgotten, and 'Return True' is removed, we can get an interpreter crash Dim sPath As String Dim sFile As String diff --git a/comp/src/gb.form/.src/Test/FMain.class b/comp/src/gb.form/.src/Test/FMain.class index 6aa097847..e7bb04458 100644 --- a/comp/src/gb.form/.src/Test/FMain.class +++ b/comp/src/gb.form/.src/Test/FMain.class @@ -1,6 +1,5 @@ ' Gambas class file - Public Sub TreeView1_Menu() Debug @@ -11,6 +10,7 @@ Public Sub Form_Open() Component.Load("gb.form.dialog") Debug Style.Name + Me.Test End diff --git a/comp/src/gb.form/.src/Test/FTestMenuButton.form b/comp/src/gb.form/.src/Test/FTestMenuButton.form index 619004b02..96a878911 100644 --- a/comp/src/gb.form/.src/Test/FTestMenuButton.form +++ b/comp/src/gb.form/.src/Test/FTestMenuButton.form @@ -79,9 +79,11 @@ MoveScaled(9,31,20,4) Text = ("Menu button") Picture = Picture["img/32/filter-menu.png"] + Border = False } { MenuButton5 MenuButton MoveScaled(9,37,20,4) + Background = Color.Green Text = ("Menu button") } { MenuButton6 MenuButton diff --git a/comp/src/gb.form/map/icon.map b/comp/src/gb.form/map/icon.map index 5c0e6e327..85e430f6e 100644 --- a/comp/src/gb.form/map/icon.map +++ b/comp/src/gb.form/map/icon.map @@ -125,6 +125,7 @@ image $(mime)/image-x-generic important emblems/emblem-important indent actions/format-indent-more info status/dialog-information +inheritance actions/code-class insert-image actions/insert-image insert-link actions/insert-link insert-text actions/insert-text