Jump to content

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


TehWhale
 Share

Recommended Posts

Sweet, Will take a look at those :P So, why can't I make the iPod red+black? I tried changing the variables at the beggining of the script but it stayed exactly the same. And, do you have any iPod png's or whatever heh. I can't find any, google failed me.

I had some errors, please re-download the attachment.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The layout is AARRGGBB where AA means alpha channel (aka transparency).

Sweet, so I still don't think I'm getting how to check if the "buttons" are clicked. I need to use the location of the GUI so you can change the GUI size, so I'm tring to use the variables that created it, but it's not working for me.

So I'm using this, just more of it.

If WinActive($hwnd) And _IsPressed("01",$user32) Then
        $pos=MouseGetPos()
        If $pos[0]>=$width / 2 - $wheelouterr / 2 And $pos[0]<=$height - $wheelouterr - 50 + 15) And $pos[1]>=10 And $pos[1]<=(10+30) Then PlayFunc()
        If $pos[0]>=10 And $pos[0]<=(10+50) And $pos[1]>=10 And $pos[1]<=(10+30) Then BackFunc()
        If $pos[0]>=10 And $pos[0]<=(10+50) And $pos[1]>=10 And $pos[1]<=(10+30) Then NextFunc()
        If $pos[0]>=10 And $pos[0]<=(10+50) And $pos[1]>=10 And $pos[1]<=(10+30) Then MenuFunc()
    EndIf
Link to comment
Share on other sites

Sweet, so I still don't think I'm getting how to check if the "buttons" are clicked. I need to use the location of the GUI so you can change the GUI size, so I'm tring to use the variables that created it, but it's not working for me.

So I'm using this, just more of it.

If WinActive($hwnd) And _IsPressed("01",$user32) Then
         $pos=MouseGetPos()
         If $pos[0]>=$width / 2 - $wheelouterr / 2 And $pos[0]<=$height - $wheelouterr - 50 + 15) And $pos[1]>=10 And $pos[1]<=(10+30) Then PlayFunc()
         If $pos[0]>=10 And $pos[0]<=(10+50) And $pos[1]>=10 And $pos[1]<=(10+30) Then BackFunc()
         If $pos[0]>=10 And $pos[0]<=(10+50) And $pos[1]>=10 And $pos[1]<=(10+30) Then NextFunc()
         If $pos[0]>=10 And $pos[0]<=(10+50) And $pos[1]>=10 And $pos[1]<=(10+30) Then MenuFunc()
     EndIf
A good way to debug this kind of things is to draw a rectangle where you are checking.

So:

1) Create a red pen

2) Use _GDIPlus_DrawRectangle() with the values you use in those if's

3) Make sure this is called in the redraw func.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

A good way to debug this kind of things is to draw a rectangle where you are checking.

So:

1) Create a red pen

2) Use _GDIPlus_DrawRectangle() with the values you use in those if's

3) Make sure this is called in the redraw func.

Alright, so create a red pen, like how the black and white are created, and then just draw it? Alright, I'll work on that, I think I have one last question, how can I change the value of some of the text, like the artist/album and stuff need to be changed, how can I do this with GDI+ or will I have to delete it, and recreate it over and over?

Thanks so much for your help monoceres, your a big help on GDI+ :P

Link to comment
Share on other sites

Alright, so create a red pen, like how the black and white are created, and then just draw it? Alright, I'll work on that, I think I have one last question, how can I change the value of some of the text, like the artist/album and stuff need to be changed, how can I do this with GDI+ or will I have to delete it, and recreate it over and over?

Thanks so much for your help monoceres, your a big help on GDI+ :P

The entire GUI is completely cleared ~30 times each second (this is why ordinary controls doesn't work), so you only need to have a call to _GDIPlus_GraphicsDrawStringEx() with a global variable that you change anytime you want something else to display (like the $artist variable changing).

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

A good way to debug this kind of things is to draw a rectangle where you are checking.

So:

1) Create a red pen

2) Use _GDIPlus_DrawRectangle() with the values you use in those if's

