Posted By: gfxExp
Draging a panel? - 10/18/09 18:49
Hi,
I experimented a bit with no results. How do I drag a panel with mouse?
I experimented a bit with no results. How do I drag a panel with mouse?
void dragPanel(PANEL *clickedPan) { while(mouse_left == 1) { //dragging the panel while holding the mousebutton clickedPan.pos_x = mouse_pos.x clickedPan.pos_y = mouse_pos.y wait(1); } } PANEL *some_pan = { pos_x = 0; pos_y = 0; bmap = XYZ; flags = SHOW; event = dragPanel; }
PANEL* some_pan = { bmap = "panel.tga"; // panel background pos_x = 10; // horizontal margin from screen top left pos_y = 10; // vertical margin from screen top left hslider (x, y, width, "knob.tga", min, max, variable); // here x and y are the horizontal and vertical margin from panel top left button (x, y, "clicked.tga", "normal.tga", "mouse_over.tga", Click_function, normal_function, mouse_over_function); // x and y same as slider, and "normal" function can be used for "on mouse out" functions. Functions can be left as NULL if you don't want to use any. flags = VISIBLE; }
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)); }
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); } }
.... drag(); while(1) { mouse_pos.x = mouse_cursor.x; mouse_pos.y = mouse_cursor.y; wait(1); }