Jump to content

Gui & GDI+ resizing issue


Recommended Posts

Been wracking my head trying to figure out why when I resize the gui, GDI+ remaking the controls start getting wrong dimensions and go beyond the window,
Can anyone lend me a second set of eyes and point out what I screwed up if anything?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Array.au3>
#include <WindowsConstants.au3>


Global $iWidth, $iHeight, $iBgColor, $iCurrentObj
Global $hD32, $hGraphics, $hGUI, $hPen, $hBitmap, $hBackbuffer
;$Object[xPos, yPos, oWidth, oHeight, oColor, oName]
Global $ObjectList[1][6]

$hD32 = DllOpen("user32.dll")
$iWidth = 600
$iHeight = 800
$iBgColor = 0x202020
$iCurrentObj = 0

_GDIPlus_Startup() ;initialize GDI+


$hGUI = GUICreate("Example", $iWidth, $iHeight, -1, -1, $WS_SIZEBOX) ;create a test GUI
GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
GUISetState(@SW_SHOW)

Graphics()



;;;$Object[xPos, yPos, oWidth, oHeight, oColor, oName]
;Global $xPos, $yPos, $oWidth, $oHeight
;$xPos = 0
;$yPos = 0
;$oWidth = 100
;$oHeight = 50

$ObjectList[0][0] = 0 ; xpos
$ObjectList[0][1] = 0 ; ypos
$ObjectList[0][2] = 120 ; width
$ObjectList[0][3] = 150 ;height
$ObjectList[0][4] = 0xFFFFFFFF ; color with alpha
$ObjectList[0][5] = "test" ; name

Local $gMsg
Do
   $gMsg = GUIGetMsg()
   Move()
   Update()
   If $gMsg = $gui_event_resized Then
      Graphics()
   EndIf
Until $gMsg = $GUI_EVENT_CLOSE

;cleanup GDI+ resources
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
DllClose($hD32)
Exit(0)

Func Graphics()
   Local $aWindow = WinGetPos($hGui)
   $iWidth = $aWindow[2]
   $iHeight = $aWindow[3]
   _GDIPlus_GraphicsDispose($hGraphics)
   _GDIPlus_GraphicsDispose($hBitmap)
   _GDIPlus_GraphicsDispose($hBackbuffer)
   $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
   _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
   $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
   $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
EndFunc

Func Check()
   ;xpos+ check
   If ($ObjectList[$iCurrentObj][0] + $ObjectList[$iCurrentObj][2] > $iWidth) Then
      $ObjectList[$iCurrentObj][0] = $iWidth - $ObjectList[$iCurrentObj][2]
   EndIf
   ;xpos- check
   If ($ObjectList[$iCurrentObj][0] < 0) Then
      $ObjectList[$iCurrentObj][0] = 0
   EndIf
   ;ypos+ check
   If ($ObjectList[$iCurrentObj][1] + $ObjectList[$iCurrentObj][3] > $iHeight) Then
      $ObjectList[$iCurrentObj][1] = $iHeight - $ObjectList[$iCurrentObj][3]
   EndIf
   ;ypos- check
   If ($ObjectList[$iCurrentObj][1] < 0) Then
      $ObjectList[$iCurrentObj][1] = 0
   EndIf

EndFunc

Func Move()
   If Not WinActive($hGUI) Then Return

   Local $Rate = 1

   ;shift faster!
   If _IsPressed("10", $hD32) Then
      $Rate *= 10
   EndIf

   ;left
   If _IsPressed("25", $hD32) Then
      $ObjectList[$iCurrentObj][0] -= $Rate
   EndIf

   ;Up
   If _IsPressed("26", $hD32) Then
      $ObjectList[$iCurrentObj][1] -= $Rate
   EndIf

   ;Right
   If _IsPressed("27", $hD32) Then
      $ObjectList[$iCurrentObj][0] += $Rate
   EndIf

   ;Down
   If _IsPressed("28", $hD32) Then
      $ObjectList[$iCurrentObj][1] += $Rate
   EndIf

   Check()
EndFunc

Func Update()
   _GDIPlus_GraphicsClear($hBackbuffer)
   For $I = 0 To UBound($ObjectList) - 1
      _GDIPlus_PenDispose($hPen)
      $hPen = _GDIPlus_PenCreate($ObjectList[$I][4], 4)
      _GDIPlus_GraphicsDrawRect($hBackbuffer, $ObjectList[$I][0], $ObjectList[$I][1], $ObjectList[$I][2], $ObjectList[$I][3], $hPen)
      _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iWidth)
   Next
EndFunc

 

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