3) Make sure this is called in the redraw func.

I don't see this function, but I do see: _GDIPlus_GraphicsDrawRect()?
Link to comment
Share on other sites

What's wrong with this!?

_GDIPlus_GraphicsDrawRect($Graphics, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $BatteryColor)

EDIT: Haha Im smarticle :P I fixed it. I created my own green pen and used $GreenPen :(

EDIT: I still can't find out how to do this so that you can change the size and it'll stay the same, like you did with your labels....Grr

Edited by TehWhale
Link to comment
Share on other sites

What's wrong with this!?

_GDIPlus_GraphicsDrawRect($Graphics, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $BatteryColor)
Didn't I tell you to draw to $backbuffer?

You should also call _ResetClip() before drawing your rect.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Didn't I tell you to draw to $backbuffer?

You should also call _ResetClip() before drawing your rect.

If I use this...

_ResetClip($BackBuffer)
_GDIPlus_GraphicsDrawRect($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $GreenPen)

Nothing shows up at all...

Sorry I'm a noob at GDI+

Edited by TehWhale
Link to comment
Share on other sites

If I use this...

_ResetClip($BackBuffer)
 _GDIPlus_GraphicsDrawRect($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $GreenPen)

Nothing shows up at all...

Sorry I'm a noob at GDI+

Make sure you put it right before this line in _Redraw()

_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)

Edit: It's a pen you're using, right? Not a brush.

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Make sure you put it right before this line in _Redraw()

_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)

Edit: It's a pen you're using, right? Not a brush.

Yeah it's a pen, I made it using _GDIPlus_CreatePen or whatever, with the battery color to stand out. Heres my code if you wanted to look at it to see whats wrong...

#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

#NoTrayIcon
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)

Global Const $Width = 250
Global Const $Height = 500
Global Const $WheelOuter = 200
Global Const $WheelInner = 75
Global $BGColor = "0xFF050505" ;Black
Global $FGColor = "0xFFFF0000" ;Red
Global $WheelColor = "0xFFFF0000" ;Red
Global $User32 = DllOpen("User32.dll")
Global $Battery_Percent = 100


$Hwnd = GUICreate("iPod", $Width, $Height, -1, -1, $WS_POPUP)
GUISetOnEvent(-3, "Close")
_GuiRoundCorners($Hwnd, 0, 0, 20, 20)
GUISetState()

_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)
$GreenPen = _GDIPlus_PenCreate("0xFF00EF00", 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)


_ReDraw() ;Load GUI


GUIRegisterMsg($WM_PAINT, "_ReDraw") ;Redraw Msg
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") ;Move msg


While 1
    _ReDraw()
    Sleep(50)
WEnd

Func Close()
    _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_PenDispose($GreenPen)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>Close

