Jump to content
Sign in to follow this  
Nemcija

Progessbar with text that turns it color

Recommended Posts

Hey,

Is it possible to create a progressbar with text on it that turns it color (inverted or something) if the background turns dark?

I've made a small sketch of it:

post-7467-0-62293000-1314811990_thumb.pn

Regards Nem

Edited by Nemcija

[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites

Nope this does not what I want.

Look again

That feature was requested in the thread

; Function Name: _ProgressSetFont()

; Description:: Sets the Font and Color of the Text of the Progressbar

; Parameter(s): $ID : ID of Progressbar

; $Font : Name of the font (empty String "" to do not change)

; $size : [Optional] size of the font ( 0 or negative to leave the old)

; $Styles : [Optional] The style of the typeface. Can be a combination of the following:

; 0 - Normal weight or thickness of the typeface

; 1 - Bold typeface

; 2 - Italic typeface

; 4 - Underline

; 8 - Strikethrough

; ( -1, negative to leave the old)

; $ARGBcolor : [Optional] the color of the font, can be RGB or ARGB (depending on $isARGB)

; (empty String "" to do not change)

; $InverseColor: [Optional] should the color be inversed when the bar is under the text?

; $isARGB : [Optional] Sets, whether $ARGBcolor is RGB (False, default) or ARGB (True)

; Requirement(s): This UDF

; Return Value(s): Success: 1, Error: 0

; Author(s): Prog@ndy

#include <StaticConstants.au3>
#include <GDIpProgress.au3>
Global $Gui, $nMsg, $iPercent, $slid, $sID, $iPos
$Gui = GUICreate("Gradient ProgressBar", 400, 350)
$slid = GUICtrlCreateSlider(5, 20, 310, 30)
GUICtrlSetData(-1, 50)
$sID = _ProgressCreate(10, 60, 300, 40)
_ProgressSet($sID, 50)
_ProgressSetText($sID, "Install %P%%")
_ProgressSetColors($sID, 0x89A49B, 0xF0D6C7, 0xFFFFFF, 0xFFFFFF)
_ProgressSetFont($sID, "", -1, -1, 0x000000, 1)
GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _ProgressDelete($sID) ; MUST BE DONE ON EXIT
            _Progress_CallBack_Free(1) ; Force Killing Timer
            _GDIPlus_Shutdown()
            Exit
  Case 0
   ;The GUIRegisterMsg() with WM_HSCROLL/WM_VSCROLL on-event method is preferable to polling in the message loop
   $iPos = GUICtrlRead($slid)
   If $iPercent <> $iPos Then
    $iPercent = $iPos
    _ProgressSet($sID, $iPercent)
   EndIf
    EndSwitch
WEnd
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

Well, i came to late, but anyway i just write this, it is far to be perfect and is just an GDI+ exersice.

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GDIP.au3>
 
Global $iPad = 2
Global $iWidth = 360
Global $iHeight = 30
Global $iMax = 100
Global $iValue = 50
Global $iStep = $iWidth / $iMax
 
$hGui = GUICreate("GDI+ ProgressBar by monoscout999")
;~ GUISetBkColor(0X123456)
$iPic = GUICtrlCreatePic("", 20 - $iPad, 100 - $iPad, $iWidth + $iPad * 2, $iHeight + $iPad * 2)
 
_GDIPlus_Startup()
 
$hGraphics = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($iPic))
 
$BackBufferBMP = _GDIPlus_BitmapCreateFromGraphics($iWidth + $iPad * 2, $iHeight + $iPad * 2, $hGraphics)
$BackBufferGr = _GDIPlus_ImageGetGraphicsContext($BackBufferBMP)
 
_GDIPlus_GraphicsSetSmoothingMode($BackBufferGr,2)
 
$hFBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF) ; Fill area
$hEBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; Empty area & Fill text area
;~ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
 
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$tLayout = _GDIPlus_RectFCreate((($iWidth + $iPad * 2) / 2) - 25, $iPad*4)
 
