Jump to content

iPod Media Player BETA 2 New user Interface with GDI+ [Updated 10-23]


TehWhale
 Share

Recommended Posts

Grr, heh, well I've got the perfect rectangle around the menu button, but now to incorporate it.

_GDIPlus_GraphicsDrawRect($BackBuffer, 100, 266, 50, 20, $GreenPen)

But, This is making me mad..

If $pos[0]>=100 And $pos[0]<=266 And $pos[1]>=150 And $pos[1]<=286 Then MsgBox(0, "", "menu")

EDIT: Well, I fixed it somewhat, but it's VERY unreliable.

Func _IsClickedInRect($Hwnd, $Left, $Top, $Width, $Height)
    If WinActive($hwnd) And _IsPressed(01, $User32) Then
        $pos=MouseGetPos()
        If $pos[0]>=$Left And $pos[0]<=($Left+$Width) And $pos[1]>=$Top And $pos[1]<=($Top+$Height) Then Return 1
    EndIf
EndFunc

You have to double click very fast to get the msgbox to pop up, and it just is unreliable. Why?

Heres my check in my main loop

If _IsClickedInRect($Hwnd, 100, 266, 50, 20) Then MsgBox(0, "", "menu")

EDIT: It's because of the WM_MOVE message I have, that will move the window, ehh, I'll have to use the old code :(

EDIT: Fixed all :P

Edited by TehWhale
Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create a rectangle as the outline, and fill it according to the percentage.... :P

Take a closer look inside the GDI+ Progressbar code. Answer will be further in there... :(

Link to comment
Share on other sites

I like it.

For me, seekbar, volume and playlist view are missing, but it's a good work :(

But, This is making me mad..

If $pos[0]>=100 And $pos[0]<=266 And $pos[1]>=150 And $pos[1]<=286 Then MsgBox(0, "", "menu")
Maybe something like this ....

Added registered message:

- WM_DRAWITEM with ownerdrawn style on ctrl buttons to avoid painting controls

- WM_NCHITTEST to move gui

ControlEvents can be polled as usualy with a GUIGetMessage()

Hope it could help :P

#cs
    Copyright information
    You are free to use this source in your project under the condition
    
    1) You credit me (monoceres) inside your application
    2) You keep this copyright notice inside your source
    3) You do not use this in any illegal way
    
    Otherwise you are free to code as you will, good luck :)
    // Andreas Karlsson (monoceres @ AutoIt forums)

#ce



#cs read me
    Do not create regular controls, the redraw function WILL overdraw them
    All GDI+ resources are loaded at once in the GDI+ startup sequence
    
    To do custom drawings (like adding stuff to the display) draw your things into the $backbuffer graphics object inside the redraw function
    All your drawings must be done before the _GDIplus_GraphicsImageDrawRect($graphics... call
    
    ; The main loop should only be used for input and status updating
    
    ; If you add GDI+ resources be sure to release them in the close() function
    

#ce



#include <GDIPlus.au3>
#include <windowsconstants.au3>
#include <winapi.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>
#include <ButtonConstants.au3>

Global Const $width = 300
Global Const $height = 500
Global Const $wheelouterr = 200
Global Const $wheelinnerr = 100
Global $bgcolor = "0xFF050505"
Global $fgcolor = "0xFFFFA0A0"
Global $wheelcolor="0xFFFF5555"
Global $user32 = DllOpen("user32.dll")
Global $battery_percent = 100

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ; Register before GUISetState()
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") ; Window moving

#Region GUI creation
;~ Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode",2)
$hwnd = GUICreate("iPod", $width, $height, -1, -1, $WS_POPUP)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
_GuiRoundCorners($hwnd, 0, 0, 20, 20)
GUICtrlCreateLabel("test", $width / 2, $height - $wheelouterr - 50)
$nMenu = GUICtrlCreateButton("", 125,265,50,20)
GUICtrlSetStyle($nMenu, $BS_OWNERDRAW) ; Make button ownerdrawn to get WM_DRAWITEM message before painting controls
$nPrevious = GUICtrlCreateButton("", 60,340,30,20)
GUICtrlSetStyle($nPrevious, $BS_OWNERDRAW) 
$nNext = GUICtrlCreateButton("", 208,340,30,20)
GUICtrlSetStyle($nNext, $BS_OWNERDRAW)
$nPlay = GUICtrlCreateButton("", 135,410,30,20)
GUICtrlSetStyle($nPlay, $BS_OWNERDRAW)


GUISetState()
#EndRegion

#Region GDI+ startup
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$backgroundbrush=_GDIPlus_BrushCreateSolid($bgcolor)
$brush = _GDIPlus_BrushCreateSolid($fgcolor)
$wheelbrush=_GDIPlus_BrushCreateSolid($wheelcolor)
$image=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\glass.png")
$overlay=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\over.png")
$white=_GDIPlus_BrushCreateSolid(0x99F0F0F0)
$blackpen=_GDIPlus_PenCreate("0xFF000000",1)
$batterycolor=_GDIPlus_BrushCreateSolid(0xFF00EF00)
$rect=_GDIPlus_RectFCreate(0,0,$width,$height) ; Elements x,y,width,height
$arial=_GDIPlus_FontFamilyCreate("Arial")
$arialmedium=_GDIPlus_FontCreate($arial,16)
$arialsmall=_GDIPlus_FontCreate($arial,14)
$format=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format,1)
$blackbrush = _GDIPlus_BrushCreateSolid("0xFF222222")
_AntiAlias($backbuffer, 4)
#EndRegion

