GUIs SetVisibility Show/Hide? How?

Hello Experts,

This is what I am upto. I have a little GfxRoundRect (to form a Circle LOL!) called EnablerCir. Using CTRL + Left Click Down (thanks to Milosz for sharing) to Position a capsule-like another GfxRoundRect containing several other GUIs called CapsuleRect.

Also hoping to use EnablerCir as a button to hide or show other GUIs with its previous state intact. So, let's say when I click on a GuiToggle its state is registered as Selected along other associated events. Then in order to utilize chart space I click on EnablerCir to hide the GUIs. This is where I am struggling and unable to figure out a way by which the code could dynamically remember the previous state of the GUI. So, when a GUI is "Shown" after being "Hidden", it would not only remember what was its previous state but also maintain the cause of its previously generated events while being "Hidden".

Uff! Sorry to ask is it possible? Below is a GIF and a code where I am unable to go beyond VisGUI.

Snips

_SECTION_BEGIN( "MA System" );
	 ChId = GetChartID();
	 xPos = yPos = 0;
	 MsBtnPressed = GetCursorMouseButtons();
	 MsLftJstClikd = MsBtnPressed & 9;
	 MsMdleJstClikd = MsBtnPressed & 4;
	 CtrlPressed =  GetAsyncKeyState( 17 ) < 0;
	 MousePxX = GetCursorXPosition( 1 );
	 MousePxY = GetCursorYPosition( 1 );
	 
	 //===========================Sliding Enabler Button============================
	 if( CtrlPressed )
	 {
		 if( MsLftJstClikd )
		 {
			 StaticVarSet( "#xPosEnablerCir" + ChId, MousePxX, False );
			 StaticVarSet( "#yPosEnablerCir" + ChId, MousePxY, False );
			 StaticVarSet( "#EnablerCirClr" + ChId, colorBlue, False );
		 }
		 if( MsMdleJstClikd )
		 {
			 StaticVarSet( "#xPosEnablerCir" + ChId, Null, False );
			 StaticVarSet( "#yPosEnablerCir" + ChId, Null, False );
		 }
		 RequestMouseMoveRefresh();
	 }
	 else
	 {
		 StaticVarSet( "#EnablerCirClr" + ChId, Null, False );
	 }
	 xPosEnablerCir = Nz( StaticVarGet( "#xPosEnablerCir" + ChId, False ), 0 );
	 yPosEnablerCir = Nz( StaticVarGet( "#yPosEnablerCir" + ChId, False ), 0 );
	 EnablerCirWidth = 10;
	 EnablerCirHeight = EnablerCirWidth;
	 EnablerCirX1 = xPosEnablerCir - EnablerCirWidth;
	 EnablerCirY1 = yPosEnablerCir - EnablerCirHeight;
	 EnablerCirX2 = xPosEnablerCir + EnablerCirWidth;
	 EnablerCirY2 = yPosEnablerCir + EnablerCirHeight;
	 EnablerCirClr = Nz( StaticVarGet( "#EnablerCirClr" + ChId, False ), ColorRGB( 179, 189, 208 ) );
	 GfxSetZOrder( 5 );
	 GfxSelectSolidBrush( EnablerCirClr );
	 GfxRoundRect( EnablerCirX1, EnablerCirY1, EnablerCirX2, EnablerCirY2, 18, 18 );
	 
	 CrsrInEnablerCir = MousePxX >= EnablerCirX1 AND MousePxX <= EnablerCirX2 AND MousePxY >= EnablerCirY1 AND MousePxY <= EnablerCirY2;
	 mipEnablerCir = Nz( StaticVarGet( "#mipEnablerCir" + ChId, False ), False ); //mip => Move In Progress
	 FrstClkEnablerCir = NOT mipEnablerCir AND CrsrInEnablerCir AND MsLftJstClikd;
	 ScndClkEnablerCir = mipEnablerCir AND CrsrInEnablerCir AND MsLftJstClikd;
	 if( FrstClkEnablerCir )
	 {
		 StaticVarSet( "#mipEnablerCir" + ChId, True, False );
		 StaticVarSet( "#VisGUI" + ChId, 1, False );
	 }
	 else if( ScndClkEnablerCir )
	 {
		 StaticVarSet( "#mipEnablerCir" + ChId, Null, False );
		 StaticVarSet( "#VisGUI" + ChId, 0, False );
	 }
	 //==============================================================================
	 
	 VisGUI = Nz( StaticVarGet( "#VisGUI" + ChId, False ), 0 );
	 if( VisGUI )
	 {
		 //===========================Rectangular Button Capsule===========================
		 CapsuleRectWidth = 113;
		 CapsuleRectHeight = 77;
		 CapsuleRectX1 = xPosEnablerCir;
		 CapsuleRectY1 = yPosEnablerCir;
		 CapsuleRectX2 = CapsuleRectX1 + CapsuleRectWidth;
		 CapsuleRectY2 = CapsuleRectY1 + CapsuleRectHeight;
		 //CapsuleRectClr = Nz( StaticVarGet( "#CapsuleRectClr" + ChId, False ), ColorRGB( 74, 93, 128 ) );
		 CapsuleRectClr = ColorRGB( 74, 93, 128 );
		 GfxSetZOrder( 4 );
		 GfxSelectSolidBrush( CapsuleRectClr );
		 GfxRoundRect( CapsuleRectX1, CapsuleRectY1, CapsuleRectX2, CapsuleRectY2, 18, 18 );
		 //================================================================================
	 
	 
		 //================================Drawing GUI Buttons=============================
		 GuiBtnHght = 20;
		 MASysBtnWidth = 73;
		 MASysBtnX = xPosEnablerCir + 22;
		 MASysBtnY = yPosEnablerCir + 6;
		 GuiToggle( "MA System", 1, MASysBtnX, MASysBtnY, MASysBtnWidth, GuiBtnHght, 1 );
		 GuiSetColors( 1, 1, 0, colorWhite, CapsuleRectClr, -1, colorBlack, ColorRGB( 255, 232, 166 ), -1, colorBlack, ColorRGB( 255, 250, 234 ), -1, -1, -1, -1 );
		 
		 //SMA/EMA Buttons
		 MABtnWidth = 35;
		 MABtnX = xPosEnablerCir + 6;
		 MABtnY = MASysBtnY + GuiBtnHght + 2;
		 for( i = 2; i <= 3; i++ )
		 {
			 if( i == 2 ) BtnTxt = "SMA";
			 else BtnTxt = "EMA";
			 GuiToggle( BtnTxt, i, MABtnX, MABtnY, MABtnWidth, GuiBtnHght, 1 );
			 MABtnY = MABtnY + GuiBtnHght;
		 }
	 
		 //SMA Level Buttons
		 SMABtnWidth = 20;
		 SMABtnX = MABtnX + MABtnWidth + 6;
		 SMABtnY = MASysBtnY + GuiBtnHght + 2;
		 for( i = 21; i <= 23; i++ )
		 {
			 if( i == 21 ) BtnTxt = "8";
			 else if( i == 22 ) BtnTxt = "13";
			 else BtnTxt = "21";
			 GuiToggle( BtnTxt, i, SMABtnX, SMABtnY, SMABtnWidth, GuiBtnHght, 1 );
			 SMABtnX = SMABtnX + SMABtnWidth;
		 }
	 
		 //EMA Level Buttons
		 EMABtnWidth = 20;
		 EMABtnX = MABtnX + MABtnWidth + 6;
		 EMABtnY = SMABtnY + GuiBtnHght + 2;
		 for( i = 31; i <= 33; i++ )
		 {
			 if( i == 31 ) BtnTxt = "8";
			 else if( i == 32 ) BtnTxt = "13";
			 else BtnTxt = "21";
			 GuiToggle( BtnTxt, i, EMABtnX, EMABtnY, EMABtnWidth, GuiBtnHght, 1 );
			 EMABtnX = EMABtnX + EMABtnWidth;
		 }
		 //================================================================================
	 }
	 
	 /*
	 ============================Event Circuits of GUIs================================
	 Do something something with the buttons
	 ...
	 ...
	 ...
	 ==================================================================================
	 */	 
