Sign in to follow this  
Followers 0
cppman

Moving Controls

1 post in this topic

#1 ·  Posted (edited)

note: I'am aware of GUICtrlSetPos() and that works perfectly fine. Except it creates alot of flicker around the drawing. Im trying to stick with ControlMove.

Okay, i have a "Graphic" control that I am trying to move, although whenever I move it, it takes about a quarter of the image that is drawn int eh graphics control, and only moves that, why the other ENTIRE drawing is still in the same spot. Maybe its bug?

anyways here is my code: i put a ;--------- comment surrounding where my problem is: its from line 117 to 142.

;PixelSoft Game Engine (Create Games Quickly and Easily)
#include <guiconstants.au3>
#include <misc.au3>
;===============================================================================
;
; Description:      Converts 3 color values(red, green, blue) into a hex value.
; Syntax:           _RGBToHex($red_value, $green_value, $blue_value)
; Parameter(s):     $red_value - 0 - 255 RED.
;                   $green_value - 0 - 255 GREEN.
;                   $blue_value - 0 - 255 BLUE.
; Requirement(s):   None
; Return Value(s):  On Success - Returns the Hexadecimal value for the RGB color.
; Author(s):        Chris95219 <chris95219@gmail.com>
; Note(s):          None.
;
;===============================================================================
Func _RGBToHex($red_add, $green_add, $blue_add)
    $NEW =   Hex( $red_add ) & Hex( $green_add ) & Hex( $blue_add )
    $RED = StringTrimRight(StringTrimLeft($new, 6), 16)
    $GREEN = StringTrimRight(StringTrimLeft($new, 14), 8)
    $BLUE = StringTrimLeft($NEW, StringLen($NEW)-2)
    Return '0x' & $RED & $GREEN & $BLUE
EndFunc

;===============================================================================
;
; Description:      Converts a hexadecimal into its corresponding RGB values.
; Syntax:           _HexToRGB($color)
; Parameter(s):     $color - Hex value.
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array of 3 rgb values. [0] = red, [1] = green, [2] = blue.
; Author(s):        Chris95219 <chris95219@gmail.com>
; Note(s):          None.
;
;===============================================================================
Func _HexToRGB($color)
    $base           = StringSplit(Hex($color, 6), "")
            $RED    = Dec( $base[1]&$base[2] )
            $GREEN  = Dec( $base[3]&$base[4] )
            $BLUE   = Dec( $base[5]&$base[6] )
            
    Local   $avColors[3]
            $avColors[0] = $RED
            $avColors[1] = $GREEN
            $avColors[2] = $BLUE
    Return  $avColors
EndFunc


Func _CreateColor($rr, $gg, $bb)
    local $avcolor[3] = [$rr, $gg, $bb]
    Return $avcolor
EndFunc

Func _CreateAlpha($color1, $color2, $alpha)
    ;$value = Hex( dec($color1)*(1.0-$alpha) + dec($color2)*($alpha), 6)
    $nRed = $color1[0] * $alpha + $color2[0] * (1.0 - $alpha)
    $nGreen = $color1[1] * $alpha + $color2[1] * (1.0 - $alpha)
    $nBlue = $color1[2] * $alpha + $color2[2] * (1.0 - $alpha)
    return (_RGBToHex($nRed, $nGreen, $nBlue))
EndFunc

Global Enum $psWindow_FullScreen = 0, $psWindow_Windowed
Global $psWindow_ExitCode   = -3
Global $psSystemSpecs[2]
Global $psLogFile
Global $psLogFileName
Global $psPenSize = 1
Global $psWindowCurBkColor = 0x000000
Func _psCreate() ;_psRelease()
    $psSystemSpecs[0] = @DesktopWidth
    $psSystemSpecs[1] = @DesktopHeight
    Do
        $RandomName = Random(0, 29999, 1)
    Until Not FileExists(@TempDir & "\psSystemLog"&$RandomName&".log")
    $psLogFileName = $RandomName
    $psLogFile = FileOpen(@TempDir & "\psSystemLog"&$RandomName&".log", 1)
    if ($psLogFile <> -1) Then
        Return $psLogFile
    Else
    EndIf
        Return False
EndFunc

Func _psRelease()
    $psSystemSpecs[0] = ""
    $psSystemSpecs[1] = ""
    FileClose($psLogFile)
    FileDelete(@TempDir & "\psSystemLog"&$psLogFileName&".log")
EndFunc

Func _psSystemSetState($psHandle, $psWindowTitle, $psWindowStyle = 0x00000080, $psWindowState = 0, $psWindowWidth = @DesktopWidth, $psWindowHeight = @DesktopHeight, $psWindowBkColor = 0x000000)
    if ($psWindowState == $psWindow_FullScreen) Then
        $window_width = @DesktopWidth
        $window_height = @DesktopHeight
        $x = 0
        $y = 0
    Else
        $window_width = $psWindowWidth
        $window_height = $psWindowHeight
        $x = (@DesktopWidth/2)
        $y = (@DesktopHeight/2)
    EndIf
    $psWindowCurBkColor = $psWindowBkColor
    FileWriteLine($psHandle, @Hour & ":" & @Min & ":" & @Sec & ">>> Setting system state to " & $psWindowTitle & "|" & $psWindowStyle & "|" & $psWindowState & "|" & $psWindowWidth & "|" & $psWindowHeight & "|" & $psWindowBkColor)
    $hWnd = GUICreate($psWindowTitle, $window_width, $window_height, $x, $y, $psWindowStyle)
    GUISetBkColor($psWindowBkColor)
    GUISetState()
    Return $hWnd
EndFunc

Func _psDrawSetPenSize($psHandle, $psPenSize)
    $psPenSize = $size
    return $psPenSize
EndFunc

;-------------------------------------------------------------
Func _psDrawRectangle($psHandle, $x, $y, $width, $height, $color = 0xFFFFFF, $opacity = 0)
    $rectangle = GUICtrlCreateGraphic($x, $y, $width, $height)
                 GUICtrlSetBkColor(-1, $psWindowCurBkColor)
    $bgcolor = _HexToRGB($psWindowCurBkColor)
    $drawcolor = _HexToRGB($color)
    $alpha = _CreateAlpha($bgcolor, $drawcolor, $opacity)
    GUICtrlSetGraphic($rectangle, $GUI_GR_COLOR, 0xFFFFFF, $alpha)
    GUICtrlSetGraphic($rectangle, $GUI_GR_PENSIZE, $psPenSize)
    GUICtrlSetGraphic($rectangle, $GUI_GR_RECT, $x, $y, $width, $height)
    GUICtrlSetGraphic($rectangle, $GUI_GR_REFRESH)
    return $rectangle
EndFunc
;--------------------------------------------------------------

;test
Local $x_object = 10
$main = _psCreate()
_psSystemSetState($main, "My Title", "OnClose")
$rect = _psDrawRectangle($main, $x_object, 10, 50, 50, 0xFFFFFF, .9)
While GUIGetMsg() <> -3
    if (_IsPressed("01")) Then 
        $x_object += 4
        ControlMove("My Title", "", $rect, $x_object, 10, 50, 50)
    EndIf
WEnd

TIA :)

Edited by CHRIS95219

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  
Followers 0