; All the resources are loaded, we can finally draw the iPod for the first time
_ReDraw()

; Calls the function when redrawing is needed
GUIRegisterMsg($WM_PAINT, "_ReDraw")

Do
    Sleep(25)
    $Msg=GUIGetMsg()
    switch $Msg
        Case $nPrevious
            MsgBox(0, "Info", "Previous Button pressed")
        Case $nMenu
            MsgBox(0, "Info", "Menu Button pressed")
        Case $nNext
            MsgBox(0, "Info", "Next Button pressed")
        Case $nPlay
            MsgBox(0, "Info", "Play Button pressed")
        Case $GUI_EVENT_CLOSE
            close()
    EndSwitch
    
    
    #Region Battery usage
    $battery_percent-=0.02
    If $battery_percent<0 Then
        $battery_percent=100
    EndIf
    #EndRegion
    
    ; Draw the updated scene
    _ReDraw()
Until False



Func close()
    #Region Clean up
    _GDIPlus_BrushDispose($blackbrush)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_ImageDispose($image)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_ImageDispose($overlay)
    _GDIPlus_BrushDispose($backgroundbrush)
    _GDIPlus_BrushDispose($white)
    _GDIPlus_BrushDispose($wheelbrush)
    _GDIPlus_StringFormatDispose($format)
    _GDIPlus_FontDispose($arialmedium)
    _GDIPlus_FontDispose($arialsmall)
    _GDIPlus_FontFamilyDispose($arial)
    _GDIPlus_PenDispose($blackpen)
    _GDIPlus_BrushDispose($batterycolor)
    _GDIplus_Shutdown()
    #EndRegion
    
    Exit
EndFunc   ;==>close


Func _AntiAlias($hGraphics, $iMode)
    Local $aResult

    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $iMode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_AntiAlias

Func _ReDraw()

    _GDIPlus_GraphicsClear($backbuffer, $bgcolor)
    _GDIPlus_GraphicsDrawImageRect($backbuffer,$overlay,0,0,$width,$height)
    _SetClipCircle($backbuffer, $width / 2 - $wheelouterr / 2, $height - $wheelouterr - 50, $wheelouterr, $wheelouterr)
    _GDIPlus_GraphicsFillEllipse($backbuffer, $width / 2 - $wheelouterr / 2, $height - $wheelouterr - 50, $wheelouterr, $wheelouterr, $wheelbrush)
    
    
    #Region Menu text
    DllStructSetData($rect,1,$width / 2 - $wheelouterr / 2)
    DllStructSetData($rect,2,$height - $wheelouterr - 50+15) ; Y offset
    DllStructSetData($rect,3,$wheelouterr)  
    _GDIPlus_GraphicsDrawStringEx($backbuffer,"Menu",$arialsmall,$rect,$format,$white)
    
    DllStructSetData($rect,1,$width / 2 - $wheelouterr / 2+50+25)
    DllStructSetData($rect,2,$height - $wheelouterr - 50+15+50+22) ; Y offset
    DllStructSetData($rect,3,$wheelouterr)  
    _GDIPlus_GraphicsDrawStringEx($backbuffer,">>I",$arialmedium,$rect,$format,$white)
    
    DllStructSetData($rect,1,$width / 2 - $wheelouterr / 2-50-25)
    DllStructSetData($rect,2,$height - $wheelouterr - 50+15+50+22) ; Y offset
    DllStructSetData($rect,3,$wheelouterr)  
    _GDIPlus_GraphicsDrawStringEx($backbuffer,"I<<",$arialmedium,$rect,$format,$white)
    
    DllStructSetData($rect,1,$width / 2 - $wheelouterr / 2)
    DllStructSetData($rect,2,$height - $wheelouterr +110) ; Y offset
    DllStructSetData($rect,3,$wheelouterr)  
    _GDIPlus_GraphicsDrawStringEx($backbuffer,"I>II",$arialmedium,$rect,$format,$white)
    #EndRegion

    ; Draws the background into the inner circle
    _SetClipCircle($backbuffer, $width / 2 - $wheelinnerr / 2, ($height - $wheelouterr - 50) + $wheelouterr / 2 - $wheelinnerr / 2, $wheelinnerr, $wheelinnerr)
    _GDIPlus_GraphicsFillRect($backbuffer,0,0,$width,$height,$backgroundbrush)
    _GDIPlus_GraphicsDrawImageRect($backbuffer,$overlay,0,0,$width,$height)

    
    ; Make sure we doesn't draw outside the display area
    _SetRoundedRectClip($backbuffer, 25, 25, $width-25*2, 175, 10)
    _GDIplus_GraphicsFillRect($backbuffer,0,0,$width,$height,$brush)
    
    ; Display text goes here
    DllStructSetData($rect,1,25)
    DllStructSetData($rect,2,25+10) ; Y offset
    DllStructSetData($rect,3,$width-25*2)
    _GDIPlus_GraphicsDrawStringEx($backbuffer,"iPod"&@CRLF&"AutoIt version",$arialmedium,$rect,$format,$blackbrush)

    
    
    ; Battery drawing
    _GDIPlus_GraphicsFillRect($backbuffer,(($width-25*2)+25)-30,25+5,20*($battery_percent/100),10,$batterycolor)
    _GDIPlus_GraphicsDrawRect($backbuffer,(($width-25*2)+25)-30,25+5,20,10,$blackpen)
    _GDIPlus_GraphicsFillRect($backbuffer,(($width-25*2)+25)-30+20,30+3,2,5,$blackbrush)
    
    
    
    
    _GDIPlus_GraphicsDrawImageRect($backbuffer,$image,25,25,$width-25*2,175)
    _ResetClip($backbuffer)
    
    
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    Return $GUI_RUNDEFMSG
    
