Jump to content

moving around a image in a GUI


Tomb
 Share

Recommended Posts

i am trying to make a basic gui that creates a picture and can move it around the gui freely with just up down left and right hotkeys. i so far har have this. I can move the image somewhat, the only problem is that i can only seem to move it to 4 different places.

#include <GUIConstants.au3>

$x = 200
$y = 100

GUICreate("GUI", 600, 600, -1, -1)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)

HotKeySet("{up}", "_UpArrow")
HotKeySet("{down}", "_DownArrow")
HotKeySet("{left}", "_LeftArrow")
HotKeySet("{right}", "_RightArrow")
HotKeySet("{ESC}", "_zExitScript")

Func _UpArrow()
HotKeySet ("{up}")
$u = ($x + 0)
$ub = ($y - 100)
GUICtrlSetPos("3", $u, $ub )
HotKeySet ( "{up}" , "_UpArrow" )
EndFunc

Func _DownArrow()
HotKeySet ("{down}")
$d = ($x + 0)
$db = ($y + 100)
GUICtrlSetPos("3", $d, $db )
HotKeySet ( "{down}" , "_DownArrow" )
EndFunc

Func _LeftArrow()
HotKeySet ("{left}")
$l = ($x - 100)
$lb = ($y + 0)
GUICtrlSetPos("3", $l, $lb )
HotKeySet ( "{left}" , "_LeftArrow" )
EndFunc

Func _RightArrow()
HotKeySet ("{right}")
$r = ($x + 100)
$rb = ($y + 0)
GUICtrlSetPos("3", $r, $rb )
HotKeySet ( "{right}" , "_RightArrow" )
EndFunc

Func _zExitScript()
    Exit
EndFunc  ;==>_zExitScript

GuiCtrlCreatePic("1.jpg",$x, $y, 0, 0)

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Link to comment
Share on other sites

Not based of your code...

Just an example I already had.

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $dot
$GUI = GUICreate("Test", 500, 500, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$dot = GUICtrlCreateLabel(".", 50, 50, 5, 5)
GUICtrlSetBkColor(-1, 0x000000)

HotKeySet("{DOWN}", "_ScrollDown")
HotKeySet("{UP}", "_ScrollUp")
HotKeySet("{LEFT}", "_ScrollLeft")
HotKeySet("{RIGHT}", "_ScrollRight")

GUISetState(@SW_SHOW)

While 1
  Sleep(10)
WEnd

Func _ScrollDown()
    $GetPos = ControlGetPos($GUI, "", $dot)
    ControlMove($GUI, "", $dot, $GetPos[0], $GetPos[1]+5)
EndFunc

Func _ScrollUp()
    $GetPos = ControlGetPos($GUI, "", $dot)
    ControlMove($GUI, "", $dot, $GetPos[0], $GetPos[1]-5)
EndFunc

Func _ScrollLeft()
    $GetPos = ControlGetPos($GUI, "", $dot)
    ControlMove($GUI, "", $dot, $GetPos[0]-5, $GetPos[1])
EndFunc

Func _ScrollRight()
    $GetPos = ControlGetPos($GUI, "", $dot)
    ControlMove($GUI, "", $dot, $GetPos[0]+5, $GetPos[1])
EndFunc

Func _Exit()
  Exit
EndFunc
Link to comment
Share on other sites

i saw that in the helpfile. the only problem is, i want the image to just move in the gui, and the example in the helpfile allows the image to move anywhere at all.

I wrote that myself. Where is that in the help file?

It's the same basic concept, just replace the label with your pic.

Edited by The Ape
Link to comment
Share on other sites

now i have another question. can i change the 1.jpg to appear as another image, such as 2.jpg i have in my folder if i press a hotkey. like if i press up, my 1.jpg will now be 2.jpg, and move to the new location. if i press down it can be 3.jpg, and move down to the new location.

Edited by Tomb616
Link to comment
Share on other sites

Maybe because your code is a little weird anyway. :)

I see you using this: GUICtrlSetPos("3", $u, $ub )

Where is that "3" coming from? You should not be using that value directly, as it could change, you should instead be using the variable returned from GUICtrlCreatePic.

$picture = GUICtrlCreatePic('c:\pic.gif', 0, 0, 100, 100)
GUICtrlSetPos($picture, $u, $ub )oÝ÷ ظ¤zØZ´¢± +k'­"f z+wöÈî²Ö¬²)©æ®¶­sbb33c·7GW&RÒuT7G&Ä7&VFU2b33¶3¢b3#·2ævbb33²Â¤uT7G&Å6WDÖvRb33c·7GW&RÂb33¶3¢b3#¶æWw2ævbb33²

Just like that.

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