From: Rowin H. <row...@gm...> - 2006-03-31 11:32:48
|
Well I kind of forgot to paste the code as I promised :P so here is it // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++ Include VXL files +++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // #include <vgui/vgui.h> #include <vgui/vgui_projection_inspector.h> // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++ Include external files ++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // #include "Tgui_picker_tableau.h" // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++ Implementation ++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // vgui_picker_tableau::object_type vgui_picker_tableau::obj_type =3D none_enu= m; //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D //: Constructor, takes a child tableau. vgui_picker_tableau::vgui_picker_tableau(vgui_tableau_sptr const& t) :child_tab(this, t) { use_event_ =3D false; pointx =3D 0; pointy =3D 0; point_ret =3D true; } //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D //: Destructor. vgui_picker_tableau::~vgui_picker_tableau() { } //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D //: Gets a user selected point. // This function grabs the event loop and will not return until a // mouse down event occurs. // Returns true if this is done with the left mouse button, otherwise false. // The coordinates of the point are returned in the parameters. bool vgui_picker_tableau::pick_point(float* x, float* y) { obj_type =3D point_enum; picking_completed =3D false; //point_ret =3D true; vgui::flush(); // handle any pending events before we grab the event loop. // Grab event loop until picking is completed: while (picking_completed =3D=3D false) next(); *x =3D pointx; *y =3D pointy; obj_type =3D none_enum; // deselect all //deselect_all_highlighted_objects(); return point_ret; } //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D //: Handles all events for this tableau. // We grab events in this way rather than using a vgui_event_server becaus= e // if we look at events outside the handle function then the gl state // associated with those events will have changed. This means for a // draw_overlay event we would end up drawing into the wrong buffer. // For a mouse event we would not be able to get the position in the image // using the projection_inspector (if e.g. the image was zoomed) since all // the gl matrices would have been reset. bool vgui_picker_tableau::handle(const vgui_event& event) { use_event_ =3D true; //---- Object type is point ----- if (obj_type =3D=3D point_enum) { if (event.type =3D=3D vgui_BUTTON_DOWN && event.button =3D=3D vgui_LEFT= ) { vgui_projection_inspector p_insp; p_insp.window_to_image_coordinates(event.wx, event.wy, pointx, pointy); point_ret =3D true; picking_completed =3D true; return true; } if (event.type =3D=3D vgui_KEY_PRESS || event.type =3D=3D vgui_FOCUSLOS= T) { picking_completed =3D true; point_ret =3D false; //obj_type =3D none_enum; return true; } } // Pass events on down to the child tableaux: return child_tab->handle(event); } //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D //: Get next event in event loop bool vgui_picker_tableau::next() { use_event_ =3D false; while (!use_event_) vgui::run_one_event(); } -- Grtz Rowin Heymans |