EndFunc   ;==>_ReDraw

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
    Local $XS_pos, $XS_ret, $XS_ret2
    $XS_pos = WinGetPos($h_win)
    $XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
    If $XS_ret[0] Then
        $XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
    EndIf
EndFunc   ;==>_GuiRoundCorners

Func _SetRoundedRectClip($g, $x, $y, $w, $h, $r)
    $Path = DllStructCreate("dword")
    DllCall($ghGDIPDll, "none", "GdipCreatePath", "int", 0, "int", DllStructGetPtr($Path))
    $pointer = DllStructGetData($Path, 1)
    DllCall($ghGDIPDll, "none", "GdipAddPathArc", "int", $pointer, "float", $x, "float", $y, "float", $r, "float", $r, "float", 180, "float", 90)
    DllCall($ghGDIPDll, "none", "GdipAddPathArc", "int", $pointer, "float", $x + ($w - $r - 1), "float", $y, "float", $r, "float", $r, "float", 270, "float", 90)
    DllCall($ghGDIPDll, "none", "GdipAddPathArc", "int", $pointer, "float", $x + ($w - $r - 1), "float", $y + ($h - $r - 1), "float", $r, "float", $r, "float", 0, "float", 90)
    DllCall($ghGDIPDll, "none", "GdipAddPathArc", "int", $pointer, "float", $x, "float", $y + ($h - $r - 1), "float", $r, "float", $r, "float", 90, "float", 90)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetClipPath", "hwnd", $g, "ptr", $pointer, "int", 0)
EndFunc   ;==>_SetRoundedRectClip

Func _ResetClip($g)

    DllCall($ghGDIPDll, "none", "GdipResetClip","hwnd",$g)

EndFunc

Func _GDIPlus_StringFormatSetAlign($hStringFormat, $iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat, "short", $iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 0 Then Return SetError(0, 0, 1)
    Return SetError(1, 0, 0)
EndFunc   ;==>_GDIPlus_StringFormatSetAlign

Func _SetClipCircle($hGraphics, $x, $y, $width, $height)
   
    ;Create struct to hold pointer to Path object
    $Path = DllStructCreate("dword")
   
    ;Create Path object, store pointer to it
    DllCall($ghGDIPDll, "none", "GdipCreatePath", "int", 0, "int", DllStructGetPtr($Path))
   
    ;Retrieve pointer from struct
    $pointer = DllStructGetData($Path,1)
   
    DllCall($ghGDIPDll, "none", "GdipAddPathEllipseI","int", $pointer,"int",$x,"int",$y,"int",$width,"int",$height)
   
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetClipPath", "hwnd", $hGraphics, "ptr", $pointer,"int",0)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) ; Intercept message and abort redraw of controls
    return 1
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    if ($hWnd = $hwnd) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc
Edited by homy
Link to comment
Share on other sites

I like it.

For me, seekbar, volume and playlist view are missing, but it's a good work :P

Thanks for the help but it was already fixed! I edited my post saying: "EDITED: All fixed :("

Thanks for your comment though, I can add a seekbar and volume and possible a playlist view. :idea:

Link to comment
Share on other sites

Nice idea!

But the memory and CPU usage?!! :idea:

The player looks nice :P

Was thinking about it myself some time ago :)

Heh, didn't even check it's CPU usage, what percent does it use for you? Only 2% for me.

good job, and the GDI+ makes it really good :P

Thanks :( Edited by TehWhale
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...