From 258d80b726643098455c774f08a3ec96575780e3 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 9 Mar 2005 02:18:40 +0000 Subject: [PATCH] removed all unnecessary glPushMatrix/glPopMatrix calls --- Fltk/Callbacks.cpp | 29 +++++++++++++++++++++++------ Fltk/Opengl_Window.cpp | 9 +-------- Graphics/CreateFile.cpp | 17 +++++++++++++---- Graphics/Draw.cpp | 6 +----- Graphics/Draw.h | 1 + Graphics/Entity.cpp | 4 ++-- Graphics/Graph2D.cpp | 28 ++++++++++++++++++---------- 7 files changed, 59 insertions(+), 35 deletions(-) diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index eae0f74839..ea120c4693 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.337 2005-02-28 23:57:59 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.338 2005-03-09 02:18:40 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -3140,13 +3140,20 @@ void view_plugin_run_cb(CALLBACK_ARGS) } } -void view_plugin_input_cb(CALLBACK_ARGS) +void view_plugin_input_value_cb(CALLBACK_ARGS) { double (*f)(int, int, double) = (double (*)(int, int, double)) data; Fl_Value_Input *input = (Fl_Value_Input*) w; f(-1, 0, input->value()); } +void view_plugin_input_cb(CALLBACK_ARGS) +{ + char* (*f)(int, int, char*) = (char* (*)(int, int, char*)) data; + Fl_Input *input = (Fl_Input*) w; + f(-1, 0, (char*)input->value()); +} + void view_plugin_options_cb(CALLBACK_ARGS) { std::pair<int, GMSH_Plugin *> *pair = (std::pair<int, GMSH_Plugin *>*) data; @@ -3159,21 +3166,31 @@ void view_plugin_options_cb(CALLBACK_ARGS) p->dialogBox->current_view_index = iView; p->dialogBox->run_button->callback(view_plugin_run_cb, (void *)p); - // configure the input fields (we get step, min and max by calling - // the option function with action==1, 2 and 3, respectively) and - // set the Fl_Value_Input callbacks + // configure the input value fields (we get step, min and max by + // calling the option function with action==1, 2 and 3, + // respectively) and set the Fl_Value_Input callbacks int n = p->getNbOptions(); if(n > MAX_PLUGIN_OPTIONS) n = MAX_PLUGIN_OPTIONS; for(int i = 0; i < n; i++) { StringXNumber *sxn = p->getOption(i); if(sxn->function){ - p->dialogBox->value[i]->callback(view_plugin_input_cb, (void*)sxn->function); + p->dialogBox->value[i]->callback(view_plugin_input_value_cb, (void*)sxn->function); p->dialogBox->value[i]->step(sxn->function(iView, 1, 0.)); p->dialogBox->value[i]->minimum(sxn->function(iView, 2, 0.)); p->dialogBox->value[i]->maximum(sxn->function(iView, 3, 0.)); } } + // set the Fl_Input callbacks + int m = p->getNbOptionsStr(); + if(m > MAX_PLUGIN_OPTIONS) m = MAX_PLUGIN_OPTIONS; + for(int i = 0; i < m; i++) { + StringXString *sxs = p->getOptionStr(i); + if(sxs->function){ + p->dialogBox->input[i]->callback(view_plugin_input_cb, (void*)sxs->function); + } + } + p->dialogBox->main_window->show(); } diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp index 8317b654c7..27c9e5d8bb 100644 --- a/Fltk/Opengl_Window.cpp +++ b/Fltk/Opengl_Window.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl_Window.cpp,v 1.45 2005-01-01 19:35:28 geuzaine Exp $ +// $Id: Opengl_Window.cpp,v 1.46 2005-03-09 02:18:40 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -77,14 +77,11 @@ void Opengl_Window::draw() Draw2d(); } else { - glPopMatrix(); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); - glPushMatrix(); glLoadIdentity(); gluOrtho2D(CTX.vxmin, CTX.vxmax, CTX.vymin, CTX.vymax); glMatrixMode(GL_MODELVIEW); - glPushMatrix(); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glColor3f(1., 1., 1.); @@ -111,10 +108,6 @@ void Opengl_Window::draw() glEnd(); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); ZoomMode = false; } locked = 0; diff --git a/Graphics/CreateFile.cpp b/Graphics/CreateFile.cpp index 3bc042142a..1ff6c80c89 100644 --- a/Graphics/CreateFile.cpp +++ b/Graphics/CreateFile.cpp @@ -1,4 +1,4 @@ -// $Id: CreateFile.cpp,v 1.67 2005-02-28 23:57:59 geuzaine Exp $ +// $Id: CreateFile.cpp,v 1.68 2005-03-09 02:18:40 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -241,12 +241,21 @@ void CreateOutputFile(char *name, int format) psformat, pssort, psoptions, GL_RGBA, 0, NULL, 15, 20, 10, size3d, fp, name); if(CTX.print.eps_quality == 0){ + double modelview[16], projection[16]; + glGetDoublev(GL_PROJECTION_MATRIX, projection); + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glPushMatrix(); - glRasterPos2d(-1., -1.); + glOrtho((double)CTX.viewport[0], (double)CTX.viewport[2], + (double)CTX.viewport[1], (double)CTX.viewport[3], -1., 1.); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glRasterPos2d(0, 0); gl2psDrawPixels(width, height, 0, 0, GL_RGB, GL_FLOAT, pixels); - glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glLoadMatrixd(projection); + glMatrixMode(GL_MODELVIEW); + glLoadMatrixd(modelview); delete [] pixels; } else{ diff --git a/Graphics/Draw.cpp b/Graphics/Draw.cpp index 8dbd959a7e..1e1e0722b8 100644 --- a/Graphics/Draw.cpp +++ b/Graphics/Draw.cpp @@ -1,4 +1,4 @@ -// $Id: Draw.cpp,v 1.72 2005-01-01 19:35:29 geuzaine Exp $ +// $Id: Draw.cpp,v 1.73 2005-03-09 02:18:40 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -77,9 +77,7 @@ void Draw3d(void) InitRenderModel(); - glPushMatrix(); Draw_Mesh(&M); - glPopMatrix(); } void Draw2d(void) @@ -96,7 +94,6 @@ void Draw2d(void) glTranslated(0., 0., CTX.clip_factor > 1. ? 1./CTX.clip_factor : CTX.clip_factor); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glPushMatrix(); Draw_Graph2D(); Draw_Text2D(); Draw_OnScreenMessages(); @@ -104,7 +101,6 @@ void Draw2d(void) Draw_Scales(); if(CTX.small_axes) Draw_SmallAxes(); - glPopMatrix(); } void DrawPlugin(void (*draw)(void)) diff --git a/Graphics/Draw.h b/Graphics/Draw.h index dcf547a651..d1643003c1 100644 --- a/Graphics/Draw.h +++ b/Graphics/Draw.h @@ -68,6 +68,7 @@ void Draw_Post(void); void Draw_Graph2D(void); void Draw_Text2D(void); void Draw_Text2D3D(int dim, int timestep, int nb, List_T *td, List_T *tc); +void FixText2DCoordinates(double *x, double *y); void Draw_OnScreenMessages(void); void Draw_Scales(void); void Draw_Axes(double s); diff --git a/Graphics/Entity.cpp b/Graphics/Entity.cpp index 2227ff34da..ca4ce8725f 100644 --- a/Graphics/Entity.cpp +++ b/Graphics/Entity.cpp @@ -1,4 +1,4 @@ -// $Id: Entity.cpp,v 1.53 2005-01-21 22:54:04 geuzaine Exp $ +// $Id: Entity.cpp,v 1.54 2005-03-09 02:18:40 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -135,7 +135,7 @@ void Draw_Sphere(double size, double x, double y, double z, int light) if(light) glEnable(GL_LIGHTING); static GLUquadricObj *qua; static int first = 1, listnum; - double s = size * CTX.pixel_equiv_x / CTX.s[0]; // size is in pixels + double s = size * CTX.pixel_equiv_x / CTX.s[0]; // size is in pixels if(first) { first = 0; qua = gluNewQuadric(); diff --git a/Graphics/Graph2D.cpp b/Graphics/Graph2D.cpp index 9ee29889e4..9c5211f637 100644 --- a/Graphics/Graph2D.cpp +++ b/Graphics/Graph2D.cpp @@ -1,4 +1,4 @@ -// $Id: Graph2D.cpp,v 1.45 2005-01-18 06:22:03 geuzaine Exp $ +// $Id: Graph2D.cpp,v 1.46 2005-03-09 02:18:40 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -421,6 +421,21 @@ void Draw_Graph2D(void) // Text strings +void FixText2DCoordinates(double *x, double *y) +{ + if(*x < 0) // measure from right border + *x = CTX.viewport[2] + *x; + else if(*x > 99999) // by convention, x-centered + *x = CTX.viewport[2]/2; + + if(*y < 0) // measure from bottom border + *y = -(*y); + else if(*y > 99999) // by convention, y-centered + *y = CTX.viewport[3]/2.; + else + *y = CTX.viewport[3] - *y; +} + // Parser format: T2(x,y,style){"str","str",...}; // T2D list of double : x,y,style,index,x,y,style,index,... // T2C list of chars : string\0,string\0,string\0,string\0,... @@ -460,16 +475,9 @@ void Draw_Text2D3D(int dim, int timestep, int nb, List_T * td, List_T * tc) d2 = (double *)List_Pointer_Test(td, (j + 1) * nbd); if(dim == 2) { x = d1[0]; - if(x < 0) // measure from right border - x = CTX.viewport[2] + x; - else if(x > 99999) // by convention, x-centered - x = CTX.viewport[2]/2; - y = CTX.viewport[3] - d1[1]; - if(d1[1] < 0) // measure from bottom border - y = -d1[1]; - else if(d1[1] > 99999) // by convention, y-centered - y = CTX.viewport[3]/2.; + y = d1[1]; z = 0.; + FixText2DCoordinates(&x, &y); style = d1[2]; index = (int)d1[3]; if(d2) -- GitLab