$hPath = _GDIPLus_pathcreate()
 
AdlibRegister("Drawing", 50)
 
GUISetState()
 
For $i = 1 to 100
    $iValue = $i
    Sleep(50)
Next
 
Do
Until GUIGetMsg() = -3
 
AdlibUnRegister("Drawing")
 
_GDIPlus_PathDispose($hPath)
_GDIPlus_FontFamilyDispose ($hFamily)
_GDIPlus_StringFormatDispose ($hFormat)
_GDIPlus_BrushDispose($hEBrush)
_GDIPlus_BrushDispose($hFBrush)
_GDIPlus_GraphicsDispose($BackBufferGr)
_GDIPlus_BitmapDispose($BackBufferBMP)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
 
Func Drawing()
    _GDIPlus_GraphicsFillRect($BackBufferGr, 0, 0, $iWidth + $iPad * 2, $iHeight + $iPad * 2)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iPad, $iPad, round($iValue * $iStep), $iHeight,$hFBrush)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iValue * $iStep+$iPad, $iPad, round($iWidth - $iValue * $iStep), $iHeight, $hEBrush)
    _GDIPlus_PathReset($hPath)
    _GDIPlus_PathAddString($hPath, $iValue & " %", $tLayout, $hFamily, 3, 16, $hFormat)
    $RectRgn = _WinAPI_CreateRectRgn($iPad, $iPad, $iPad + round($iValue * $iStep), $iPad + $iHeight)
    $GDIRectRgn = _GDIPlus_RegionCreateFromHrgn($RectRgn)
    _GDIPlus_RegionCombinePath($GDIRectRgn, $hPath,1)
    _WinAPI_DeleteObject($RectRgn)
    _GDIPlus_GraphicsFillPath($BackBufferGr, $hPath)
    _GDIPlus_GraphicsFillRegion($BackBufferGr,$GDIRectRgn,$hEBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $BackBufferBMP, 0, 0, $iWidth + $iPad * 2, $iHeight + $iPad * 2)
    _GDIPlus_RegionDispose($GDIRectRgn)
EndFunc   ;==>Drawing

EDIT: It needs GDIP.au3, you can get it from the link in my signature.

Edited by monoscout999

Share this post


Link to post
Share on other sites

Well, i came to late, but anyway i just write this, it is far to be perfect and is just an GDI+ exersice.

Very nice example!

That's exactly what I meant.

It just have got some Round() related flicker bug at right corner area (fill empty rect),

right vertical edge of progressbar (empty area) is moving by 1 or 2 pixels while it changes its value.

Edited by Zedna

Share this post


Link to post
Share on other sites

Thanks for the feedback i fix it and i make it good loooking too :mellow:

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GDIP.au3>

Global $iPad = 2
Global $iWidth = 360
Global $iHeight = 25
Global $iMax = 100
Global $iValue = 50
Global $iStep = $iWidth / $iMax
Global $iLoopStep = 1
Global $iFontSize = Round($iHeight * 0.8)
$hGui = GUICreate("GDI+ ProgressBar by monoscout999")
GUISetBkColor(0X123456)
$iPic = GUICtrlCreatePic("", 20 - $iPad, 100 - $iPad, $iWidth + $iPad * 2, $iHeight + $iPad * 2)

_GDIPlus_Startup()

$hGraphics = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($iPic))

$BackBufferBMP = _GDIPlus_BitmapCreateFromGraphics($iWidth + $iPad * 2, $iHeight + $iPad * 2, $hGraphics)
$BackBufferGr = _GDIPlus_ImageGetGraphicsContext($BackBufferBMP)

_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
_GDIPlus_GraphicsSetSmoothingMode($BackBufferBMP, 2)

