SEKOMD Posted January 12 Posted January 12 (edited) Hello everyone! I found a working example of a _GDIPlus button on the forum. But how do I make rounded edges on the button? (square) Thanks in advance! sorry for my english please! expandcollapse popup#include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> Global $hGraphic, $hBrush, $hBrushFont, $hFont, $hFormat, $hFamily, $hGUI, $tRect_Coords[4] ;would be used in two functions therefore declared as global. Global $iTheme = 0 Example() Func Example() ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) ; Fill a rectangle _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBrush = _GDIPlus_BrushCreateSolid(0xAA43A6DF) $hBrushFont = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Light") $hFont = _GDIPlus_FontCreate($hFamily, 20, 2) $tRect_Coords[0] = 10 $tRect_Coords[1] = 10 $tRect_Coords[2] = 100 $tRect_Coords[3] = 100 ;Register for painting GUIRegisterMsg($WM_PAINT, "WM_PAINT") ;$WM_PAINT GUISetState() ; Loop until the user exits. Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN If CheckPointer($tRect_Coords) Then SetTheme(1) Case $GUI_EVENT_PRIMARYUP SetTheme(0) Case $GUI_EVENT_MOUSEMOVE If GetTheme() = 1 Then ContinueLoop If CheckPointer($tRect_Coords) Then SetTheme(2) Else SetTheme(0) EndIf EndSwitch Until 0 ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrushFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) ;Your Code must lie below ;Paint the string _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0) _GDIPlus_GraphicsFillRect($hGraphic, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], $hBrush) _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world", $hFont, _GDIPlus_RectFCreate($tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3]), $hFormat, $hBrushFont) ;End of your code _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE) Return 0;'GUI_RUNDEFMSG' EndFunc ;==>WM_PAINT Func CheckPointer(ByRef $aiCoords_ClientRel) Return _WinAPI_PtInRectEx(_WinAPI_GetMousePosX(True, $hGUI), _WinAPI_GetMousePosY(True, $hGUI), $aiCoords_ClientRel[0], $aiCoords_ClientRel[1], $aiCoords_ClientRel[2] + $aiCoords_ClientRel[0], $aiCoords_ClientRel[3] + $aiCoords_ClientRel[1]) EndFunc ;==>CheckPointer Func GetTheme() Return $iTheme EndFunc ;==>GetTheme Func SetTheme($Theme, $f_Redraw = true) If GetTheme() = $Theme Then Return 1 If $Theme = 0 Then ;Idle _GDIPlus_BrushSetSolidColor($hBrush, 0xAA43A6DF) _GDIPlus_BrushSetSolidColor($hBrushFont, 0xFFFFFFFF) ;Default Dimensions $tRect_Coords[0] = 10 $tRect_Coords[1] = 10 $tRect_Coords[2] = 100 $tRect_Coords[3] = 100 ElseIf $Theme = 1 Then ;MouseDown _GDIPlus_BrushSetSolidColor($hBrush, 0xFF3685B2) _GDIPlus_BrushSetSolidColor($hBrushFont, 0xFFFFFFFF) ;Compress a Bit $tRect_Coords[0] = 12 $tRect_Coords[1] = 12 $tRect_Coords[2] = 96 $tRect_Coords[3] = 96 ElseIf $Theme = 2 Then ;MouseOver _GDIPlus_BrushSetSolidColor($hBrush, 0xBB7BC1E9) _GDIPlus_BrushSetSolidColor($hBrushFont, 0xFFFFFFFF) ;Enlarge a Bit $tRect_Coords[0] = 8 $tRect_Coords[1] = 8 $tRect_Coords[2] = 104 $tRect_Coords[3] = 104 Else Return SetError(1, 0, 0) EndIf $iTheme = $Theme ConsoleWrite("CurTheme: " & $iTheme & @CRLF) If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE)) endfunc ;==>SetTheme Edited January 12 by SEKOMD
ioa747 Posted January 12 Posted January 12 (edited) It's not the solution for the _GDIPlus problem, but it does make buttons with rounded corners. Spoiler expandcollapse popup#include <GUIConstants.au3> #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") ; _IsPressed Global $hGUI = GUICreate("GUI") GUISetStyle(-1, $WS_EX_COMPOSITED) GUISetBkColor(0x0D1117) Global $id_1 = _CreateButton("INPUT1", 20, 20, 150, 30, "0xFFD800", 15) Global $id_2 = _CreateButton("INPUT2", 20, 60, 150, 30, "0xB6FF00") Global $id_3 = _CreateButton("INPUT3", 20, 100, 150, 35, "0x00FFFF", 10) Global $id_4 = _CreateButton("INPUT4", 20, 145, 150, 35, "0x0094FF") Global $id_5 = _CreateButton("INPUT5", 20, 190, 150, 40, "0xFF0000", 10) Global $id_6 = _CreateButton("INPUT6", 20, 240, 150, 40, "0xFF80EE") GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $id_1 ; to react to in mouse up While _IsPressed("01", $hDLL) ; 01 Left mouse button Sleep(100) WEnd ConsoleWrite("$id_1" & @CRLF) Case $id_2 ; to react to in mouse up While _IsPressed("01", $hDLL) ; 01 Left mouse button Sleep(100) WEnd ConsoleWrite("$id_2" & @CRLF) Case $id_3 ConsoleWrite("$id_3" & @CRLF) Case $id_4 ConsoleWrite("$id_4" & @CRLF) Case $id_5 ConsoleWrite("$id_5" & @CRLF) Case $id_6 ConsoleWrite("$id_6" & @CRLF) EndSwitch WEnd DllClose($hDLL) ;---------------------------------------------------------------------------------------- Func _CreateButton($Text, $Left, $Top, $Width, $Height, $Color, $Corner = 10) ; $Corner Valid value [0=Rectangle] to [($Height/2)=Round], Default=($Height/4) ; Validate parameters If $Corner < 0 Or $Corner = Default Then $Corner = $Height / 4 If $Corner > $Height / 2 Then $Corner = $Height / 2 If $Width <= 0 Or $Height <= 0 Then Return SetError(1, 0, 0) EndIf ; graphic GUICtrlCreateGraphic($Left, $Top, $Width, $Height) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $Color, $Color) ; body GUICtrlSetGraphic(-1, $GUI_GR_RECT, $Corner, 0, $Width - ($Corner * 2), $Height) ; outer part GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, $Corner, $Width, $Height - ($Corner * 2)) ; inner part ; corners GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, $Corner * 2, $Corner * 2) ; Top-left GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, $Width - $Corner * 2, 0, $Corner * 2, $Corner * 2) ; Top-right GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, $Height - $Corner * 2, $Corner * 2, $Corner * 2) ; Bottom-left GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, $Width - $Corner * 2, $Height - $Corner * 2, $Corner * 2, $Corner * 2) ; Bottom-right GUICtrlSetState(-1, $GUI_DISABLE) $idCtrl = GUICtrlCreateLabel($Text, $Left + $Corner, $Top + ($Height * 0.2), $Width - ($Corner * 2), $Height * 0.6, BitOR($SS_NOTIFY, $SS_CENTER), $WS_EX_COMPOSITED) GUICtrlSetFont($idCtrl, $Height * 0.4, 400) GUICtrlSetBkColor($idCtrl, $Color) Return $idCtrl EndFunc ;==>_CreateButton ;---------------------------------------------------------------------------------------- with the code from 212533-input-control-with-label-and-rounded-corners Edited January 12 by ioa747 SEKOMD 1 I know that I know nothing
Nine Posted January 12 Posted January 12 Here how you could draw a rounded button with GDI+ : expandcollapse popup#include <GDIPlus.au3> #include <GUIConstants.au3> Example() Func Example() Local $hGUI = GUICreate("GDI+", 500, 300) GUISetState(@SW_SHOW) _GDIPlus_Startup() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; antialiasing _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF) Local $hBrush = _GDIPlus_BrushCreateSolid(0x7F8800AA) Local $hPen = _GDIPlus_PenCreate(0xFF8800AA, 2) Local $hPen2 = _GDIPlus_PenCreate(0xFFFF0000, 2) Local $aPoints[4][2] = [[3]] Local $hPath = _GDIPlus_PathCreate() $aPoints[1][0] = 0 $aPoints[1][1] = 35 $aPoints[2][0] = 5 $aPoints[2][1] = 5 $aPoints[3][0] = 35 $aPoints[3][1] = 0 _GDIPlus_PathAddCurve($hPath, $aPoints) _GDIPlus_PathAddLine($hPath, 35, 0, 150, 0) $aPoints[1][0] = 150 $aPoints[1][1] = 0 $aPoints[2][0] = 180 $aPoints[2][1] = 5 $aPoints[3][0] = 185 $aPoints[3][1] = 35 _GDIPlus_PathAddCurve($hPath, $aPoints) $aPoints[1][0] = 185 $aPoints[1][1] = 35 $aPoints[2][0] = 180 $aPoints[2][1] = 65 $aPoints[3][0] = 150 $aPoints[3][1] = 70 _GDIPlus_PathAddCurve($hPath, $aPoints) _GDIPlus_PathAddLine($hPath, 150, 70, 35, 70) $aPoints[1][0] = 35 $aPoints[1][1] = 70 $aPoints[2][0] = 5 $aPoints[2][1] = 65 $aPoints[3][0] = 0 $aPoints[3][1] = 35 _GDIPlus_PathAddCurve($hPath, $aPoints) _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) Local $hBrushFont = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Light") Local $hFont = _GDIPlus_FontCreate($hFamily, 18, 1) _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world !", $hFont, _GDIPlus_RectFCreate(20, 20, 160, 40), $hFormat, $hBrushFont) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrushFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PathDispose($hPath) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example I hardcoded everything since I am not sure if this is what you want. SEKOMD and ioa747 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
ioa747 Posted January 12 Posted January 12 (edited) a little different expandcollapse popup#include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> Global $hGraphic, $hBrush, $hBrushFont, $hFont, $hFormat, $hFamily, $hGUI, $tRect_Coords[4] Global $iTheme = 0 Example() ;--------------------------------------------------------------------------------------- Func Example() ; Create GUI $hGUI = GUICreate("GDI+ Centered Text", 400, 300) ; Initialize GDI+ _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBrush = _GDIPlus_BrushCreateSolid(0xAA43A6DF) ; Blue $hBrushFont = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; White $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) ; Horizontal alignment _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ; Vertical alignment $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Light") $hFont = _GDIPlus_FontCreate($hFamily, 20, 2) ; Rectangle coordinates $tRect_Coords[0] = 50 $tRect_Coords[1] = 50 $tRect_Coords[2] = 200 $tRect_Coords[3] = 100 ; Register for painting GUIRegisterMsg($WM_PAINT, "WM_PAINT") GUISetState() ; Loop until the user exits Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN If CheckPointer($tRect_Coords) Then SetTheme(1) Case $GUI_EVENT_PRIMARYUP SetTheme(0) Case $GUI_EVENT_MOUSEMOVE If GetTheme() = 1 Then ContinueLoop If CheckPointer($tRect_Coords) Then SetTheme(2) Else SetTheme(0) EndIf EndSwitch Until 0 ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrushFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example ;--------------------------------------------------------------------------------------- Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) ; Clear the canvas _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0) ; Create a path for the rounded rectangle Local $hPath = _GDIPlus_PathCreate() _GDIPlus_PathAddRoundRect($hPath, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], 20) ; Fill the rounded rectangle _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ; Optionally draw the outline Local $hPen = _GDIPlus_PenCreate(0xFF3685B2, 2) ; Darker Blue border _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ; Draw the string centered in the rectangle _GDIPlus_GraphicsDrawStringEx($hGraphic, "Click Me", $hFont, _GDIPlus_RectFCreate($tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3]), $hFormat, $hBrushFont) ; Clean up _GDIPlus_PenDispose($hPen) _GDIPlus_PathDispose($hPath) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE) Return 0 EndFunc ;==>WM_PAINT ;--------------------------------------------------------------------------------------- Func CheckPointer(ByRef $aiCoords_ClientRel) Return _WinAPI_PtInRectEx(_WinAPI_GetMousePosX(True, $hGUI), _WinAPI_GetMousePosY(True, $hGUI), $aiCoords_ClientRel[0], $aiCoords_ClientRel[1], $aiCoords_ClientRel[0] + $aiCoords_ClientRel[2], $aiCoords_ClientRel[1] + $aiCoords_ClientRel[3]) EndFunc ;==>CheckPointer ;--------------------------------------------------------------------------------------- Func GetTheme() Return $iTheme EndFunc ;==>GetTheme ;--------------------------------------------------------------------------------------- Func SetTheme($Theme, $f_Redraw = True) If GetTheme() = $Theme Then Return 1 If $Theme = 0 Then ; Idle _GDIPlus_BrushSetSolidColor($hBrush, 0xAA43A6DF) ; Blue $tRect_Coords[0] = 50 $tRect_Coords[1] = 50 ElseIf $Theme = 1 Then ; MouseDown _GDIPlus_BrushSetSolidColor($hBrush, 0xFF3685B2) ; Darker Blue $tRect_Coords[0] = 52 $tRect_Coords[1] = 52 ; Move slightly down ElseIf $Theme = 2 Then ; MouseOver _GDIPlus_BrushSetSolidColor($hBrush, 0xBB7BC1E9) ; Lighter Blue $tRect_Coords[0] = 50 $tRect_Coords[1] = 50 Else Return SetError(1, 0, 0) EndIf $iTheme = $Theme If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE)) EndFunc ;==>SetTheme ;--------------------------------------------------------------------------------------- Func _GDIPlus_PathAddRoundRect($hPath, $iX, $iY, $iWidth, $iHeight, $iRadius) Local $iDiameter = $iRadius * 2 _GDIPlus_PathAddArc($hPath, $iX, $iY, $iDiameter, $iDiameter, 180, 90) _GDIPlus_PathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - $iRadius, $iY) _GDIPlus_PathAddArc($hPath, $iX + $iWidth - $iDiameter, $iY, $iDiameter, $iDiameter, 270, 90) _GDIPlus_PathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - $iRadius) _GDIPlus_PathAddArc($hPath, $iX + $iWidth - $iDiameter, $iY + $iHeight - $iDiameter, $iDiameter, $iDiameter, 0, 90) _GDIPlus_PathAddLine($hPath, $iX + $iWidth - $iRadius, $iY + $iHeight, $iX + $iRadius, $iY + $iHeight) _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - $iDiameter, $iDiameter, $iDiameter, 90, 90) _GDIPlus_PathAddLine($hPath, $iX, $iY + $iHeight - $iRadius, $iX, $iY + $iRadius) EndFunc ;==>_GDIPlus_PathAddRoundRect ;--------------------------------------------------------------------------------------- Edited January 12 by ioa747 SEKOMD and Nine 1 1 I know that I know nothing
Nine Posted January 12 Posted January 12 I like the AddArc. It is simpler to code than AddCurve. Here my take on your function : Func _GDIPlus_PathAddRoundRect(ByRef $hPath, $iX, $iY, $iWidth, $iHeight, $iRadius) _GDIPlus_PathAddArc($hPath, $iX, $iY, $iRadius, $iHeight, 90, 180) _GDIPlus_PathAddArc($hPath, $iX + $iWidth, $iY, $iRadius, $iHeight, -90, 180) _GDIPlus_PathCloseFigure($hPath) EndFunc Called this way : _GDIPlus_PathAddRoundRect($hPath, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], 60) Adding : _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; antialiasing Make really nice rounded buttons... SEKOMD and ioa747 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
ioa747 Posted January 12 Posted January 12 another approach for buttons with rounded corners https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263 SEKOMD and argumentum 1 1 I know that I know nothing
Solution Popular Post UEZ Posted January 12 Solution Popular Post Posted January 12 I modified one of my old script from 2014: expandcollapse popup;Coded by UEZ #include <GUIConstantsEx.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hGUI = GUICreate("GDI+ Test", 200, 100) GUISetBkColor(0x505050) Global Const $iPicBtn = GUICtrlCreatePic("", 50, 28, 100, 44) Global $aButtons = _GDIPlus_BitmapCreateRoundedButtonAndText("install", 100, 44) _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) GUISetState() Global $aMouseInfo, $bShow = False, $bHide = False Do If WinActive($hGUI) Then $aMouseInfo = GUIGetCursorInfo($hGUI) ;hover simulation Switch $aMouseInfo[4] Case $iPicBtn _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[1])) $bShow = True $bHide = False Case Else _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) $bHide = True $bShow = False EndSwitch EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($aButtons[0]) _WinAPI_DeleteObject($aButtons[1]) _GDIPlus_Shutdown() Exit Case $iPicBtn MsgBox(0, "Information", "Button pressed") EndSwitch Until False ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_BitmapCreateRoundedButtonAndText ; Description ...: Draw rounded button ; Syntax ........: _GDIPlus_BitmapCreateRoundedButtonAndText($sString, $iWidth, $iHeight[, $iBgColor = 0xFF1BA0E1[, $iFontSize = 16[, $sFont = "Times New Roman"[, ; $iHoverColor = 0xFFC9388C[, $iFrameSize = 2[, $iFontFrameColor = 0x408AD5EA[, $iFontColor = 0xFFFFFFFF]]]]]]) ; Parameters ....: $sString - A string value. ; $iWidth - An integer value. ; $iHeight - An integer value. ; $iBgColor - [optional] An integer value. Default is 0xFF1BA0E1. ; $iFontSize - [optional] An integer value. Default is 16. ; $sFont - [optional] A string value. Default is "Times New Roman". ; $iHoverColor - [optional] An integer value. Default is 0xFFC9388C. ; $iFrameSize - [optional] An integer value. Default is 2. ; $iFontFrameColor - [optional] An integer value. Default is 0x408AD5EA. ; $iFontColor - [optional] An integer value. Default is 0xFFFFFFFF. ; Return values .: an array with 2 GDI bitmap handles -> [0]: default button, [1]: hover button ; Author ........: UEZ ; Version .......: 0.85 build 2025-01-12 ; Modified ......: ; Remarks .......: Dispose returned GDI bitmap handles when done ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateRoundedButtonAndText($sString, $iWidth, $iHeight, $iBgColor = 0xFF1BA0E1, $iFontSize = 16, $sFont = "Times New Roman", $iHoverColor = 0xF0FFFFFF, $iFrameSize = 2, $iFontFrameColor = 0x408AD5EA, $iFontColor = 0xFFFFFFFF) ;some checks If $sString = "" Then Return SetError(1, 0, 0) If Int($iWidth) < $iFrameSize * 2 Then Return SetError(2, 0, 0) If Int($iHeight) < $iFrameSize * 2 Then Return SetError(3, 0, 0) ;create font objects Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;center string on X axis _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;center string on Y axis ;create bitmap and graphics context handles Local Const $aBitmaps[2] = [_GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)] Local Const $aGfxCtxt[2] = [_GDIPlus_ImageGetGraphicsContext($aBitmaps[0]), _GDIPlus_ImageGetGraphicsContext($aBitmaps[1])] ;set drawing quality _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[0], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[1], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($aGfxCtxt[0], $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT) ;define brush and pen objects Local Const $hBrushFontColor = _GDIPlus_BrushCreateSolid($iFontColor) ;, $hBrushBGColor = _GDIPlus_BrushCreateSolid($iBgColor) Local Const $hPenFontFrameColor = _GDIPlus_PenCreate($iFontFrameColor, $iFrameSize), $hPenHoverColor = _GDIPlus_PenCreate($iHoverColor, $iFrameSize) ;create path object Local Const $hPath = _GDIPlus_PathCreate() ;create cloned path object for string measurement Local Const $hPath_Dummy = _GDIPlus_PathClone($hPath) _GDIPlus_PathAddString($hPath_Dummy, $sString, $tLayout, $hFamily, 0, $iFontSize, $hFormat) _GDIPlus_PathStartFigure($hPath) Local $fArcSize = $iWidth * 0.33333 _GDIPlus_PathAddArc($hPath, $iFrameSize, $iHeight - $fArcSize - $iFrameSize, $fArcSize, $fArcSize, 180, -90) ;BR _GDIPlus_PathAddArc($hPath, $iWidth - $fArcSize - $iFrameSize, $iHeight - $fArcSize - $iFrameSize, $fArcSize, $fArcSize, -270, -90) ;BL _GDIPlus_PathAddArc($hPath, $iWidth - $fArcSize - $iFrameSize, $iFrameSize, $fArcSize, $fArcSize, 0, -90) ;TR _GDIPlus_PathAddArc($hPath, $iFrameSize, $iFrameSize, $fArcSize, $fArcSize, -90, -90) ;TL _GDIPlus_PathCloseFigure($hPath) Local Const $hPath_Clone = _GDIPlus_PathClone($hPath) Local Const $hBrushBGColor = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetSurroundColor($hBrushBGColor, $iBgColor) _GDIPlus_PathBrushSetCenterColor($hBrushBGColor, 0xFFFFFFFF) _GDIPlus_PathBrushSetCenterPoint($hBrushBGColor, $iWidth / 2, $iHeight / 2) _GDIPlus_PathBrushSetSigmaBlend($hBrushBGColor, 1, 0.33333) _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushBGColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) _GDIPlus_PathReset($hPath) ;add string to path _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 1, $iFontSize, $hFormat) ;clear bitmap and draw string _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushFontColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) ;draw rectangle on cloned bitmap for hover effect _GDIPlus_GraphicsDrawImageRect($aGfxCtxt[1], $aBitmaps[0], 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDrawPath($aGfxCtxt[1], $hPath_Clone, $hPenHoverColor) ;dispose object resources _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PathDispose($hPath) _GDIPlus_PathDispose($hPath_Dummy) _GDIPlus_PathDispose($hPath_Clone) _GDIPlus_GraphicsDispose($aGfxCtxt[0]) _GDIPlus_GraphicsDispose($aGfxCtxt[1]) _GDIPlus_BrushDispose($hBrushFontColor) _GDIPlus_BrushDispose($hBrushBGColor) _GDIPlus_PenDispose($hPenFontFrameColor) _GDIPlus_PenDispose($hPenHoverColor) ;create GDI bitmap for later usage Local $aHBitmaps[2] = [_GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[0]), _GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[1])] ;dispose GDI+ bitmaps _GDIPlus_BitmapDispose($aBitmaps[0]) _GDIPlus_BitmapDispose($aBitmaps[1]) Return $aHBitmaps EndFunc ;==>_GDIPlus_BitmapCreateRoundedButtonAndText robertocm, spudw2k, Danyfirex and 2 others 4 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now