Func _ReDraw()
    _GDIPlus_GraphicsClear($BackBuffer, $BGColor)
    _GDIPlus_GraphicsDrawImageRect($BackBuffer, $Overlay, 0, 0, $Width, $Height)
    _SetClipCircle($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50, $WheelOuter, $WheelOuter)
    _GDIPlus_GraphicsFillEllipse($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50, $WheelOuter, $WheelOuter, $WheelBrush)
    
    #Region Menu text
    DllStructSetData($Rect, 1, $Width / 2 - $WheelOuter / 2)
    DllStructSetData($Rect, 2, $Height - $WheelOuter - 50 + 15) ; Y offset
    DllStructSetData($Rect, 3, $WheelOuter)
    _GDIPlus_GraphicsDrawStringEx($BackBuffer, "Menu", $ArialSmall, $Rect, $Format, $BlackBrush)
    
    DllStructSetData($Rect, 1, $Width / 2 - $WheelOuter / 2 + 50 + 25)
    DllStructSetData($Rect, 2, $Height - $WheelOuter - 50 + 15 + 50 + 22) ; Y offset
    DllStructSetData($Rect, 3, $WheelOuter)
    _GDIPlus_GraphicsDrawStringEx($BackBuffer, ">>I", $ArialMedium, $Rect, $Format, $BlackBrush)
    
    DllStructSetData($Rect, 1, $Width / 2 - $WheelOuter / 2 - 50 - 25)
    DllStructSetData($Rect, 2, $Height - $WheelOuter - 50 + 15 + 50 + 22) ; Y offset
    DllStructSetData($Rect, 3, $WheelOuter)
    _GDIPlus_GraphicsDrawStringEx($BackBuffer, "I<<", $ArialMedium, $Rect, $Format, $BlackBrush)
    
    DllStructSetData($Rect, 1, $Width / 2 - $WheelOuter / 2)
    DllStructSetData($Rect, 2, $Height - $WheelOuter + 110) ; Y offset
    DllStructSetData($Rect, 3, $WheelOuter)
    _GDIPlus_GraphicsDrawStringEx($BackBuffer, "I>II", $ArialMedium, $Rect, $Format, $BlackBrush)
    #EndRegion Menu text

    ; Draws the background into the inner circle
    _SetClipCircle($BackBuffer, $Width / 2 - $WheelInner / 2, ($Height - $WheelOuter - 50) + $WheelOuter / 2 - $WheelInner / 2, $WheelInner, $WheelInner)
    _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, 150, 10) ;Display
    _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)

    _GDIPlus_GraphicsDrawRect($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $GreenPen)
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_ReDraw

;INTERNAL FUNCTIONS
Func _AntiAlias($hGraphics, $iMode)
    Local $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 _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 DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
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   ;==>_ResetClip
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)
    Local $Path = DllStructCreate("dword")
    DllCall($ghGDIPDll, "none", "GdipCreatePath", "int", 0, "int", DllStructGetPtr($Path))
    Local $pointer = DllStructGetData($Path, 1)
    DllCall($ghGDIPDll, "none", "GdipAddPathEllipseI", "int", $pointer, "int", $x, "int", $y, "int", $Width, "int", $Height)
    Local $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   ;==>_SetClipCircle
Func WM_NCHITTEST($Hwnd, $Msg, $wParam, $lParam)
    Local $iProc = DllCall("user32.dll", "int", "DefWindowProc", "hwnd", $Hwnd, "int", $Msg, "wparam", $wParam, "lparam", $lParam)
    $iProc = $iProc[0]
    If $iProc = $HTCLIENT Then Return $HTCAPTION
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

Just throw it in the folder that has the 2 images.

Link to comment
Share on other sites

Put this:

_GDIPlus_GraphicsDrawRect($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $GreenPen)

Before

_GDIPlus_GraphicsDrawImageRect($Graphics, $Bitmap, 0, 0, $Width, $Height)

Everyting must be done when calling this function _GDIPlus_GraphicsDrawImageRect($Graphics, $Bitmap, 0, 0, $Width, $Height)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Put this:

_GDIPlus_GraphicsDrawRect($BackBuffer, $Width / 2 - $WheelOuter / 2, $Height - $WheelOuter - 50 + 15, 15, 20, $GreenPen)

Before

_GDIPlus_GraphicsDrawImageRect($Graphics, $Bitmap, 0, 0, $Width, $Height)

Everyting must be done when calling this function _GDIPlus_GraphicsDrawImageRect($Graphics, $Bitmap, 0, 0, $Width, $Height)

Sweet! Ok now, When using the variables for the MENU button, I used it in the rectangle and they go way off? I'm using the same ones, shouldn't the green box be around the menu? I'm getting really confused with this GDI+ stuff. But it's also a very good learning experience.
Link to comment
Share on other sites

Sweet! Ok now, When using the variables for the MENU button, I used it in the rectangle and they go way off? I'm using the same ones, shouldn't the green box be around the menu? I'm getting really confused with this GDI+ stuff. But it's also a very good learning experience.

The text is centered by the GDI+ functions internally so you don't know where the text is. What you have to do is try different values until you think you get a good clicking area.

Broken link? PM me and I'll send you the file!

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...