Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Draging a panel? [Re: gfxExp] #294712
10/20/09 18:31
10/20/09 18:31
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
ok do it this way:

store the mouse position relative to the panel, ie lets say panel is at 120,120 of the screen and the mouse is at 125,140 at the moment of the panel is clicked.

then you get the diffrence on x and y, in our cas there is 5 diffrence on x and 20 diffrence on y.

store these on the variables like y_diff and x_diff and set this vars when the panels are clicked.

then change your panel's pos accordingly like

panel.pos_x = mouse_pos.x - x_diff;
panel.pos_y = mouse_pos.y - y_diff;

i guess i explained it in a little confusing way, if you dont understand what i am talking about, i can make a small example app.

aww rei replied before me and i did not saw that. and made an example:
Code:
BMAP* dummy_bmap = "#256x256x24";

void drag_me(PANEL* panel){
	var x_diff = mouse_pos.x - panel.pos_x;
	var y_diff = mouse_pos.y - panel.pos_y;
	while(mouse_left){
		panel.pos_x = mouse_pos.x - x_diff;
		panel.pos_y = mouse_pos.y - y_diff;
		wait(1);
	}
}

void drag_event(PANEL* panel){
	if(event_type == EVENT_CLICK){
		drag_me(panel);
	}
}
PANEL* draggable_panel = {
	bmap = dummy_bmap;
	event = drag_event;
	flags = SHOW;
}

void main(){
	mouse_mode = 4;
	vec_set(screen_color,vector(128,128,128));
}



code is standalone, it doesnt need any external images etc. just copy/paste and run.

edit2: rei also posted an example seconds before me >.<
anyway this gives you 2 examples grin

Last edited by Quadraxas; 10/20/09 18:42.

3333333333
Re: Draging a panel? [Re: Quad] #294716
10/20/09 18:41
10/20/09 18:41
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Here is you code:
Code:
PANEL* test_pan =
{
	bmap = "cool.bmp";
	layer = 5;
	flags = SHOW;
}

function drag()
{
	var diff_x, diff_y;
	while(1)
	{
		if((mouse_left)&&(mouse_pos.x >= test_pan.pos_x)&&(mouse_pos.x <= test_pan.pos_x+bmap_width(test_pan.bmap))&&(mouse_pos.y >= test_pan.pos_y)&&(mouse_pos.y <= test_pan.pos_x+bmap_height(test_pan.bmap)))
		{
			diff_x = mouse_pos.x - test_pan.pos_x;
			diff_y = mouse_pos.y - test_pan.pos_y;
			while(mouse_left)
			{
				test_pan.pos_x = mouse_pos.x - diff_x;
				test_pan.pos_y = mouse_pos.y - diff_y;
				wait(1);
			}
		}
		wait(1);
	}
}



And this in the main:
Code:
....
drag();
	while(1)
	{
		mouse_pos.x = mouse_cursor.x;
		mouse_pos.y = mouse_cursor.y;
		wait(1);
	}



Re: Draging a panel? [Re: Rei_Ayanami] #294722
10/20/09 19:23
10/20/09 19:23
Joined: Aug 2009
Posts: 46
gfxExp Offline OP
Newbie
gfxExp  Offline OP
Newbie

Joined: Aug 2009
Posts: 46
Thanks Quad and Rei! Works great! These examples also showed me how things can be done in different ways as well. laugh

Re: Draging a panel? [Re: gfxExp] #301166
12/08/09 17:28
12/08/09 17:28
Joined: Aug 2002
Posts: 164
Houston
Nicholas Offline
Member
Nicholas  Offline
Member

Joined: Aug 2002
Posts: 164
Houston
To add upon this idea, how would I keep the panel from being dragged out of a specific bounding box. ie. if windowed, I don't want to drag it off screen or up too high over my static menu at the top.
I've tried adding " && sender.pos_x <= 600" to the while mouse_left loop, but if I drag really fast it will go past the bounding box and have to snap back... doesn't look good, I need it to be smooth and just stop at the edge of the predefined area.


Black holes are where God divided by zero.
Page 3 of 3 1 2 3

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