Panel and Button

Posted By: Anonymous2009

Panel and Button - 04/11/09 13:21

I'm using Bloodshed Dev-C++ for C++ using A7 engine (version 7.06.1).

Showing panels itself is no problem, but I don't know how to implement buttons into them. When I try to implement button into my panel, both bmap and button give me an error that they are undeclared.

I tried all variations of buttons and different ways of putting them:
button_toggle(_VAR(0), _VAR(0), resume0_bmp, resume0_bmp, resume1_bmp, resume1_bmp, NULL, NULL, NULL);
and
button_toggle = _VAR(0), _VAR(0), resume0_bmp, resume0_bmp, resume1_bmp, resume1_bmp, NULL, NULL, NULL;

This is part of my codes (there are no functions inside my button, it is still in testing phase):

Code:
BMAP* resume0_bmp = bmap_create("button_resumeOut.bmp");
BMAP* resume1_bmp = bmap_create("button_resumeOver.bmp");
PANEL* pause_pan;

void loadHUD()
{
   pause_pan = pan_create("bmap = screen_pause.tga;", _VAR(2));

   pause_pan->pos_x = _VAR(373);
   pause_pan->pos_y = _VAR(197);
   pause_pan->flags |= OVERLAY | TRANSLUCENT;
   button_toggle(_VAR(0), _VAR(0), resume0_bmp, resume0_bmp, resume1_bmp, resume1_bmp, NULL, NULL, NULL);
}

void engine_init()
{
   ev = engine_open(NULL);
   SETV(video_mode, 8);
   SETV(max_particles, 20000);
   SETV(max_entities, 2000);
   SETV(fps_max, 60);
   SETV(ph_fps_max_lock, 60);
   SETV(shadow_stencil, ON);

   ...

   loadHUD();

   ...
}


Creating it using this method doesn't give any error on compiling but crash while running.

Code:
PANEL* pause_pan = pan_create("bmap = screen_pause.tga; pos_x = _VAR(373); pos_y = _VAR(197); button_toggle(_VAR(0), _VAR(0), resume0_bmp, resume0_bmp, resume1_bmp, resume1_bmp, NULL, NULL, NULL); flags |= OVERLAY | TRANSLUCENT | INVISIBLE;", _VAR(3));


Anyone know what is my problem? How can I solve it?

EDIT: typo
Posted By: Cowabanga

Re: Panel and Button - 04/11/09 13:39

I have no idea about the problem. But, try to update your Gamestudio. smile
Posted By: EvilSOB

Re: Panel and Button - 04/11/09 21:30

Your BMAPs are declared incorrectly for globals.

You would use this syntax if you were declaring LOCAL bmaps (INSIDE a function),
BMAP* resume0_bmp = bmap_create("button_resumeOut.bmp");
BMAP* resume1_bmp = bmap_create("button_resumeOver.bmp");

But you are defining GLOBAL bmaps (OUTSIDE a function), so you need to use
BMAP* resume0_bmp = "button_resumeOut.bmp";
BMAP* resume1_bmp = "button_resumeOver.bmp";

Its weird I know, but thats how it goes....

[EDIT] Sorry, just remembered you are using C++, not lite-c.
This comment may not be applicable...



Posted By: Anonymous2009

Re: Panel and Button - 04/12/09 12:41

Thanks, EvilSOB, will try that nevertheless.
Posted By: Anonymous2009

Re: Panel and Button - 04/13/09 04:08

EvilSOB > I can't use your method, it will say it "cannot convert from to BMAP*"

Anyway, my main problem is with the button, any other suggestion?
Posted By: EvilSOB

Re: Panel and Button - 04/13/09 04:51

This is largely educated guessing but try this.
WARNING - requires 7.71
Code:
BMAP  *resume0_bmp, *resume1_bmp;
PANEL *pause_pan;

void loadHUD()
{
   resume0_bmp = bmap_create("button_resumeOut.bmp");
   resume1_bmp = bmap_create("button_resumeOver.bmp");
   pause_pan = pan_create("bmap = screen_pause.tga;", _VAR(2));
   pause_pan->pos_x = _VAR(373);
   pause_pan->pos_y = _VAR(197);
   pause_pan->flags |= OVERLAY | TRANSLUCENT;
   pan_setbutton(pause_pan, _VAR(0), _VAR(2), _VAR(0), _VAR(0), resume0_bmp, resume0_bmp, resume1_bmp, resume1_bmp, NULL, NULL, NULL);
}



Posted By: Anonymous2009

Re: Panel and Button - 04/15/09 08:26

I didn't try upgrading my version because my friend managed to make it work, anyway, I can make the button show, but it is not responding to any of the mouse over/click...

PANEL* panel2 = pan_create("button_toggle(0, 0, red.bmp, green.bmp, blue.bmp, white.bmp, clickMe, leaveMe, overMe);", _VAR(999));

And the image of the button is always in green.bmp, which is the off state. The clickMe, leaveMe, overMe are just simple functions to do a cout message.

Do you see any mistake in that line?
Posted By: Olorin

Re: Panel and Button - 04/20/09 09:35

Hi. I had same problem. Try this code:

char *sStart_pan; // this is a pointer to char array with code of panel
ev = engine_open(NULL);

if (!ev) return 1; // acknex.dll not found

//folder with button images
add_folder("%EXE_DIR%\\DATA\\Btn\\");

...
//Allocation of memory
sStart_pan = new char[strlen("bmap = Start_pan.jpg;\
button (381, 229, btnStart_d.jpg, btnStart_u.jpg, btnStart_u.jpg, meth1, NULL, NULL);\
flags = OVERLAY;")];

//copy code of panel to char array
strcpy(sStart_pan,"bmap = Start_pan.jpg;\
button (381, 229, btnStart_d.jpg, btnStart_u.jpg, btnStart_u.jpg, meth1, NULL, NULL);\
flags = OVERLAY;");

//create a new panel
Start_pan = pan_create(sStart_pan,1);

// make it visible
Start_pan->flags|=VISIBLE;

// wait some frame for visualisation of panel
for (int i=0; i<3; i++) engine_frame();

It's working on my computer.
The buttons is shown and method "meth1" is working.
I'm using MS Visual Studio 2005 and A7 engine (version 7.06.1)

With best regards.
Posted By: Olorin

Re: Panel and Button - 04/20/09 10:38

And If you want to add Event on the button you should use
"pan_setevent" function

In my project (see example in previous post) i use this code:

pan_setevent(Start_pan,_VAR(3),_VAR(1),(EVENT)Change_Mode);
You can read more about this function in acknex help
© 2024 lite-C Forums