Sign in to follow this  
Followers 0
lordicast

GUICtrlSetGraphic Question

8 posts in this topic

Hello folks,

Is it possible to change the color of a graphic already drawn? I tried using a hotkey call

GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0, 0xff0000)

with no sucess please help.


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites



Soooo should I try a new approach I take it?


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

Delete and redraw the graphic. I think the results of GUICtrlSetGraphic() are changes to the pixels in a graphic, not a graphical element that can be manipulated later.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Can you not draw over the top?

#include <GUIConstantsEx.au3>

GUICreate ("test")

GUISetState ()

$hGraphic = GUICtrlCreateGraphic (2, 2, 100, 100)

GUICtrlSetGraphic ($hGraphic, $GUI_GR_MOVE, 0, 0)
GUICtrlSetGraphic ($hGraphic, $GUI_GR_COLOR, 0x0000FF, 0xFFFFFF) ; blue
GUICtrlSetGraphic ($hGraphic, $GUI_GR_LINE, 100, 100)
GUICtrlSetGraphic ($hGraphic, $GUI_GR_REFRESH)

Sleep (2000)

GUICtrlSetGraphic ($hGraphic, $GUI_GR_MOVE, 0, 0)
GUICtrlSetGraphic ($hGraphic, $GUI_GR_COLOR, 0xFF0000, 0xFFFFFF) ; red
GUICtrlSetGraphic ($hGraphic, $GUI_GR_LINE, 100, 100)
GUICtrlSetGraphic ($hGraphic, $GUI_GR_REFRESH)

Sleep (2000)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@Mat In this script that doesnt really work because it is called as a hotkey.

@PsaltyDS when using

func ReDraw()
GUICtrlDelete($Previous)
$New = GUICtrlCreateGraphic(24, 32, 400, 400)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0x008b00)
GUICtrlSetGraphic(-1, $GUI_GR_PIE, 200, 200, 190, 100, 80)
EndFunc

It only deletes the Graphic but does nothing to update it with $New graphic.

EDIT: Update

So I got working by deleting ctrl and redrawing then refreshing 1 problem with that is I have a Graphic ontop of it so when I redraw the graphic it covers previous object.

How do I keep that other object ontop without redrawing?

Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It did, but doesn't refresh the window immediately. Add $GUI_GR_REFRESH:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $ctrlGraphic = 0, $iColor = 0xFFFFFF
Global $hGUI = GUICreate("Draw Test", 300, 300)
GUISetState()
HotKeySet("g", "_Redraw") ; Hit 'g' to redraw graphic

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _Redraw()
    If $ctrlGraphic Then
        GUICtrlDelete($ctrlGraphic)
        $iColor -= 0x404040
        If $iColor < 0 Then $iColor = 0xFFFFFF
    EndIf
    $ctrlGraphic = GUICtrlCreateGraphic(10, 10, 280, 280)
    ConsoleWrite("Debug: $ctrlGraphic = " & $ctrlGraphic & "; $iColor = 0x" & Hex($iColor) & @LF)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetColor(-1, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $iColor)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 140, 140, 100, 30, 270)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $iColor)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 145, 141, 100, -60, 90)
    GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
EndFunc   ;==>ReDraw

...1 problem with that is I have a Graphic ontop of it so when I redraw the graphic it covers previous object.

How do I keep that other object ontop without redrawing?

With the control state:
GuiCtrlSetState($ctrlGraphic, $GUI_ONTOP)

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

@PsaltyDS !

WOW thanks so much what I was doing was creating multiple "Graphics" handles when I could just use 1 graphic to represent multiple grapics so this is what I was aiming for on a larger scale.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $ctrlGraphic = 0, $iColor = 0xFFFFFF
Global $hGUI = GUICreate("Draw Test", 300, 300)
GUISetState()
HotKeySet("g", "_Redraw") ; Hit 'g' to redraw graphic

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _Redraw()
    If $ctrlGraphic Then
        GUICtrlDelete($ctrlGraphic)
        $iColor -= 0x404040
        If $iColor < 0 Then $iColor = 0xFFFFFF
    EndIf
    $ctrlGraphic = GUICtrlCreateGraphic(10, 10, 280, 280)
    ConsoleWrite("Debug: $ctrlGraphic = " & $ctrlGraphic & "; $iColor = 0x" & Hex($iColor) & @LF)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetColor(-1, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $iColor)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 140, 140, 100, 30, 270)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 000000)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 145, 141, 100, -60, 90)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0x00ff00)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 145, 141, 20, 0, 360)
    GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
EndFunc   ;==>ReDraw

making the large cicle change color without affecting the Lime colored one.

Another question can I stop flickering when changing quickly?


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

Another question can I stop flickering when changing quickly?

I don't think so. Best you could do is limit it by adding some logic to ensure it doesn't redraw if the data hasn't changed significantly. Most of the flashing is probably redrawing unchanged data.

Beyond that, I think you would need to abandon GuiCtrlCreateGraphic() and use the GDI+ UDF instead.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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