_SECTION_END();

Zillion Thanks!

@cougar, a lazy way to do it is to never truly "hide" but simply move the controls offscreen when hiding (add a huge x or y offset) and reset the original coordinates for "show".

3 Likes

@beppe thanks. Below is as per your suggestion:

_SECTION_BEGIN( "MA System" );
	 ChId = GetChartID();
	 xPos = yPos = 0;
	 MsBtnPressed = GetCursorMouseButtons();
	 MsLftJstClikd = MsBtnPressed & 9;
	 MsMdleJstClikd = MsBtnPressed & 4;
	 CtrlPressed =  GetAsyncKeyState( 17 ) < 0;
	 MousePxX = GetCursorXPosition( 1 );
	 MousePxY = GetCursorYPosition( 1 );
	 
	 //===========================Sliding Enabler Button============================
	 if( CtrlPressed )
	 {
		 if( MsLftJstClikd )
		 {
			 StaticVarSet( "#xPosEnablerCir" + ChId, MousePxX, False );
			 StaticVarSet( "#yPosEnablerCir" + ChId, MousePxY, False );
			 StaticVarSet( "#EnablerCirClr" + ChId, colorBlue, False );
		 }
		 if( MsMdleJstClikd )
		 {
			 StaticVarSet( "#xPosEnablerCir" + ChId, Null, False );
			 StaticVarSet( "#yPosEnablerCir" + ChId, Null, False );
		 }
		 RequestMouseMoveRefresh();
	 }
	 else
	 {
		 StaticVarSet( "#EnablerCirClr" + ChId, Null, False );
	 }
	 xPosEnablerCir = Nz( StaticVarGet( "#xPosEnablerCir" + ChId, False ), 0 );
	 yPosEnablerCir = Nz( StaticVarGet( "#yPosEnablerCir" + ChId, False ), 0 );
	 EnablerCirWidth = 10;
	 EnablerCirHeight = EnablerCirWidth;
	 EnablerCirX1 = xPosEnablerCir - EnablerCirWidth;
	 EnablerCirY1 = yPosEnablerCir - EnablerCirHeight;
	 EnablerCirX2 = xPosEnablerCir + EnablerCirWidth;
	 EnablerCirY2 = yPosEnablerCir + EnablerCirHeight;
	 EnablerCirClr = Nz( StaticVarGet( "#EnablerCirClr" + ChId, False ), ColorRGB( 179, 189, 208 ) );
	 GfxSetZOrder( 5 );
	 GfxSelectSolidBrush( EnablerCirClr );
	 GfxRoundRect( EnablerCirX1, EnablerCirY1, EnablerCirX2, EnablerCirY2, 18, 18 );
	 
	 CrsrInEnablerCir = MousePxX >= EnablerCirX1 AND MousePxX <= EnablerCirX2 AND MousePxY >= EnablerCirY1 AND MousePxY <= EnablerCirY2;
	 mipEnablerCir = Nz( StaticVarGet( "#mipEnablerCir" + ChId, False ), False ); //mip => Move In Progress
	 FrstClkEnablerCir = NOT mipEnablerCir AND CrsrInEnablerCir AND MsLftJstClikd;
	 ScndClkEnablerCir = mipEnablerCir AND CrsrInEnablerCir AND MsLftJstClikd;
	 if( FrstClkEnablerCir )
	 {
		 StaticVarSet( "#mipEnablerCir" + ChId, True, False );
		 StaticVarSet( "#CapsuleRectX1" + ChId, Null );
		 StaticVarSet( "#CapsuleRectY1" + ChId, Null );
	 }
	 else if( ScndClkEnablerCir )
	 {
		 StaticVarSet( "#mipEnablerCir" + ChId, Null, False );
		 pxWidth = Status( "pxchartwidth" );
		 pxHeight = Status( "pxchartheight" );
		 StaticVarSet( "#CapsuleRectX1" + ChId, pxWidth*2 );
		 StaticVarSet( "#CapsuleRectY1" + ChId, pxHeight*2 );
	 }
	 //==============================================================================
	 
	 //===========================Rectangular Button Capsule===========================
	 CapsuleRectWidth = 113;
	 CapsuleRectHeight = 77;
	 CapsuleRectX1 = Nz( StaticVarGet( "#CapsuleRectX1" + ChId, False ), xPosEnablerCir );
	 CapsuleRectY1 = Nz( StaticVarGet( "#CapsuleRectY1" + ChId, False ), yPosEnablerCir );
	 CapsuleRectX2 = CapsuleRectX1 + CapsuleRectWidth;
	 CapsuleRectY2 = CapsuleRectY1 + CapsuleRectHeight;
	 //CapsuleRectClr = Nz( StaticVarGet( "#CapsuleRectClr" + ChId, False ), ColorRGB( 74, 93, 128 ) );
	 CapsuleRectClr = ColorRGB( 74, 93, 128 );
	 GfxSetZOrder( 4 );
	 GfxSelectSolidBrush( CapsuleRectClr );
	 GfxRoundRect( CapsuleRectX1, CapsuleRectY1, CapsuleRectX2, CapsuleRectY2, 18, 18 );
	 //================================================================================
	
	
	 //================================Drawing GUI Buttons=============================
	 GuiBtnHght = 20;
	 MASysBtnWidth = 73;
	 MASysBtnX = CapsuleRectX1 + 22;
	 MASysBtnY = CapsuleRectY1 + 6;
	 GuiToggle( "MA System", 1, MASysBtnX, MASysBtnY, MASysBtnWidth, GuiBtnHght, 1 );
	 GuiSetColors( 1, 1, 0, colorWhite, CapsuleRectClr, -1, colorBlack, ColorRGB( 255, 232, 166 ), -1, colorBlack, ColorRGB( 255, 250, 234 ), -1, -1, -1, -1 );
	
	 //SMA/EMA Buttons
	 MABtnWidth = 35;
	 MABtnX = CapsuleRectX1 + 6;
	 MABtnY = MASysBtnY + GuiBtnHght + 2;
	 for( i = 2; i <= 3; i++ )
	 {
		 if( i == 2 ) BtnTxt = "SMA";
		 else BtnTxt = "EMA";
		 GuiToggle( BtnTxt, i, MABtnX, MABtnY, MABtnWidth, GuiBtnHght, 1 );
		 MABtnY = MABtnY + GuiBtnHght;
	 }
	
	 //SMA Level Buttons
	 SMABtnWidth = 20;
	 SMABtnX = MABtnX + MABtnWidth + 6;
	 SMABtnY = MASysBtnY + GuiBtnHght + 2;
	 for( i = 21; i <= 23; i++ )
	 {
		 if( i == 21 ) BtnTxt = "8";
		 else if( i == 22 ) BtnTxt = "13";
		 else BtnTxt = "21";
		 GuiToggle( BtnTxt, i, SMABtnX, SMABtnY, SMABtnWidth, GuiBtnHght, 1 );
		 SMABtnX = SMABtnX + SMABtnWidth;
	 }
	
	 //EMA Level Buttons
	 EMABtnWidth = 20;
	 EMABtnX = MABtnX + MABtnWidth + 6;
	 EMABtnY = SMABtnY + GuiBtnHght + 2;
	 for( i = 31; i <= 33; i++ )
	 {
		 if( i == 31 ) BtnTxt = "8";
		 else if( i == 32 ) BtnTxt = "13";
		 else BtnTxt = "21";
		 GuiToggle( BtnTxt, i, EMABtnX, EMABtnY, EMABtnWidth, GuiBtnHght, 1 );
		 EMABtnX = EMABtnX + EMABtnWidth;
	 }
	 //================================================================================
	 
	 /*
	 ============================Event Circuits of GUIs================================
	 Do something something with the buttons
	 ...
	 ...
	 ...
	 ==================================================================================
	 */	 
_SECTION_END();

Any alternate legit way to deal with it? Lol :smile:

1 Like

In 6.30 you will have this:
http://www.amibroker.com/f?guisetvisible

5 Likes

@Tomasz Thank you very much.....