Originally Posted By: Schubido
Hi,

I had a similar problem doing a while(...) {... wait(1) ...} within an entity event. It seemed that it ran just for one frame. The manual says that you should not use wait(1) in entity events - maybe thats also true for panel events.
So maybe it could help to do the panel movement in a seperate function and just set a trigger in the panel event. Something like ...

Code:
var popupboxDrag = 0;

function popupbox_click_event();
PANEL* popupbox = 
{
	bmap = popupbox_map;
	layer = 4;
	event = popupbox_click_event;
}

function popupbox_click_event()
{
	popupboxDrag = 1
}

function popupboxAction()
{
  while(1)
  {
    if(popupboxDrag)
    {
        popupboxDrag = 0;
	while(mouse_left)
	{
		popupbox.pos_x += mickey.x;
		popupbox.pos_y += mickey.y;
		wait(1);
	}
    }
    wait(1);
  }
}

main()
{

  ...
  popupboxAction();
  ...

}


as GorNaKosh said you shouldn't be using += for the position.

Though neither of you take account for moving it from where is was click and always aligning directly to the mouse position.

Try this. It uses a button rather than giving the whole panel the click event, just change it as required.
Code:
#include <acknex.h>
#include <default.c>

PANEL* pnl_dummy;

void move_panel(var id, PANEL* pnl){
	
	int x = mouse_pos.x - pnl.pos_x;
	int y = mouse_pos.y - pnl.pos_y;
	
	while(mouse_left){
		pnl.pos_x = mouse_pos.x - x;
		pnl.pos_y = mouse_pos.y - y;
		wait(1);
	}
}

void main(){
	
	mouse_mode = 4;
	wait(1);
	
	pnl_dummy = pan_create("", 1);
	pnl_dummy.bmap = bmap_createblack(100, 60, 32);
	bmap_fill(pnl_dummy.bmap, COLOR_GREEN, 100);
	set(pnl_dummy, SHOW);

	BMAP* bmp_moveBtn = bmap_createblack(100, 10, 32);
	bmap_fill(bmp_moveBtn, COLOR_RED, 100);
	
	pan_setbutton(pnl_dummy, 0, 0, 0, 0, bmp_moveBtn, bmp_moveBtn, bmp_moveBtn, bmp_moveBtn, move_panel, NULL, NULL);
}