Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011 #include "vgui_displaylist3D_tableau.h"
00012
00013 #include <vcl_iostream.h>
00014 #include <vcl_vector.h>
00015
00016 #include <vgui/vgui_gl.h>
00017 #include <vgui/vgui_glu.h>
00018 #include <vgui/vgui_event.h>
00019 #include <vgui/vgui_utils.h>
00020 #include <vgui/vgui_soview.h>
00021
00022 bool vgui_displaylist3D_tableau::handle(const vgui_event& e)
00023 {
00024 if (e.type == vgui_LEAVE)
00025 return true;
00026
00027 return vgui_displaybase_tableau::handle(e);
00028 }
00029
00030 void vgui_displaylist3D_tableau::get_hits(float x, float y, vcl_vector<unsigned>& my_hits)
00031 {
00032 GLuint *ptr = vgui_utils::enter_pick_mode(x,y,10.0,10.0);
00033
00034 this->gl_mode = GL_SELECT;
00035 this->handle(vgui_event(vgui_DRAW));
00036 this->gl_mode = GL_RENDER;
00037
00038 int num_hits = vgui_utils::leave_pick_mode();
00039
00040
00041 vcl_vector<vcl_vector<unsigned> > hits;
00042 vgui_utils::process_hits(num_hits, ptr, hits);
00043
00044
00045
00046
00047 for (vcl_vector<vcl_vector<unsigned> >::iterator i=hits.begin();
00048 i != hits.end(); ++i) {
00049 vcl_vector<unsigned> names = *i;
00050
00051 for (vcl_vector<unsigned>::iterator n_iter = names.begin();
00052 n_iter != names.end(); ++n_iter) {
00053 unsigned t_name = *n_iter;
00054
00055 for (vcl_vector<vgui_soview*>::iterator so_iter = this->objects.begin();
00056 so_iter != this->objects.end(); ++so_iter) {
00057 if ((*so_iter)->get_id() == t_name) {
00058 my_hits.push_back(t_name);
00059 break;
00060 }
00061 }
00062 }
00063 }
00064 }
00065
00066 bool vgui_displaylist3D_tableau::mouse_down(int x, int y, vgui_button button, vgui_modifier modifier)
00067 {
00068
00069 if (button == vgui_LEFT)
00070 {
00071 #ifdef DEBUG
00072 vcl_cerr << "selecting at " << x << ' ' << y << vcl_endl;
00073 #endif
00074 vcl_vector<unsigned> hits;
00075 get_hits(x,y,hits);
00076
00077 for (vcl_vector<unsigned>::iterator hi = hits.begin();
00078 hi != hits.end(); ++hi) {
00079 this->select(*hi);
00080 }
00081
00082 if (hits.size() > 0) {
00083 this->post_redraw();
00084 }
00085
00086 return true;
00087 }
00088
00089
00090 else if (button == vgui_MIDDLE)
00091 {
00092 if (modifier & vgui_SHIFT) {
00093 #ifdef DEBUG
00094 vcl_cerr << "deselecting all\n";
00095 #endif
00096 this->deselect_all();
00097 this->post_redraw();
00098 return false;
00099 }
00100
00101 #ifdef DEBUG
00102 vcl_cerr << "deselecting at " << x << ' ' << y << vcl_endl;
00103 #endif
00104
00105 vcl_vector<unsigned> hits;
00106 get_hits(x,y,hits);
00107
00108 for (vcl_vector<unsigned>::iterator hi = hits.begin();
00109 hi != hits.end(); ++hi) {
00110 this->deselect(*hi);
00111 }
00112
00113 if (hits.size() > 0) {
00114 this->post_redraw();
00115 }
00116
00117 return true;
00118 }
00119 return false;
00120 }
00121