Janos Siklosi Posted November 28, 2010 Posted November 28, 2010 (edited) Hi, I'm making little utility and have a some problems. My script has some rectangles 3x for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) $rgbled1[$i+1] = GUICtrlCreateGraphic($line*30-20, $col*30-20, 30, 30) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, 0x000000) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 30) next I also have two color pickers and idea is to use left/right mouse button (picker1/picker2's color) and to change colors of rectangles (also generate code for microcontroller and put into $input's) right now I have couple of problems. When I click on first rectangle guigetmsg gets called by case $rgbled1[1] but GUICtrlSetBkColor($rgbled1[1], 0xff0000) doesn't change color of rectangle (do I need to redraw form or...?) Also is there a way to detect left/right click on each rectangle and do something without typing 192 case's (3 x 8x8 rectangles)... frankly I don't know how to detect right mouse button click on rectangle even with typing every case separately. This is "complete" code that is where I bumped int wall... expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <ColorPicker.au3> #include <Misc.au3> Opt('MustDeclareVars', 1) Global $Form1, $rgbled1[65], $rgbled2[65], $rgbled3[65], $Input1, $Input2, $Input3, $Input4, $Input5, $Label1, $Label2, $Label3, $Label4, $Label5, $Label6, $Label7, $Button1, $Button2, $Button3, $Button4, $Button5, $Picker1, $Picker2, $hCursor, $nMsg, $Data, $Datal, $Datar, $RGBLEDs[193], $RGBLEDs1, $RGBLEDs2, $RGBLEDs3, $RGBLEDs4, $RGBLEDs5, $i, $line, $col $Form1 = GUICreate("Editor", 942, 444, 293, 333) for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) $rgbled1[$i+1] = GUICtrlCreateGraphic($line*30-20, $col*30-20, 30, 30) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, 0x000000) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 30) next for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) $rgbled2[$i+1] = GUICtrlCreateGraphic($line*30+225, $col*30-20, 30, 30) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, 0x000000) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 30) next for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) $rgbled3[$i+1] = GUICtrlCreateGraphic($line*30+470, $col*30-20, 30, 30) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, 0x000000) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 30) next $Input1 = GUICtrlCreateInput("", 60, 280, 769, 21) $Input2 = GUICtrlCreateInput("", 60, 311, 769, 21) $Input3 = GUICtrlCreateInput("", 60, 343, 769, 21) $Input4 = GUICtrlCreateInput("", 60, 375, 769, 21) $Input5 = GUICtrlCreateInput("", 60, 407, 769, 21) $Label1 = GUICtrlCreateLabel("1:", 40, 288, 13, 17) $Label2 = GUICtrlCreateLabel("2:", 40, 320, 13, 17) $Label3 = GUICtrlCreateLabel("3:", 40, 352, 13, 17) $Label4 = GUICtrlCreateLabel("1+2:", 32, 384, 25, 17) $Label5 = GUICtrlCreateLabel("1+2+3:", 22, 416, 37, 17) $Button1 = GUICtrlCreateButton("Copy to Clipboard", 840, 280, 97, 25) $Button2 = GUICtrlCreateButton("Copy to Clipboard", 840, 312, 97, 25) $Button3 = GUICtrlCreateButton("Copy to Clipboard", 840, 344, 97, 25) $Button4 = GUICtrlCreateButton("Copy to Clipboard", 840, 376, 97, 25) $Button5 = GUICtrlCreateButton("Copy to Clipboard", 840, 408, 97, 25) $Label6 = GUICtrlCreateLabel("Left Button:", 776, 56, 59, 17) $Label7 = GUICtrlCreateLabel("Right Button:", 773, 129, 66, 17) $Picker1 = _GUIColorPicker_Create('', 832, 10, 105, 65, 0xFF0000, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_CHOOSERBUTTON), 0, -1, -1, $hCursor, 'Select LED Color') $Picker2 = _GUIColorPicker_Create('', 832, 80, 105, 65, 0x000000, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_CHOOSERBUTTON), 0, -1, -1, $hCursor, 'Select LED Color') ;set default values for $i = 1 to 192 $rgbleds[$i] = "000000" Next $Datal = "FF0000" $Datar = "000000" GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Picker1 $Data = _GUIColorPicker_GetColor($Picker1, 1) $Datal=(Hex($Data[0], 6)) Case $Picker2 $Data = _GUIColorPicker_GetColor($Picker2, 1) $Datar=(Hex($Data[0], 6)) case $rgbled1[1] ConsoleWrite("Event triggered " & $Datal) GUICtrlSetBkColor($rgbled1[1], 0xff0000) ; should be I guess '0x' & $datal instead of 0xff0000 but it's not working anyway fillinputs() case $button1 ClipPut(GUICtrlRead($Input1)) case $button2 ClipPut(GUICtrlRead($Input2)) case $button3 ClipPut(GUICtrlRead($Input3)) case $button4 ClipPut(GUICtrlRead($Input4)) case $button5 ClipPut(GUICtrlRead($Input5)) EndSwitch WEnd func fillinputs() $rgbleds1="" $rgbleds2="" $rgbleds3="" $rgbleds4="" $rgbleds5="" $rgbleds[1]=$Datal for $i = 1 to 64 $rgbleds1 = $rgbleds1 & $rgbleds[$i] next GUICtrlSetData($input1,$rgbleds1) for $i = 65 to 128 $rgbleds2 = $rgbleds2 & $rgbleds[$i] Next GUICtrlSetData($input2,$rgbleds2) for $i = 129 to 192 $rgbleds3 = $rgbleds3 & $rgbleds[$i] Next GUICtrlSetData($input3,$rgbleds3) for $i = 1 to 128 $rgbleds4 = $rgbleds4 & $rgbleds[$i] Next GUICtrlSetData($input4,$rgbleds4) for $i = 1 to 192 $rgbleds5 = $rgbleds5 & $rgbleds[$i] Next GUICtrlSetData($input5,$rgbleds5) EndFunc Thanks in advance... Edited November 28, 2010 by Janos Siklosi
Janos Siklosi Posted November 29, 2010 Author Posted November 29, 2010 OK I made some progress... basically it's all working except right mouse button... I figured that when using GuiGetMsg(1) you can get mouse position so I used that and made only 3 graphics with 64 rectangles each and only 3 case's. Still not working is right mouse button detection... But even without that I could declare it as solved... but if anyone has any tip about right mouse button... I would appreciate... Here is working code:expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <ColorPicker.au3> #include <Misc.au3> Opt('MustDeclareVars', 1) Global $Form1, $mcpx, $mcpy, $rgbled1, $rgbled2, $rgbled3, $led, $Input1, $Input2, $Input3, $Input4, $Input5, $Label1, $Label2, $Label3, $Label4, $Label5, $Label6, $Label7, $Button1, $Button2, $Button3, $Button4, $Button5, $Picker1, $Picker2, $hCursor, $nMsg, $Data, $Datal, $Datar, $RGBLEDs[193], $RGBLEDs1, $RGBLEDs2, $RGBLEDs3, $RGBLEDs4, $RGBLEDs5, $i, $line, $col $Form1 = GUICreate("Editor", 942, 444, 293, 333) $Input1 = GUICtrlCreateInput("", 60, 280, 769, 21) $Input2 = GUICtrlCreateInput("", 60, 311, 769, 21) $Input3 = GUICtrlCreateInput("", 60, 343, 769, 21) $Input4 = GUICtrlCreateInput("", 60, 375, 769, 21) $Input5 = GUICtrlCreateInput("", 60, 407, 769, 21) $Label1 = GUICtrlCreateLabel("1:", 40, 288, 13, 17) $Label2 = GUICtrlCreateLabel("2:", 40, 320, 13, 17) $Label3 = GUICtrlCreateLabel("3:", 40, 352, 13, 17) $Label4 = GUICtrlCreateLabel("1+2:", 32, 384, 25, 17) $Label5 = GUICtrlCreateLabel("1+2+3:", 22, 416, 37, 17) $Button1 = GUICtrlCreateButton("Copy to Clipboard", 840, 280, 97, 25) $Button2 = GUICtrlCreateButton("Copy to Clipboard", 840, 312, 97, 25) $Button3 = GUICtrlCreateButton("Copy to Clipboard", 840, 344, 97, 25) $Button4 = GUICtrlCreateButton("Copy to Clipboard", 840, 376, 97, 25) $Button5 = GUICtrlCreateButton("Copy to Clipboard", 840, 408, 97, 25) $Label6 = GUICtrlCreateLabel("Left Button:", 776, 56, 59, 17) $Label7 = GUICtrlCreateLabel("Right Button:", 773, 129, 66, 17) $Picker1 = _GUIColorPicker_Create('', 832, 10, 105, 65, 0xFF0000, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_CHOOSERBUTTON), 0, -1, -1, $hCursor, 'Select LED Color') $Picker2 = _GUIColorPicker_Create('', 832, 80, 105, 65, 0x000000, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_CHOOSERBUTTON), 0, -1, -1, $hCursor, 'Select LED Color') ;set default values for $i = 1 to 192 $rgbleds[$i] = "000000" Next $Datal = "FF0000" $Datar = "000000" drawled1() drawled2() drawled3() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[0] Case $GUI_EVENT_CLOSE Exit Case $Picker1 $Data = _GUIColorPicker_GetColor($Picker1, 1) $Datal=(Hex($Data[0], 6)) Case $Picker2 $Data = _GUIColorPicker_GetColor($Picker2, 1) $Datar=(Hex($Data[0], 6)) case $rgbled1 $mcpx=$nMsg[3] - 10 $mcpy=$nMsg[4] -10 $line = Ceiling($mcpy/30) $col = Ceiling($mcpx/30) ConsoleWrite($nMsg[0] & @CR) $rgbleds[($line-1)*8+$col]="0x"&$datal fillinputs() GUICtrlDelete($rgbled1) drawled1() case $rgbled2 $mcpx=$nMsg[3] - 260 $mcpy=$nMsg[4] -10 $line = Ceiling($mcpy/30) $col = Ceiling($mcpx/30) $rgbleds[(($line-1)*8+$col)+64]="0x"&$datal fillinputs() GUICtrlDelete($rgbled2) drawled2() case $rgbled3 $mcpx=$nMsg[3] - 520 $mcpy=$nMsg[4] -10 $line = Ceiling($mcpy/30) $col = Ceiling($mcpx/30) $rgbleds[(($line-1)*8+$col)+128]="0x"&$datal fillinputs() GUICtrlDelete($rgbled3) drawled3() case $button1 ClipPut(GUICtrlRead($Input1)) case $button2 ClipPut(GUICtrlRead($Input2)) case $button3 ClipPut(GUICtrlRead($Input3)) case $button4 ClipPut(GUICtrlRead($Input4)) case $button5 ClipPut(GUICtrlRead($Input5)) EndSwitch WEnd func fillinputs() $rgbleds1="" $rgbleds2="" $rgbleds3="" $rgbleds4="" $rgbleds5="" for $i = 1 to 64 $rgbleds1 = $rgbleds1 & $rgbleds[$i] next GUICtrlSetData($input1,$rgbleds1) for $i = 65 to 128 $rgbleds2 = $rgbleds2 & $rgbleds[$i] Next GUICtrlSetData($input2,$rgbleds2) for $i = 129 to 192 $rgbleds3 = $rgbleds3 & $rgbleds[$i] Next GUICtrlSetData($input3,$rgbleds3) for $i = 1 to 128 $rgbleds4 = $rgbleds4 & $rgbleds[$i] Next GUICtrlSetData($input4,$rgbleds4) for $i = 1 to 192 $rgbleds5 = $rgbleds5 & $rgbleds[$i] Next GUICtrlSetData($input5,$rgbleds5) EndFunc func drawled1() $rgbled1 = GUICtrlCreateGraphic(10, 10, 250, 250) for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, $rgbleds[$i+1]) GUICtrlSetGraphic(-1, $GUI_GR_RECT, $line*30-30, $col*30-30, 30, 30) next GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) EndFunc func drawled2() $rgbled2 = GUICtrlCreateGraphic(260, 10, 250, 250) for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, $rgbleds[$i+65]) GUICtrlSetGraphic(-1, $GUI_GR_RECT, $line*30-30, $col*30-30, 30, 30) next GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) EndFunc func drawled3() $rgbled3 = GUICtrlCreateGraphic(520, 10, 250, 250) for $i = 0 to 63 $line = Mod($i,8)+1 $col = Ceiling(($i +1)/8) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x222222, $rgbleds[$i+129]) GUICtrlSetGraphic(-1, $GUI_GR_RECT, $line*30-30, $col*30-30, 30, 30) next GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) EndFuncThis script need's Yashied's ColorPicker.au3
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now