Jump to content

Hiding many elements cause form flickering


_Vlad
 Share

Recommended Posts

Hello forum,

I want to create a program with multiple menus and many elements inside. The problem is my way of doing this and below I have an example of how I do these menus.

I know it's a bad way of doing them as using this method for more elements and menus cause big flickering.

 

Can someone please help me with some tips of optimizing this or tell me another way of creating that menus with many elements without cause flickering? From a long time ago I still try to solve this but without any results, just small improvements.

Many thanks for everyone.

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

Global $MENU_HOVER = ''
Global $MENU_SELECTED = ''
Global $COLOR_STANDARD = 0x94A5E9
Global $COLOR_HOVER = 0x8292d1
Global $COLOR_SELECTED = 0x7584bf

$MENU = GUICreate("Menu", 615, 437, -1, -1, -1, -1, 0)
GUISetFont(10, 400, 0, "Arial")
$MENU_1 = GUICtrlCreateLabel("Menu 1", 8, 24, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$MENU_2 = GUICtrlCreateLabel("Menu 2", 8, 56, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$MENU_3 = GUICtrlCreateLabel("Menu 3", 8, 88, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE))

;MENU 1 ELEMENTS
$MENU_1_ELEMENT_1 = GUICtrlCreateButton("Menu1 Button", 128, 24, 147, 25)

;MENU 2 ELEMENTS
$MENU_2_ELEMENT_1 = GUICtrlCreateButton("Menu2 Button", 128, 24, 147, 25)
$MENU_2_ELEMENT_2 = GUICtrlCreateLabel("Another element", 128, 64, 99, 20)

_Design()
_Hide_All()
GUISetState(@SW_SHOW, $MENU)

While 1
    $Cursor = GUIGetCursorInfo($MENU)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $MENU_1
            _Previous_Selected_Cancel()
            $MENU_SELECTED = 'Menu1'
            GUICtrlSetBkColor($MENU_1, $COLOR_SELECTED)
            _Show('Menu1')

        Case $MENU_2
            _Previous_Selected_Cancel()
            $MENU_SELECTED = 'Menu2'
            GUICtrlSetBkColor($MENU_2, $COLOR_SELECTED)
            _Show('Menu2')

        Case $MENU_3
            _Previous_Selected_Cancel()
            $MENU_SELECTED = 'Menu3'
            GUICtrlSetBkColor($MENU_3, $COLOR_SELECTED)
            _Show('Menu3')

    EndSwitch

    If $Cursor[4] = $MENU_1 Then
        If $MENU_HOVER <> 'Menu1' And $MENU_SELECTED <> 'Menu1' Then
            _Previous_Hover_Cancel()
            GUICtrlSetBkColor($MENU_1, $COLOR_HOVER)
            $MENU_HOVER = 'Menu1'
        EndIf
    ElseIf $Cursor[4] = $MENU_2 Then
        If $MENU_HOVER <> 'Menu2' And $MENU_SELECTED <> 'Menu2' Then
            _Previous_Hover_Cancel()
            GUICtrlSetBkColor($MENU_2, $COLOR_HOVER)
            $MENU_HOVER = 'Menu2'
        EndIf
    ElseIf $Cursor[4] = $MENU_3 Then
        If $MENU_HOVER <> 'Menu3' And $MENU_SELECTED <> 'Menu3' Then
            _Previous_Hover_Cancel()
            GUICtrlSetBkColor($MENU_3, $COLOR_HOVER)
            $MENU_HOVER = 'Menu3'
        EndIf
    Else
        _Previous_Hover_Cancel()
        $MENU_HOVER = 'Idle'
    EndIf

WEnd

Func _Design()
    GUICtrlSetColor($MENU_1, 0xFFFFFF)
    GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD)
    GUICtrlSetCursor($MENU_1, 0)
    GUICtrlSetColor($MENU_2, 0xFFFFFF)
    GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD)
    GUICtrlSetCursor($MENU_2, 0)
    GUICtrlSetColor($MENU_3, 0xFFFFFF)
    GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD)
    GUICtrlSetCursor($MENU_3, 0)
EndFunc   ;==>_Design

Func _Hide_All()
    GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_HIDE)
    GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_HIDE)
    GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_HIDE)
EndFunc   ;==>_Hide_All

Func _Show($MENU_SHOW)

    _Hide_All()

    If $MENU_SHOW = 'Menu1' Then
        GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_SHOW)
    ElseIf $MENU_SHOW = 'Menu2' Then
        GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_SHOW)
        GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_SHOW)
    ElseIf $MENU_SHOW = 'Menu3' Then
    EndIf

EndFunc   ;==>_Show

Func _Previous_Hover_Cancel()

    If $MENU_HOVER = 'Menu1' Then
        If $MENU_SELECTED <> 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD)
    ElseIf $MENU_HOVER = 'Menu2' Then
        If $MENU_SELECTED <> 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD)
    ElseIf $MENU_HOVER = 'Menu3' Then
        If $MENU_SELECTED <> 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD)
    EndIf

EndFunc   ;==>_Previous_Hover_Cancel

Func _Previous_Selected_Cancel()
    If $MENU_SELECTED = 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD)
    If $MENU_SELECTED = 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD)
    If $MENU_SELECTED = 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD)
EndFunc   ;==>_Previous_Selected_Cancel

 

Link to comment
Share on other sites

There is no flickering here cause it's just an example of how I work around with multiple menus and elements. Try to add to this 5 more menus and 100+ elements, it will go crazy. :( This is why I want to discover another method of doing these better and optimized.

