Moving Panels together

Posted By: Aku_Aku

Moving Panels together - 07/16/20 15:53

I would like to move more than one (2 or 3 or 14 or 35 or 42 or more...) panels together, at once. If it is possible...
I have an idea, I think that would work, but... What would be the most appropriate method to do it?
Thanks in advance.
Posted By: Superku

Re: Moving Panels together - 08/02/20 09:46

Save a difference vector = panel pos - mouse_pos on left mouse clicks, set panel to (new) mouse_pos + difference vector.
This could either be saved in panel skills or in a helper struct which you access via some panel ID.
Posted By: Aku_Aku

Re: Moving Panels together - 08/02/20 19:41

Yeah I am using the same algorithm for moving one panel. I am just curious how should do it with perhaps four panels.
Moving the rest three panels is the exciting part. One method is modifying their position in the first panel mover function.
Is there another method under the sun?

I did not know the panels have skills. Can I refer to them like this? mypanel.skill[42]
How many skills do they have? What kind of data can be stored in one skill?
Maybe, somehow I overlooked this information in the manual.
Posted By: Emre

Re: Moving Panels together - 08/02/20 23:08

Originally Posted by Aku_Aku
I did not know the panels have skills. Can I refer to them like this? mypanel.skill[42]
How many skills do they have? What kind of data can be stored in one skill?
Maybe, somehow I overlooked this information in the manual.


You should take a look at "atypes.h" All structures are in that file.

[Linked Image]
Posted By: Superku

Re: Moving Panels together - 08/02/20 23:09

Go to your Gamestudio installation folder, then open the "include" subfolder. Among others you'll find atypes.h in there. You might have seen and looked into it before but still, check it out. There's the PANEL definition inside:
Code
typedef struct PANEL {
	C_LINK link;
	long	type;		// internal use only
	var	layer;		// layer number (read only)
	var	pos_x,pos_y;	// screen position in pixels
	long	flags;		// 
	var	alpha;		// transparency factor
	BMAP	*bmap;		// background bitmap
	var	scale_x,scale_y;
	var	blue,green,red;	// color for background and Truetype fonts
	var	size_x,size_y;	// panel dimension
	var	angle;			// rotation angle (6.5 or above)
	var	center_x,center_y;	// rotation center
	BMAP	*mouse_map;
	BMAP	*target_map;
	EVENT	event;		// panel function, executed on mouse click
	var   skill_x,skill_y; // general purpose variables
	byte  pad[PAD_PANEL];
} PANEL;


You can use skill_x/y freely. center_x/y might be usable (in a hacky way sort of) as well, never tried it.
If you've got the code to move one panel you have it to move them all. You need to know beforehand which panels to move of course.
What about something like this (needs more stuff to work but you get the idea):

Code
typedef struct
{
	PANEL* pnl;
	int isSelected;
	var diffX, diffY;
} PANEL_EXTENDED;
#define PANELS_EXTENDED_MAX 8
PANEL_EXTENDED panelsExtended[PANELS_EXTENDED_MAX];

void panelsExtendedInit()
{
	panelsExtended[0].pnl = myPanel1;
	panelsExtended[0].isSelected = 1;
	
	panelsExtended[1].pnl = myPanel2;
	
	panelsExtended[2].pnl = myPanel3;
	panelsExtended[2].isSelected = 1;
}

void panelsExtendedSetDiffs() // call this on left mouse presses (once, like on_mouse_left)
{
	int i;
	for(i = 0; i < PANELS_EXTENDED_MAX; i++)
	{
		PANEL_EXTENDED *pnlExtended = &panelsExtended[i];
		PANEL* pnl = pnlExtended.pnl;
		if(pnl != NULL && pnlExtended.isSelected)
		{
			pnlExtended.diffX = pnl.pos_x - mouse_pos.x;
			pnlExtended.diffY = pnl.pos_y - mouse_pos.y;
		}
	}	
}

void panelsExtendedMove()
{
	int i;
	for(i = 0; i < PANELS_EXTENDED_MAX; i++)
	{
		PANEL_EXTENDED *pnlExtended = &panelsExtended[i];
		PANEL* pnl = pnlExtended.pnl;
		if(pnl != NULL && pnlExtended.isSelected)
		{
			pnl.pos_x = mouse_pos.x + pnlExtended.diffX;
			pnl.pos_y = mouse_pos.y + pnlExtended.diffY;
		}
	}
}

Posted By: Aku_Aku

Re: Moving Panels together - 08/03/20 12:22

Thanks for Emre and Superku for pointing out the atypes.h. Yesterday I had the idea, should peek into that file, that should be worthy. You two made it sure.
Special thanks for Superku for the idea supported by example code. I was suspected something like this. But the code is nice to see.
Thanks again for you. This community is great.
© 2024 lite-C Forums