panel on_click problem

Posted By: Jaxas

panel on_click problem - 01/22/09 23:41

I can't handle panel on_click function. Here's an example:


////////////////////////////////////////
PANEL* test =
{
pos_x = 100;
pos_y = 100;
layer = 1;
bmap = panel_bmp;
flags = OVERLAY | VISIBLE;
on_click = mouse_use;
}

function mouse_use(panel)
{
test.pos_x = mouse_cursor.x;
test.pos_y = mouse_cursor.y;
}
////////////////////////////////////////////

On_click function doesn't call mouse_use() function. I work with A7.
Posted By: Ottawa

Re: panel on_click problem - 01/22/09 23:51

Hi!
Remove :
on_click = mouse_use;
from the PANEL* test
Place this line in a function
like main under a while loop
Now if you want to click on something look for examples of buttons in manual.

This will get you started smile

Ottawa
Posted By: Jaxas

Re: panel on_click problem - 01/23/09 00:09

you see,there are 2 on_click functions,one which used for panels, and second for view. Like you said, to use not in panel, but then on_click will afect view. In Aum48 is morrowing example(Link, direct to code snippets),and inventory.wdl, i tried to do the same thing,but it don't work. I can't understand where's the problem.
Posted By: Ottawa

Re: panel on_click problem - 01/23/09 00:17

Hi Jaxas smile

In a panel definition there are certain codes that you can and
cannot use. Your line "on_click..." should not be there.
I don't know the example your using.
You can place buttons in the panel. You will be
able to clic on these buttons with the mouse and the things that you
have put in a function will be done.

Hope this helps.
Posted By: Jaxas

Re: panel on_click problem - 01/23/09 00:32

but how else i know i'm clicking on panel or not? Here's an example from GameStudio manual:

/////////////////////////////////////////////////////////////

panel.on_click
Instead of the 'global' ON_CLICK function, this given function is performed by left clicking with the mouse pointer anywhere within the panel bitmap, as long as no panel element (like a button) is hit. The panel pointer is passed as optional parameter to the function and can be used for determining which panel was clicked on.
Example:

function redblue(panel); //prototype

PANEL* redpan = { x = 10; y = 20; bmap = redmap; on_click = redblue; }
PANEL* bluepan = { x = 10; y = 40; bmap = bluemap; on_click = redblue; }

function redblue(panel)
{
if (panel == redpan) { print("redpan clicked!"); }
if (panel == bluepan) { print("bluepan clicked!"); }
}

///////////////////////////////////////////////

As you can see,functio on_click are used in panel wink
Posted By: flits

Re: panel on_click problem - 01/23/09 10:55

first its a event = mouse_use;

second its mouse_use(PANEL* pan)

on_lick and panel is c_script
Posted By: Cowabanga

Re: panel on_click problem - 01/23/09 11:07

Code:
PANEL* test = 
{
	pos_x = 100;
	pos_y = 100;
	layer = 1;
	bmap = panel_bmp;
	flags = OVERLAY | VISIBLE;
	event = mouse_use;
}

function mouse_use()
{
	if(mouse_left == 1)
	{
		test.pos_x = mouse_cursor.x;
		test.pos_y = mouse_cursor.y;
	}
}


This will work! smile
Posted By: Ottawa

Re: panel on_click problem - 01/23/09 14:58

Hi!

I've gone back to the manual and checked for on_click
On_click is an event as was said by Cowabanga

The manual says
Quote:
The on_click function is executed when clicking left with the mouse pointer somewhere
within a VIEW, without hitting any object or panel.


and when clicking in a view an event is activated.
This situation can also be used in panels, which is what your trying to do but there is a difference

Quote:
This function is triggered by left clicking with the mouse pointer anywhere
within the panel bitmap, as long as no panel element (like a button) is hit.


Look up in the index --- event (panel) for the Light-C correct syntax.


On_click in an event but in panel you use the word event.

Hope this is helpfull

Ottawa smile
Posted By: Jaxas

Re: panel on_click problem - 01/23/09 16:34

Solved problem. I set mouse_map to bmap, and on_click work now. Thanks for helping all wink
© 2024 lite-C Forums