Link to comment
Share on other sites

1 minute ago, _Vlad said:

Try to add to this 5 more menus and 100+ elements, it will go crazy.

Could you upload an example of that kind of script so I can see what is the issue.

Link to comment
Share on other sites

8 minutes ago, _Vlad said:

Try to add to this 5 more menus and 100+ elements, it will go crazy. :( 

Please provide an example with e.g. 10 menus and 100+ elements. This saves us time to create it ourselves ;).

EDIT : Oh, @Nine was a bit faster :lol:.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

3 minutes ago, _Vlad said:

If it's necessary, give me a few minutes I will upscale this.

Yes, that would at least give us an impression of how strong the flickering is.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

It's difficult to rebuild as an example as I have a big source code file, that I am not allowed to put here.

Let me put that problem different,

How would you build multiple menus with many elements, different than this?

I try to search different solutions for optimizing a form with many elements, that's all or some multiple methods of building it more stable.

Link to comment
Share on other sites

Here is an example from @Melba23  :  creating-menus-using-arrays

Example from Melba23 :
https://www.autoitscript.com/forum/topic/136975-creating-menus-using-arrays/?do=findComment&comment=958203
#ce

#include <GUIConstantsEx.au3>

; Create an array to hold the menu items when created
Global $aMenuItems[1][2] = [[0]]

; Declare ini file
$sIni = @ScriptDir & "\Melba23.ini"

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; And start the menu creation process
_Fill_Menu(0, "MenuTitles")

GUISetState()

While 1

    ; Get the control ID
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; Loop through the array to see ifit is a menuitem controlID
            For $i = 1 To $aMenuItems[0][0]
                If $aMenuItems[$i][0] = $iMsg Then
                    ; It is!
                    MsgBox(0, "Menu", "You clicked " & @CRLF & $aMenuItems[$i][1])
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd



Func _Fill_Menu($hCID, $sText)

    ; Read next level down
    $aMenu = IniReadSection($sIni, $sText)
    If Not @error Then
        ; Now either create a further submenu or a menuitem
        For $i = 1 To $aMenu[0][0]
            Switch $aMenu[$i][0]
                Case "Item"
                    ; Increase the count of menuitems
                    $aMenuItems[0][0] += 1
                    ; Increase the array size by adding a new element
                    ReDim $aMenuItems[$aMenuItems[0][0] + 1][2]
                    ; Add the ControlID and text to the newly created array element
                    $aMenuItems[$aMenuItems[0][0]][0] = GUICtrlCreateMenuItem(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                    $aMenuItems[$aMenuItems[0][0]][1] = StringReplace($aMenu[$i][1], "_", " ")
                Case "Menu"
                    ; Create menu
                    If $hCID Then
                        ; It is a submenu
                        $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                    Else
                        ; It is a top level menu
                        $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "))
                    EndIf
                    ; Fill menu - note this is a recursive call and we need to take care
                    _Fill_Menu($aMenu[$i][0], $aMenu[$i][1])
            EndSwitch
        Next
    EndIf

EndFunc

 

Melba23.ini

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Thanks for the answers but it seems my problem can't be re-created here as the source code file is too large.

I already know how to do this kind of menu, but it doesn't help me as now I work on a good looking interface and at this chapter probably I will go with GDI+.

 

Thank you one more time.

Have a good day!

Edited by _Vlad
Link to comment
Share on other sites

it's simple, use GUICtrlCreateTab() and hide it  ;) 

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

;~ Global $MENU_HOVER = ''
;~ Global $MENU_SELECTED = ''
;~ Global $COLOR_STANDARD = 0x94A5E9
;~ Global $COLOR_HOVER = 0x8292d1
;~ Global $COLOR_SELECTED = 0x7584bf

Global $aLabels[18][5]
$aLabels[0][0] = UBound($aLabels) -1
SplashTextOn("..loading many things..", "..wait a sec..")
$MENU = GUICreate("Menu", 615, 437, -1, -1, -1, $WS_EX_COMPOSITED)
GUISetFont(10, 400, 0, "Arial")
For $n = 1 To $aLabels[0][0]
$aLabels[$n][0] = GUICtrlCreateButton("Menu " & $n, 8, 8 + (24 * ($n - 1)), 106, 23)
Next

$aLabels[0][1] = GUICtrlCreateTab(200,100,300,300)
GUICtrlSetState(-1, $GUI_HIDE)

For $n = 1 To $aLabels[0][0]
    $aLabels[$n][1] = GUICtrlCreateTabItem("Tab " & $n)
    For $m = 1 To 17 ; or whatever
        For $o = 1 To 5
            Switch Random(1, 5, 1)
                Case 1
                    GUICtrlCreateLabel("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 2
                    GUICtrlCreateButton("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 3
                    GUICtrlCreateInput("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 4
                    GUICtrlCreateCheckbox("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 5
                    GUICtrlCreateRadio("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
            EndSwitch
        Next
    Next
Next

GUISetState(@SW_SHOW, $MENU)

SplashOff()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case 0, -5, -6, -7, -8, -9, -10, -11
            ; save CPU
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
        Case Else
            For $n = 1 To $aLabels[0][0]
                If $nMsg = $aLabels[$n][0] Then
                    GUICtrlSetState($aLabels[$n][1], $GUI_SHOW)
                EndIf
            Next
    EndSwitch
WEnd

 

Edited by argumentum
added code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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

×
×
  • Create New...