Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Call function with params from a button? #150912
08/29/07 04:36
08/29/07 04:36
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I'm converting/re-writing one of my older programs, and I'm planning on using a function with PANEL* as a parameter. The thing is, I want to be able to access it from a button();. Is it possible to call a function from a button(); with parameters? I have a workaround in mind if it isn't, but I'm just checking before I do something redundant.

EDIT: according to the manual:

Quote:


Several buttons may share the same function. The number of the button is passed as the first parameter to the function (1 = first button), the panel pointer is passed as the second parameter.





does this mean that if I have a function with a PANEL* as a parameter (void blablabla(PANEL* _pan)), that it chooses the panel automatically?

Last edited by MrCode; 08/29/07 06:37.
Re: Call function with params from a button? [Re: MrCode] #150913
08/29/07 08:11
08/29/07 08:11
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
yes, i guess it will be set automatically, but i always define button functions with 2 parameters - panel pointer and button_number

Re: Call function with params from a button? [Re: Shadow969] #150914
08/29/07 21:51
08/29/07 21:51
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
It doesn't work.

I'll just have to use the redundant method, I guess.

EDIT: Ugh! More trouble! My for loops (apparently) aren't organized correctly. I don't see what's wrong, though.

Code:

void scroll_menu_switch(PANEL* _pan)
{
if(_pan.flags&= ~VISIBLE)
{
for(_pan.flags|= VISIBLE,_pan.scale_y= 0.005; _pan.scale_y < 1; _pan.scale_y+= 0.1 * time_step) wait(1);
}
else
{
for(_pan.scale_y; _pan.scale_y > 0.01; _pan.scale_y-= 0.1 * time_step) wait(1);
_pan.flags&= ~VISIBLE;
}
}



This is how I had the old wdl code before (pretty much the same idea):

Code:

function swap_gui_panel() // rolls up/down the GUI drop-down menus.
{
//gui_dropdown.visible= (gui_dropdown.visible== off);
//file_txt.visible= (file_txt.visible== off);
if (gui_dropdown.visible== off)
{
file_txt.visible= on;
gui_dropdown.scale_y= 0.01;
gui_dropdown.visible= on;
while(gui_dropdown.scale_y < 0.9)
{
gui_dropdown.scale_y+= 0.1 * time_step;
wait(1);
}
}
else
{
while(gui_dropdown.scale_y > 0.01)
{
gui_dropdown.scale_y-= 0.1 * time_step;
wait(1);
}
file_txt.visible= off;
wait(1);
gui_dropdown.visible= off;
}
}



I hate these brain-strains!

Last edited by MrCode; 08/29/07 21:58.
Re: Call function with params from a button? [Re: MrCode] #150915
08/30/07 04:33
08/30/07 04:33
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I've revised it, but I don't know how you can retrieve the button number on a panel.

Here's my Code:

#define OFF 0
...

int button_num,dummy;
...

void scroll_menu_down(PANEL* _pan)
{
for(_pan.scale_y= 0.1,_pan.flags|= VISIBLE; _pan.scale_y < 0.9; _pan.scale_y+= 0.1 * time_step) wait(1);
}

void scroll_menu_up(PANEL* _pan)
{
for(_pan.scale_y; _pan.scale_y > 0.1; _pan.scale_y-= 0.1 * time_step) wait(1);
}

void menu()
{
dummy= (dummy== OFF);
switch(button_num)
{
case 1:
if(dummy== 0)
{
scroll_menu_down(gui_dropdown1);
}
else
{
scroll_menu_up(gui_dropdown1);
}
case 2:
if(dummy== 0)
{
scroll_menu_down(gui_dropdown2);
}
else
{
scroll_menu_up(gui_dropdown2);
}
case 3:
if(dummy== 0)
{
scroll_menu_down(gui_dropdown3);
}
else
{
scroll_menu_up(gui_dropdown3);
}
case 4:
if(dummy== 0)
{
scroll_menu_down(gui_dropdown4);
}
else
{
scroll_menu_up(gui_dropdown4);
}
}
}



I have no idea how to set this all up to work with the buttons.

I guess I should just give up trying to make my programming sleeker, if it's going to be more difficult than doing it the long way.

EDIT: Yay! with a little more revision, it works! Well, sort of. You have to click on one button at least once before you can open the menus. And the behavior of it is odd when you have multiple things open at one time (not that you'll need to ).

Last edited by MrCode; 08/30/07 05:24.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Call function with params from a button? [Re: MrCode] #150916
08/30/07 08:00
08/30/07 08:00
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Code:
if(_pan.flags&= ~VISIBLE)


I guess you want to check if the VISIBLE flag is off. You should do it like this:
Code:
if((_pan.flags) & (~VISIBLE))


Or else it will reset the flag. Remember, if there is an "=" in there, it can change the flags.

Also, you should always initialize your variables. Maybe your problem ("You have to click on one button at least once before you can open the menus.") is related to this.

int button_num = 0, dummy = 0;

Re: Call function with params from a button? [Re: Excessus] #150917
08/30/07 16:08
08/30/07 16:08
Joined: Mar 2007
Posts: 75
Hamburg, Ger
Altimeter Offline
Junior Member
Altimeter  Offline
Junior Member

Joined: Mar 2007
Posts: 75
Hamburg, Ger
Essentially I do the same like you: panel calls one function for all buttons. This function then makes use of switch case or if (..){..};
My function looks like this:

void pnlPanClicked(var button_number,PANEL* pan) //select, which button was pressed on panel pan

{
if (button_number == 1)
{
scroll_menu_down(gui_dropdown2);
}
if (button_number == 2)
{
....
etc
}


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1