From a7b6b646670fb928dacecc51505beb0a22e63855 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 10 Jan 2001 20:14:35 +0000 Subject: [PATCH] *** empty log message *** --- Fltk/Callbacks.cpp | 6 +- Fltk/Callbacks.h | 2 + Fltk/GUI.cpp | 363 ++++++++++++++++++++++++----------------- Fltk/GUI.h | 38 +++-- Fltk/Opengl.cpp | 16 +- Fltk/Opengl_Window.cpp | 226 ++++++++++++------------- Graphics/Mesh.cpp | 4 +- 7 files changed, 367 insertions(+), 288 deletions(-) diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 778cb5665b..f3784904fb 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.10 2001-01-10 12:12:18 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.11 2001-01-10 20:14:34 geuzaine Exp $ #include "Gmsh.h" #include "GmshUI.h" @@ -64,6 +64,10 @@ void CancelMeshThread(void){ } +int SetGlobalShortcut(int event){ + return WID->global_shortcuts(event); +} + // Common callbacks void cancel_cb(CALLBACK_ARGS){ diff --git a/Fltk/Callbacks.h b/Fltk/Callbacks.h index 0b779d30c8..15f5fce1cc 100644 --- a/Fltk/Callbacks.h +++ b/Fltk/Callbacks.h @@ -3,6 +3,8 @@ #define CALLBACK_ARGS Fl_Widget* w, void* data +int SetGlobalShortcut(int event); + // Common callbacks void cancel_cb(CALLBACK_ARGS) ; diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index a572f958a0..753163266a 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -27,7 +27,7 @@ Fl_Menu_Item m_menubar_table[] = { {"Merge...", FL_CTRL+'m', (Fl_Callback *)file_merge_cb, 0, FL_MENU_DIVIDER}, {"Save", FL_CTRL+'s', (Fl_Callback *)file_save_cb, 0}, {"Save As", 0, 0, 0, FL_MENU_DIVIDER|FL_SUBMENU}, - {"By extension...", 0, (Fl_Callback *)file_save_as_auto_cb, 0}, + {"By extension...", FL_CTRL+'p', (Fl_Callback *)file_save_as_auto_cb, 0}, {"GEO...", 0, (Fl_Callback *)file_save_as_geo_cb, 0}, {"GEO options...", 0, (Fl_Callback *)file_save_as_geo_options_cb, 0}, {"MSH...", 0, (Fl_Callback *)file_save_as_msh_cb, 0}, @@ -242,13 +242,26 @@ Context_Item menu_post[] = { { "2", NULL } , { NULL } }; -// The GUI constructor creates ONLY the widgets that always exist (we -// want the lowest memory footprint for the interface and the fastest -// startup time). All optional dialogs are also created only once, but -// on demand. +// Global shortcuts + +int GUI::global_shortcuts(int event){ + // we only handle shortcuts here + if(event != FL_SHORTCUT) return 0 ; + + // test... + if(Fl::test_shortcut(FL_CTRL+'z')){ + gen_butt[0]->do_callback(); + printf("CACACACAC\n"); + return 1; + } + + return 0; +} + + +// The GUI constructor GUI::GUI() { - int i, x, y; BH = 2*CTX.fontsize+2; // button height WB = CTX.fontsize-6; // window border width @@ -257,148 +270,25 @@ GUI::GUI() { if(strlen(CTX.display)) Fl::display(CTX.display); + Fl::add_handler(SetGlobalShortcut); + // Icons icon1_bmp = new Fl_Bitmap(g1_bits,g1_width,g1_height); icon2_bmp = new Fl_Bitmap(g2_bits,g2_width,g2_height); icon3_bmp = new Fl_Bitmap(g3_bits,g3_width,g3_height); - // Menu Window - - { - int width = 155 ; - MH = 2*BH+6 ; // this is the initial height: no dynamic button is shown! - - m_window = new Fl_Window(width,MH); - m_window->box(FL_THIN_UP_BOX); - m_window->label("Gmsh"); - - { - Fl_Menu_Bar *o = new Fl_Menu_Bar(0,0,width,BH); - o->menu(m_menubar_table); - o->global(); - o->textsize(CTX.fontsize); - o->box(FL_UP_BOX); - } - - Fl_Box *o = new Fl_Box(0,BH,width,BH+6); - o->box(FL_UP_BOX); - - y = BH + 3; - - m_navig_butt[0] = new Fl_Button(2,y,20,BH/2,"@<"); - m_navig_butt[0]->labeltype(FL_SYMBOL_LABEL); - m_navig_butt[0]->box(FL_FLAT_BOX); - m_navig_butt[0]->selection_color(FL_WHITE); - m_navig_butt[0]->callback(mod_back_cb); - m_navig_butt[1] = new Fl_Button(2,y+BH/2,20,BH/2,"@>"); - m_navig_butt[1]->labeltype(FL_SYMBOL_LABEL); - m_navig_butt[1]->box(FL_FLAT_BOX); - m_navig_butt[1]->selection_color(FL_WHITE); - m_navig_butt[1]->callback(mod_forward_cb); - - m_module_butt = new Fl_Choice(22,y,width-28,BH); - m_module_butt->menu(m_module_table); - m_module_butt->textsize(CTX.fontsize); - m_module_butt->box(FL_THIN_DOWN_BOX); - - y = MH ; - - for(i=0; i<NB_BUTT_MAX; i++){ - m_push_butt[i] = new Fl_Button(0,y+i*BH,width,BH); - m_push_butt[i]->labelsize(CTX.fontsize); - m_push_butt[i]->hide(); - m_toggle_butt[i] = new Fl_Light_Button(0,y+i*BH,width,BH); - m_toggle_butt[i]->labelsize(CTX.fontsize); - m_toggle_butt[i]->callback(view_toggle_cb, (void*)i); - m_toggle_butt[i]->hide(); - m_popup_butt[i] = new Fl_Menu_Button(0,y+i*BH,width,BH); - m_popup_butt[i]->type(Fl_Menu_Button::POPUP3); - m_popup_butt[i]->add("Reload", 0, - (Fl_Callback *)view_reload_cb, (void*)i, 0); - m_popup_butt[i]->add("Remove", 0, - (Fl_Callback *)view_remove_cb, (void*)i, 0); - m_popup_butt[i]->add("Duplicate", 0, - (Fl_Callback *)view_duplicate_cb, (void*)i, FL_MENU_DIVIDER) ; - m_popup_butt[i]->add("Lighting", 0, - (Fl_Callback *)view_lighting_cb, (void*)i, 0); - m_popup_butt[i]->add("Show Elements", 0, - (Fl_Callback *)view_elements_cb, (void*)i, 0); - m_popup_butt[i]->add("Apply as Background Mesh", 0, - (Fl_Callback *)view_applybgmesh_cb, (void*)i, FL_MENU_DIVIDER); - m_popup_butt[i]->add("Options...", 0, - (Fl_Callback *)view_options_cb, (void*)i, 0); - m_popup_butt[i]->textsize(CTX.fontsize); - m_popup_butt[i]->hide(); - } - - m_window->position(800,50); - m_window->end(); - m_window->show(); - - } - - // Graphic Window - - { - g_window = new Fl_Window(700,520); - g_opengl_window = new Opengl_Window(0,0,700,500); - - { - Fl_Group *o = new Fl_Group(0,500,700,20); - o->box(FL_THIN_UP_BOX); - - x = 2; - - g_status_butt[0] = new Fl_Button(x,502,15,16,"X"); x+=15; - g_status_butt[0]->callback(status_xyz1p_cb, (void*)0); - //g_status_butt[0]->tooltip("Set X view"); - g_status_butt[1] = new Fl_Button(x,502,15,16,"Y"); x+=15; - g_status_butt[1]->callback(status_xyz1p_cb, (void*)1); - g_status_butt[2] = new Fl_Button(x,502,15,16,"Z"); x+=15; - g_status_butt[2]->callback(status_xyz1p_cb, (void*)2); - g_status_butt[3] = new Fl_Button(x,502,20,16,"1:1"); x+=20; - g_status_butt[3]->callback(status_xyz1p_cb, (void*)3); - g_status_butt[4] = new Fl_Button(x,502,15,16,"?"); x+=15; - g_status_butt[4]->callback(status_xyz1p_cb, (void*)4); - - g_status_butt[5] = new Fl_Button(x,502,15,16); x+=15; - g_status_butt[5]->callback(status_play_cb); - start_bmp = new Fl_Bitmap(start_bits,start_width,start_height); - start_bmp->label(g_status_butt[5]); - stop_bmp = new Fl_Bitmap(stop_bits,stop_width,stop_height); - - g_status_butt[6] = new Fl_Button(x,502,15,16); x+=15; - g_status_butt[6]->callback(status_cancel_cb); - abort_bmp = new Fl_Bitmap(abort_bits,abort_width,abort_height); - abort_bmp->label(g_status_butt[6]); - g_status_butt[6]->deactivate(); - - for(i = 0 ; i<7 ; i++){ - g_status_butt[i]->box(FL_FLAT_BOX); - g_status_butt[i]->selection_color(FL_WHITE); - g_status_butt[i]->labelsize(CTX.fontsize); - g_status_butt[i]->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); - } - - g_status_label[0] = new Fl_Box(x,502,(700-x)/3,16); - g_status_label[1] = new Fl_Box(x+(700-x)/3,502,(700-x)/3,16); - g_status_label[2] = new Fl_Box(x+2*(700-x)/3,502,(700-x)/3-2,16); - for(i = 0 ; i<3 ; i++){ - g_status_label[i]->box(FL_FLAT_BOX); - g_status_label[i]->labelsize(CTX.fontsize); - g_status_label[i]->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); - } - - o->end(); - } - - g_window->resizable(g_opengl_window); - g_window->position(20,30); - g_window->end(); - g_window->show(); - - } + // All static windows are contructed (even if some are not + // displayed) since the shortcuts should be valid even for hidden + // windows + create_menu_window(); m_window->show(); + create_graphic_window(); g_window->show(); + create_general_options_window(); + create_geometry_options_window(); + create_mesh_options_window(); + create_post_options_window(); + create_help_window(); + create_about_window(); // Draw the actual scene @@ -492,19 +382,31 @@ void GUI::set_statistics(){ // set the current drawing context to the main opengl window -void GUI::make_gl_current(){ +void GUI::make_current(){ g_opengl_window->make_current(); } + +// set the current drawing context to the overlay opengl window + +void GUI::make_overlay_current(){ + g_opengl_window->make_overlay_current(); +} +// swap buffer + +void GUI::swap_buffers(){ + g_opengl_window->swap_buffers(); +} + // Draw the opengl window -void GUI::draw_gl(){ +void GUI::draw(){ g_opengl_window->redraw(); } // Draw the opengl overlay window -void GUI::draw_gl_overlay(){ +void GUI::draw_overlay(){ g_opengl_window->redraw_overlay(); } @@ -522,7 +424,7 @@ void GUI::check(){ // Set the size of the graphical window -void GUI::set_gl_size(int new_w, int new_h){ +void GUI::set_size(int new_w, int new_h){ g_window->size(new_w,new_h+g_window->h()-g_opengl_window->h()); } @@ -633,6 +535,169 @@ int GUI::get_context(){ return m_module_butt->value(); } + + + +// Create the menu window + +void GUI::create_menu_window(){ + static int init_menu_window = 0; + int i, y; + + if(!init_menu_window){ + init_menu_window = 1 ; + + int width = 155 ; + MH = 2*BH+6 ; // this is the initial height: no dynamic button is shown! + + m_window = new Fl_Window(width,MH); + m_window->box(FL_THIN_UP_BOX); + m_window->label("Gmsh"); + + m_menu_bar = new Fl_Menu_Bar(0,0,width,BH); + m_menu_bar->menu(m_menubar_table); + m_menu_bar->textsize(CTX.fontsize); + m_menu_bar->box(FL_UP_BOX); + m_menu_bar->global(); + + Fl_Box *o = new Fl_Box(0,BH,width,BH+6); + o->box(FL_UP_BOX); + + y = BH + 3; + + m_navig_butt[0] = new Fl_Button(2,y,20,BH/2,"@<"); + m_navig_butt[0]->labeltype(FL_SYMBOL_LABEL); + m_navig_butt[0]->box(FL_FLAT_BOX); + m_navig_butt[0]->selection_color(FL_WHITE); + m_navig_butt[0]->callback(mod_back_cb); + m_navig_butt[1] = new Fl_Button(2,y+BH/2,20,BH/2,"@>"); + m_navig_butt[1]->labeltype(FL_SYMBOL_LABEL); + m_navig_butt[1]->box(FL_FLAT_BOX); + m_navig_butt[1]->selection_color(FL_WHITE); + m_navig_butt[1]->callback(mod_forward_cb); + + m_module_butt = new Fl_Choice(22,y,width-28,BH); + m_module_butt->menu(m_module_table); + m_module_butt->textsize(CTX.fontsize); + m_module_butt->box(FL_THIN_DOWN_BOX); + + y = MH ; + + for(i=0; i<NB_BUTT_MAX; i++){ + m_push_butt[i] = new Fl_Button(0,y+i*BH,width,BH); + m_push_butt[i]->labelsize(CTX.fontsize); + m_push_butt[i]->hide(); + m_toggle_butt[i] = new Fl_Light_Button(0,y+i*BH,width,BH); + m_toggle_butt[i]->labelsize(CTX.fontsize); + m_toggle_butt[i]->callback(view_toggle_cb, (void*)i); + m_toggle_butt[i]->hide(); + m_popup_butt[i] = new Fl_Menu_Button(0,y+i*BH,width,BH); + m_popup_butt[i]->type(Fl_Menu_Button::POPUP3); + m_popup_butt[i]->add("Reload", 0, + (Fl_Callback *)view_reload_cb, (void*)i, 0); + m_popup_butt[i]->add("Remove", 0, + (Fl_Callback *)view_remove_cb, (void*)i, 0); + m_popup_butt[i]->add("Duplicate", 0, + (Fl_Callback *)view_duplicate_cb, (void*)i, FL_MENU_DIVIDER) ; + m_popup_butt[i]->add("Lighting", 0, + (Fl_Callback *)view_lighting_cb, (void*)i, 0); + m_popup_butt[i]->add("Show Elements", 0, + (Fl_Callback *)view_elements_cb, (void*)i, 0); + m_popup_butt[i]->add("Apply as Background Mesh", 0, + (Fl_Callback *)view_applybgmesh_cb, (void*)i, FL_MENU_DIVIDER); + m_popup_butt[i]->add("Options...", 0, + (Fl_Callback *)view_options_cb, (void*)i, 0); + m_popup_butt[i]->textsize(CTX.fontsize); + m_popup_butt[i]->hide(); + } + + m_window->position(800,50); + m_window->end(); + } + else{ + if(m_window->shown()) + m_window->redraw(); + else + m_window->show(); + + } +} + + +// Create the graphic window + +void GUI::create_graphic_window(){ + static int init_graphic_window = 0; + int i, x; + + if(!init_graphic_window){ + init_graphic_window = 1 ; + + g_window = new Fl_Window(700,520); + g_opengl_window = new Opengl_Window(0,0,700,500); + + { + Fl_Group *o = new Fl_Group(0,500,700,20); + o->box(FL_THIN_UP_BOX); + + x = 2; + + g_status_butt[0] = new Fl_Button(x,502,15,16,"X"); x+=15; + g_status_butt[0]->callback(status_xyz1p_cb, (void*)0); + //g_status_butt[0]->tooltip("Set X view"); + g_status_butt[1] = new Fl_Button(x,502,15,16,"Y"); x+=15; + g_status_butt[1]->callback(status_xyz1p_cb, (void*)1); + g_status_butt[2] = new Fl_Button(x,502,15,16,"Z"); x+=15; + g_status_butt[2]->callback(status_xyz1p_cb, (void*)2); + g_status_butt[3] = new Fl_Button(x,502,20,16,"1:1"); x+=20; + g_status_butt[3]->callback(status_xyz1p_cb, (void*)3); + g_status_butt[4] = new Fl_Button(x,502,15,16,"?"); x+=15; + g_status_butt[4]->callback(status_xyz1p_cb, (void*)4); + + g_status_butt[5] = new Fl_Button(x,502,15,16); x+=15; + g_status_butt[5]->callback(status_play_cb); + start_bmp = new Fl_Bitmap(start_bits,start_width,start_height); + start_bmp->label(g_status_butt[5]); + stop_bmp = new Fl_Bitmap(stop_bits,stop_width,stop_height); + + g_status_butt[6] = new Fl_Button(x,502,15,16); x+=15; + g_status_butt[6]->callback(status_cancel_cb); + abort_bmp = new Fl_Bitmap(abort_bits,abort_width,abort_height); + abort_bmp->label(g_status_butt[6]); + g_status_butt[6]->deactivate(); + + for(i = 0 ; i<7 ; i++){ + g_status_butt[i]->box(FL_FLAT_BOX); + g_status_butt[i]->selection_color(FL_WHITE); + g_status_butt[i]->labelsize(CTX.fontsize); + g_status_butt[i]->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); + } + + g_status_label[0] = new Fl_Box(x,502,(700-x)/3,16); + g_status_label[1] = new Fl_Box(x+(700-x)/3,502,(700-x)/3,16); + g_status_label[2] = new Fl_Box(x+2*(700-x)/3,502,(700-x)/3-2,16); + for(i = 0 ; i<3 ; i++){ + g_status_label[i]->box(FL_FLAT_BOX); + g_status_label[i]->labelsize(CTX.fontsize); + g_status_label[i]->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); + } + + o->end(); + } + + g_window->resizable(g_opengl_window); + g_window->position(20,30); + g_window->end(); + } + else{ + if(g_window->shown()) + g_window->redraw(); + else + g_window->show(); + + } +} + // Create the window for general options void GUI::create_general_options_window(){ @@ -753,7 +818,6 @@ void GUI::create_general_options_window(){ } gen_window->end(); - gen_window->show(); } else{ if(gen_window->shown()) @@ -856,7 +920,6 @@ void GUI::create_geometry_options_window(){ } geo_window->end(); - geo_window->show(); } else{ if(geo_window->shown()) @@ -1019,7 +1082,6 @@ void GUI::create_mesh_options_window(){ } mesh_window->end(); - mesh_window->show(); } else{ if(mesh_window->shown()) @@ -1098,7 +1160,6 @@ void GUI::create_post_options_window(){ } post_window->end(); - post_window->show(); } else{ if(post_window->shown()) @@ -1237,7 +1298,6 @@ void GUI::create_help_window(){ help_window->resizable(o); help_window->end(); - help_window->show(); } else{ if(help_window->shown()) @@ -1283,7 +1343,6 @@ void GUI::create_about_window(){ o2->callback(cancel_cb, (void*)about_window); about_window->end(); - about_window->show(); } else{ if(about_window->shown()) diff --git a/Fltk/GUI.h b/Fltk/GUI.h index dadfffe8ff..03bebc63a2 100644 --- a/Fltk/GUI.h +++ b/Fltk/GUI.h @@ -82,6 +82,7 @@ class GUI{ // menu window Fl_Window *m_window ; + Fl_Menu_Bar *m_menu_bar ; Fl_Choice *m_module_butt ; Fl_Button *m_navig_butt [2] ; Fl_Button *m_push_butt [NB_BUTT_MAX] ; @@ -147,13 +148,29 @@ public: // the constructor GUI(); + // create the windows + void create_menu_window(); + void create_graphic_window(); + void create_general_options_window(); + void create_geometry_options_window(); + void create_mesh_options_window(); + void create_post_options_window(); + void create_statistics_window(); + void create_view_window(int numview); + void create_help_window(); + void create_about_window(); + void create_geometry_context_window(int num); + void create_mesh_context_window(int num); + // general purpose interaction void run(); void check(); - void make_gl_current(); - void draw_gl(); - void draw_gl_overlay(); - void set_gl_size(int w, int h); + void make_current(); + void make_overlay_current(); + void swap_buffers(); + void draw(); + void draw_overlay(); + void set_size(int w, int h); void set_menu_size(int nb_butt); void set_context(Context_Item menu[], int flag); int get_context(); @@ -162,6 +179,8 @@ public: void set_statistics(); void set_title(char *str); void activate_custom(int val); + void add_handler(); + int global_shortcuts(int event); // geometry contexts queries char *get_geometry_parameter(int num); @@ -176,17 +195,6 @@ public: char *get_mesh_length(int num); char *get_mesh_attractor(int num); - // create additional windows - void create_general_options_window(); - void create_geometry_options_window(); - void create_mesh_options_window(); - void create_post_options_window(); - void create_statistics_window(); - void create_view_window(int numview); - void create_help_window(); - void create_about_window(); - void create_geometry_context_window(int num); - void create_mesh_context_window(int num); }; diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp index 5895cdef30..21adbaaa57 100644 --- a/Fltk/Opengl.cpp +++ b/Fltk/Opengl.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl.cpp,v 1.6 2001-01-10 10:06:38 geuzaine Exp $ +// $Id: Opengl.cpp,v 1.7 2001-01-10 20:14:34 geuzaine Exp $ #include "Gmsh.h" #include "GmshUI.h" @@ -25,18 +25,19 @@ void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2, /* ------------------------------------------------------------------------ */ void Init(void){ - WID->make_gl_current(); + //WID->make_current(); } void InitOverlay(void){ + WID->make_overlay_current(); } void Draw(void){ - WID->draw_gl(); + WID->draw(); } void DrawOverlay(void){ - WID->draw_gl_overlay(); + WID->draw_overlay(); } void DrawUI(void){ @@ -51,9 +52,10 @@ void Draw_String(char *s){ return ; } } - + /* glListBase(CTX.font_base); glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s); + */ } /* ------------------------------------------------------------------------ @@ -92,6 +94,8 @@ int check_type(int type, Vertex *v, Curve *c, Surface *s){ } int SelectEntity(int type, Vertex **v, Curve **c, Surface **s){ + return 0; + /* int hits; GLuint ii[SELECTION_BUFFER_SIZE],jj[SELECTION_BUFFER_SIZE]; int event; @@ -117,7 +121,7 @@ int SelectEntity(int type, Vertex **v, Curve **c, Surface **s){ } } } - + */ } diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp index 21b8aee157..b549a7987c 100644 --- a/Fltk/Opengl_Window.cpp +++ b/Fltk/Opengl_Window.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl_Window.cpp,v 1.2 2001-01-10 10:06:16 geuzaine Exp $ +// $Id: Opengl_Window.cpp,v 1.3 2001-01-10 20:14:34 geuzaine Exp $ #include "Gmsh.h" #include "GmshUI.h" @@ -36,14 +36,28 @@ void Opengl_Window::draw() { } if((w() != CTX.viewport[2]-CTX.viewport[0]) || (h() != CTX.viewport[3]-CTX.viewport[1])){ - WID->set_gl_size(CTX.viewport[2]-CTX.viewport[0], - CTX.viewport[3]-CTX.viewport[1]); + WID->set_size(CTX.viewport[2]-CTX.viewport[0], + CTX.viewport[3]-CTX.viewport[1]); glViewport(CTX.viewport[0], CTX.viewport[1], CTX.viewport[2], CTX.viewport[3]); } + Orthogonalize(0,0); + glClearColor(UNPACK_RED(CTX.color.bg)/255., + UNPACK_GREEN(CTX.color.bg)/255., + UNPACK_BLUE(CTX.color.bg)/255., + 0.); + glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); + Draw3d(); + Draw2d(); +} + +// one should not call Opengl_Window::draw() from the handle(), but +// rather the following: +void DrawUpdate(){ + WID->make_current(); Orthogonalize(0,0); glClearColor(UNPACK_RED(CTX.color.bg)/255., UNPACK_GREEN(CTX.color.bg)/255., @@ -52,6 +66,7 @@ void Opengl_Window::draw() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); Draw3d(); Draw2d(); + WID->swap_buffers(); } void Opengl_Window::clear_overlay() { @@ -123,6 +138,12 @@ void Opengl_Window::draw_overlay() { static int Modifier=0; +// le principe de FLTK est assez diffrent des autres toolkits: les +// events sont passes au handle du widget qui a le focus. Si ce handle +// revoie 1, alors l'event est considere comme traite, et est +// supprime. Si le handle retourne 0, l'event est passe au handle du +// parent. + int Opengl_Window::handle(int event) { GLuint ii[SELECTION_BUFFER_SIZE], jj[SELECTION_BUFFER_SIZE]; int previous_mesh_draw, previous_post_draw ; @@ -143,23 +164,7 @@ int Opengl_Window::handle(int event) { switch (event) { - /* ------------------------------------------------------------- - S h o r t c u t s - ------------------------------------------------------------- */ - - case FL_SHORTCUT: - /* - m = menu->test_shortcut(); - if (m) {m->do_callback(this, (void*)m); return 1;} - */ - return 0; - - /* ------------------------------------------------------------- - B u t t o n P r e s s - ------------------------------------------------------------- */ - case FL_PUSH: - ButtonPressed++; FirstClick=1; ibut = Fl::event_button(); @@ -191,8 +196,7 @@ int Opengl_Window::handle(int event) { Modifier = 0; set_s(1, CTX.s[0]); set_s(2, CTX.s[0]); - Init(); - Draw(); + DrawUpdate(); } else{ ZoomClick=0; @@ -210,8 +214,7 @@ int Opengl_Window::handle(int event) { } set_t(0,0.); set_t(1,0.); set_t(2,0.); set_s(0,1.); set_s(1,1.); set_s(2,1.); - Init(); - Draw(); + DrawUpdate(); } else{ ZoomClick=0; @@ -222,12 +225,7 @@ int Opengl_Window::handle(int event) { return 1; - /* ------------------------------------------------------------- - B u t t o n R e l e a s e - ------------------------------------------------------------- */ - case FL_RELEASE: - if(ButtonPressed>0){ ButtonPressed--; ibut = Fl::event_button(); @@ -235,26 +233,19 @@ int Opengl_Window::handle(int event) { y = Fl::event_y(); } if(!ZoomClick){ - Init(); previous_mesh_draw = CTX.mesh.draw ; previous_post_draw = CTX.post.draw ; if(ButtonPressed>0){ if(CTX.fast) CTX.mesh.draw = CTX.post.draw = 0; } - Draw(); + DrawUpdate(); CTX.mesh.draw = previous_mesh_draw ; CTX.post.draw = previous_post_draw ; } - return 1; - /* ------------------------------------------------------------- - M o t i o n N o t i f y - ------------------------------------------------------------- */ - case FL_DRAG: - movx = Fl::event_x()-x; movy = Fl::event_y()-y; @@ -270,88 +261,99 @@ int Opengl_Window::handle(int event) { draw_overlay(); } else { - if(ButtonPressed){ - - clear_overlay(); - - if(FirstClick){ - xc1 = ( ((GLdouble) x / width) * (CTX.vxmax - CTX.vxmin) - + CTX.vxmin )/CTX.s[0] - CTX.t[0]; - yc1 = ( CTX.vymax - ((GLdouble) y / height) * - (CTX.vymax - CTX.vymin))/CTX.s[1] - CTX.t[1]; - xt1 = CTX.t[0]; - yt1 = CTX.t[1]; - xscale1 = CTX.s[0]; - yscale1 = CTX.s[1]; - FirstClick=0; - } - - switch(ibut){ - case 1: - - if(CTX.useTrackball){ - CTX.addQuaternion ((2.0*x - width) / width, - (height - 2.0*y) / height, - (2.0*Fl::event_x() - width) / width, - (height - 2.0*Fl::event_y()) / height); - } - else{ - set_r(1, CTX.r[1] + ((abs(movx) > abs(movy))?180*(float)movx/(float)width:0)); - set_r(0, CTX.r[0] + ((abs(movx) > abs(movy))?0:180*(float)movy/(float)height)); - } - break; - case 2: - if(!CTX.useTrackball) - set_r(2, CTX.r[2] + ((abs(movy) > abs(movx))?0:-180*(float)movx/(float)width)); - - set_s(0, CTX.s[0] * ( (abs(movy) > abs(movx)) ? - ( (movy>0) ? (float)(1.04*(abs(movy)+height))/(float)height - : (float)(height)/(float)(1.04*(abs(movy)+height)) ) - : 1.) ); - set_s(1, CTX.s[0]); - set_s(2, CTX.s[0]); - - if(abs(movy) > abs(movx)){ - set_t(0, xt1*(xscale1/CTX.s[0])-xc1*(1.-(xscale1/CTX.s[0]))); - set_t(1, yt1*(yscale1/CTX.s[1])-yc1*(1.-(yscale1/CTX.s[1]))); - } - break; - case 3: - xc = ( ((GLdouble) x / width) * (CTX.vxmax - CTX.vxmin) + - CTX.vxmin ) / CTX.s[0]; - yc = ( CTX.vymax - ((GLdouble) y / height) * - (CTX.vymax - CTX.vymin)) / CTX.s[1]; - set_t(0, xc-xc1); - set_t(1, yc-yc1); - set_t(2, 0.); - break; - } - Init(); - previous_mesh_draw = CTX.mesh.draw ; - previous_post_draw = CTX.post.draw ; - if(CTX.fast) CTX.mesh.draw = CTX.post.draw = 0; - Draw(); - CTX.mesh.draw = previous_mesh_draw ; - CTX.post.draw = previous_post_draw ; + clear_overlay(); + + if(FirstClick){ + xc1 = ( ((GLdouble) x / width) * (CTX.vxmax - CTX.vxmin) + + CTX.vxmin )/CTX.s[0] - CTX.t[0]; + yc1 = ( CTX.vymax - ((GLdouble) y / height) * + (CTX.vymax - CTX.vymin))/CTX.s[1] - CTX.t[1]; + xt1 = CTX.t[0]; + yt1 = CTX.t[1]; + xscale1 = CTX.s[0]; + yscale1 = CTX.s[1]; + FirstClick=0; } - else{ - Process_SelectionBuffer(Fl::event_x(), Fl::event_y(), &hits, ii, jj); - ov = v; oc = c; os = s; - v = NULL; c = NULL; s = NULL; - Filter_SelectionBuffer(hits,ii,jj,&v,&c,&s,&M); - draw_overlay_highlight(); + + switch(ibut){ + case 1: + if(CTX.useTrackball){ + CTX.addQuaternion ((2.0*x - width) / width, + (height - 2.0*y) / height, + (2.0*Fl::event_x() - width) / width, + (height - 2.0*Fl::event_y()) / height); + } + else{ + set_r(1, CTX.r[1] + ((abs(movx) > abs(movy))?180*(float)movx/(float)width:0)); + set_r(0, CTX.r[0] + ((abs(movx) > abs(movy))?0:180*(float)movy/(float)height)); + } + break; + case 2: + if(!CTX.useTrackball) + set_r(2, CTX.r[2] + ((abs(movy) > abs(movx))?0:-180*(float)movx/(float)width)); + set_s(0, CTX.s[0] * ( (abs(movy) > abs(movx)) ? + ( (movy>0) ? (float)(1.04*(abs(movy)+height))/(float)height + : (float)(height)/(float)(1.04*(abs(movy)+height)) ) + : 1.) ); + set_s(1, CTX.s[0]); + set_s(2, CTX.s[0]); + if(abs(movy) > abs(movx)){ + set_t(0, xt1*(xscale1/CTX.s[0])-xc1*(1.-(xscale1/CTX.s[0]))); + set_t(1, yt1*(yscale1/CTX.s[1])-yc1*(1.-(yscale1/CTX.s[1]))); + } + break; + case 3: + xc = ( ((GLdouble) x / width) * (CTX.vxmax - CTX.vxmin) + + CTX.vxmin ) / CTX.s[0]; + yc = ( CTX.vymax - ((GLdouble) y / height) * + (CTX.vymax - CTX.vymin)) / CTX.s[1]; + set_t(0, xc-xc1); + set_t(1, yc-yc1); + set_t(2, 0.); + break; + } + previous_mesh_draw = CTX.mesh.draw ; + previous_post_draw = CTX.post.draw ; + if(CTX.fast){ + CTX.mesh.draw = 0 ; + CTX.post.draw = 0; } - x += movx; - y += movy; + DrawUpdate(); + CTX.mesh.draw = previous_mesh_draw ; + CTX.post.draw = previous_post_draw ; } - + x += movx; + y += movy; return 1; + - /* ------------------------------------------------------------- - O t h er - ------------------------------------------------------------- */ + case FL_MOVE: + movx = Fl::event_x()-x; + movy = Fl::event_y()-y; + Process_SelectionBuffer(Fl::event_x(), Fl::event_y(), &hits, ii, jj); + ov = v; oc = c; os = s; v = NULL; c = NULL; s = NULL; + Filter_SelectionBuffer(hits,ii,jj,&v,&c,&s,&M); +#if 0 + // l'overlay ne marche pas, meme dans les demos de fltk! + // soumettre un bug ? + if(ov != v || oc != c || os != s) { + WID->make_overlay_current(); + if(ov != v || oc != c || os != s) { + glClearIndex(0); + glClear(GL_COLOR_BUFFER_BIT); + glIndexi((CTX.color.bg<CTX.color.fg)?FL_WHITE:FL_BLACK); + BeginHighlight(); + HighlightEntity(v,c,s,0); + EndHighlight(0); + } + WID->make_current(); + } +#endif + x += movx; + y += movy; + return 1; - default: // pass other events to the base class... + default: return Fl_Gl_Window::handle(event); } diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp index b199479647..dd72adef74 100644 --- a/Graphics/Mesh.cpp +++ b/Graphics/Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Mesh.cpp,v 1.15 2001-01-09 14:24:09 geuzaine Exp $ +// $Id: Mesh.cpp,v 1.16 2001-01-10 20:14:35 geuzaine Exp $ #include "Gmsh.h" #include "GmshUI.h" @@ -112,7 +112,7 @@ void Draw_Mesh (Mesh *M) { if(CTX.render_mode != GMSH_SELECT){ if(CTX.axes) Draw_Axes(CTX.lc_middle/4.); - if(CTX.post.draw) /* les init de shading se font par view */ + if(CTX.post.draw) // les init de shading se font par view Draw_Post(); } } -- GitLab