Sign in to follow this  
Followers 0
Nemcija

A Gui idea

4 posts in this topic

#1 ·  Posted (edited)

Is there any way to improve the cpu usage of this:

;~ Includes
#include <Guiconstants.au3>
;~ opts
;~ funcs
Func terminate()
    Exit
EndFunc
;~ hotkeys
HotKeySet("{ESC}","terminate")
;~ vars
$sli = 0
$br = 100
$c_a = 0xff0000
$c_i = 0xffffff
;~ Gui
GUICreate("GraphSlider",$br+10,30)
    dim $grx[$br+1]
    for $i = 1 to $br
        $grx[$i] = GUICtrlCreateGraphic(5+$i,5,1,20)
        GUICtrlSetBkColor(-1,$c_i)
    Next
GUISetState(@SW_SHOW)
;~ runtime
While 1
    $msg = GUIGetMsg()
    for $i = 1 to $br
        If $msg = $grx[$i] Then
            if $sli < $i Then
                for $y = 1 to $br
                    if $y > $i Then
                        GUICtrlSetBkColor($grx[$y],$c_i)
                    Else
                        GUICtrlSetBkColor($grx[$y],$c_a)
                    EndIf
                Next
            Else
                for $y = 1 to $br
                    if ($br-$y) > $i Then
                        GUICtrlSetBkColor($grx[(($br+1)-$y)],$c_i)
                    Else
                        GUICtrlSetBkColor($grx[(($br+1)-$y)],$c_a)
                    EndIf
                Next
            EndIf
            $sli = $i
        EndIf
    Next
WEnd    
;~ end

Is there a gui object which is similar? (but FASTER) ^^

greetings, Nemcija

Edited by Nemcija

[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites



How is this a topic appropriate for the "Idea Lab"? Moved to Support where it belongs.

Share this post


Link to post
Share on other sites

uhhh if you don't already know, you need to add in sleeps like this:

While 1
    $msg = GUIGetMsg()
    for $i = 1 to $br
        If $msg = $grx[$i] Then
            if $sli < $i Then
                for $y = 1 to $br
                    if $y > $i Then
                        GUICtrlSetBkColor($grx[$y],$c_i)
                    Else
                        GUICtrlSetBkColor($grx[$y],$c_a)
                    EndIf
                Next
            Else
                for $y = 1 to $br
                    if ($br-$y) > $i Then
                        GUICtrlSetBkColor($grx[(($br+1)-$y)],$c_i)
                    Else
                        GUICtrlSetBkColor($grx[(($br+1)-$y)],$c_a)
                    EndIf
                Next
            EndIf
            $sli = $i
        EndIf
    Sleep ( 1 )
    Next
WEnd

Adjustments might need to be made if it decreases performance a ton


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Remarks

This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.

From the help file page for GUIGetMsg( [advanced] ).

Edit: fixed quite, missed line feed

Edited by Icekirby1

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