$hCBrush = _GDIPlus_LineBrushCreate(0, 0, 0, $iHeight / 2, 0x11FFFFFF, 0xFF000000, 1) ; Contorn Brush
$hFBrush = _GDIPlus_LineBrushCreate(0, 0, 0, $iHeight / 2, 0xFF000055, 0xFF0000FF, 1) ; Fill area
$hEBrush = _GDIPlus_LineBrushCreate(0, 0, 0, $iHeight / 2, 0xFF777777, 0xFFFFFFFF, 1) ; Empty area & Fill text area
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Comic Sans MS")
$tLayout = _GDIPlus_RectFCreate($iWidth / 2 - $iFontSize, $iHeight / 2 - $iFontSize / 1.5) ; Something Like that :S

$hPath = _GDIPLus_pathcreate()

AdlibRegister("Drawing", 50)

GUISetState()

For $i = 0 to $iMax step $iLoopStep
    $iValue = $i
    Sleep(50)
    If $iMax - $i < $iLoopStep then $iValue = $iMax
Next

Do
Until GUIGetMsg() = -3

AdlibUnRegister("Drawing")

_GDIPlus_PathDispose($hPath)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BrushDispose($hEBrush)
_GDIPlus_BrushDispose($hFBrush)
_GDIPlus_BrushDispose($hCBrush)
_GDIPlus_GraphicsDispose($BackBufferGr)
_GDIPlus_BitmapDispose($BackBufferBMP)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

Func Drawing()
    _GDIPlus_GraphicsFillRect($BackBufferGr, 0, 0, $iWidth + $iPad * 2, $iHeight + $iPad * 2,$hCBrush)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iPad, $iPad, Round($iValue * $iStep), $iHeight, $hFBrush)
    _GDIPlus_GraphicsFillRect($BackBufferGr, Round($iValue * $iStep + $iPad), $iPad, Round($iWidth - $iValue * $iStep), $iHeight, $hEBrush)
    _GDIPlus_PathReset($hPath)
    _GDIPlus_PathAddString($hPath, Round($iValue * 100 / $iMax) & " %", $tLayout, $hFamily, 2, $iFontSize, $hFormat)
    $RectRgn = _WinAPI_CreateRectRgn($iPad, $iPad, Round($iValue * $iStep), $iPad + $iHeight)
    $GDIRectRgn = _GDIPlus_RegionCreateFromHrgn($RectRgn)
    _GDIPlus_RegionCombinePath($GDIRectRgn, $hPath, 1)
    _WinAPI_DeleteObject($RectRgn)
    _GDIPlus_GraphicsFillPath($BackBufferGr, $hPath)
    _GDIPlus_GraphicsFillRegion($BackBufferGr, $GDIRectRgn, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $BackBufferBMP, 0, 0, $iWidth + $iPad * 2, $iHeight + $iPad * 2)
    _GDIPlus_RegionDispose($GDIRectRgn)
EndFunc   ;==>Drawing

Share this post


Link to post
Share on other sites

Well, i came to late, but anyway i just write this, it is far to be perfect and is just an GDI+ exersice.

EDIT: It needs GDIP.au3, you can get it from the link in my signature.

Original

Func Drawing()
    _GDIPlus_GraphicsFillRect($BackBufferGr, 0, 0, $iWidth + $iPad * 2, $iHeight + $iPad * 2)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iPad, $iPad, round($iValue * $iStep), $iHeight,$hFBrush)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iValue * $iStep+$iPad, $iPad, round($iWidth - $iValue * $iStep), $iHeight, $hEBrush)
    ...

Fixed bad repainting of right edge:

Func Drawing()
    _GDIPlus_GraphicsFillRect($BackBufferGr, 0, 0, $iWidth + $iPad * 2, $iHeight + $iPad * 2)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iPad, $iPad, $iWidth, $iHeight, $hEBrush)
    _GDIPlus_GraphicsFillRect($BackBufferGr, $iPad, $iPad, round($iValue * $iStep), $iHeight,$hFBrush)
    ...
Edited by Zedna

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...