diff --git a/Fltk/Draw.cpp b/Fltk/Draw.cpp index c4a3070193593880cce8125404de132515c66c18..d5c5fdf5a06fab2144d7549a4d334ec502abebf2 100644 --- a/Fltk/Draw.cpp +++ b/Fltk/Draw.cpp @@ -3,6 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. +#include <string.h> #include <FL/gl.h> //FIXME: workaround faulty fltk installs @@ -15,7 +16,9 @@ #include "GUI.h" #include "graphicWindow.h" +#include "optionWindow.h" #include "GmshDefines.h" +#include "GmshMessage.h" #include "Draw.h" #include "StringUtils.h" #include "gl2ps.h" @@ -74,130 +77,93 @@ void DrawPlugin(void (*draw)(void *context)) CTX.mesh.draw = 1; } -void Draw_String(std::string s, const char *font_name, int font_enum, - int font_size, int align) +void GetStoredViewport(int viewport[4], int index) { - if(CTX.printing && !CTX.print.text) return; - - // change the raster position only if not creating TeX files - if(align > 0 && (!CTX.printing || CTX.print.format != FORMAT_TEX)){ - GLboolean valid; - glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); - if(valid == GL_TRUE){ - GLdouble pos[4]; - glGetDoublev(GL_CURRENT_RASTER_POSITION, pos); - double x[3], w[3] = {pos[0], pos[1], pos[2]}; - gl_font(font_enum, font_size); - float width = gl_width(s.c_str()); - float height = gl_height(); - switch(align){ - case 1: w[0] -= width/2.; break; // bottom center - case 2: w[0] -= width; break; // bottom right - case 3: w[1] -= height; break; // top left - case 4: w[0] -= width/2.; w[1] -= height; break; // top center - case 5: w[0] -= width; w[1] -= height; break; // top right - case 6: w[1] -= height/2.; break; // center left - case 7: w[0] -= width/2.; w[1] -= height/2.; break; // center center - case 8: w[0] -= width; w[1] -= height/2.; break; // center right - default: break; - } - Viewport2World(w, x); - glRasterPos3d(x[0], x[1], x[2]); - } - } - - if(!CTX.printing){ - gl_font(font_enum, font_size); - gl_draw(s.c_str()); - } - else{ - if(CTX.print.format == FORMAT_TEX){ - std::string tmp = SanitizeTeXString(s.c_str(), CTX.print.tex_as_equation); - int opt; - switch(align){ - case 1: opt = GL2PS_TEXT_B; break; // bottom center - case 2: opt = GL2PS_TEXT_BR; break; // bottom right - case 3: opt = GL2PS_TEXT_TL; break; // top left - case 4: opt = GL2PS_TEXT_T; break; // top center - case 5: opt = GL2PS_TEXT_TR; break; // top right - case 6: opt = GL2PS_TEXT_CL; break; // center left - case 7: opt = GL2PS_TEXT_C; break; // center center - case 8: opt = GL2PS_TEXT_CR; break; // center right - default: opt = GL2PS_TEXT_BL; break; // bottom left - } - gl2psTextOpt(tmp.c_str(), font_name, font_size, opt, 0.); - } - else if(CTX.print.eps_quality && (CTX.print.format == FORMAT_PS || - CTX.print.format == FORMAT_EPS || - CTX.print.format == FORMAT_PDF || - CTX.print.format == FORMAT_SVG)){ - gl2psText(s.c_str(), font_name, font_size); - } - else{ - gl_font(font_enum, font_size); - gl_draw(s.c_str()); - } + if(!GUI::available()) return; + if(index >= 0 && index < GUI::instance()->graph.size()){ + for(int i = 0; i < 4; i++) + viewport[i] = GUI::instance()->graph[index]->gl->getDrawContext()->viewport[i]; } } -void Draw_String(std::string s) +int GetFontIndex(const char *fontname) { - Draw_String(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 0); + if(fontname){ + for(int i = 0; i < NUM_FONTS; i++) + if(!strcmp(menu_font_names[i].label(), fontname)) + return i; + } + Msg::Error("Unknown font \"%s\" (using \"Helvetica\" instead)", fontname); + Msg::Info("Available fonts:"); + for(int i = 0; i < NUM_FONTS; i++) + Msg::Info(" \"%s\"", menu_font_names[i].label()); + return 4; } -void Draw_String_Center(std::string s) +int GetFontEnum(int index) { - Draw_String(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 1); + if(index >= 0 && index < NUM_FONTS) + return (long)menu_font_names[index].user_data(); + return FL_HELVETICA; } -void Draw_String_Right(std::string s) +const char *GetFontName(int index) { - Draw_String(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 2); + if(index >= 0 && index < NUM_FONTS) + return menu_font_names[index].label(); + return "Helvetica"; } -void Draw_String(std::string s, double style) +int GetFontAlign(const char *alignstr) { - unsigned int bits = (unsigned int)style; - - if(!bits){ // use defaults - Draw_String(s); - } - else{ - int size = (bits & 0xff); - int font = (bits>>8 & 0xff); - int align = (bits>>16 & 0xff); - int font_enum = GetFontEnum(font); - const char *font_name = GetFontName(font); - if(!size) size = CTX.gl_fontsize; - Draw_String(s, font_name, font_enum, size, align); + if(alignstr){ + if(!strcmp(alignstr, "BottomLeft") || !strcmp(alignstr, "Left") || + !strcmp(alignstr, "left")) + return 0; + else if(!strcmp(alignstr, "BottomCenter") || !strcmp(alignstr, "Center") || + !strcmp(alignstr, "center")) + return 1; + else if(!strcmp(alignstr, "BottomRight") || !strcmp(alignstr, "Right") || + !strcmp(alignstr, "right")) + return 2; + else if(!strcmp(alignstr, "TopLeft")) + return 3; + else if(!strcmp(alignstr, "TopCenter")) + return 4; + else if(!strcmp(alignstr, "TopRight")) + return 5; + else if(!strcmp(alignstr, "CenterLeft")) + return 6; + else if(!strcmp(alignstr, "CenterCenter")) + return 7; + else if(!strcmp(alignstr, "CenterRight")) + return 8; } + Msg::Error("Unknown font alignment \"%s\" (using \"Left\" instead)", alignstr); + Msg::Info("Available font alignments:"); + Msg::Info(" \"Left\" (or \"BottomLeft\")"); + Msg::Info(" \"Center\" (or \"BottomCenter\")"); + Msg::Info(" \"Right\" (or \"BottomRight\")"); + Msg::Info(" \"TopLeft\""); + Msg::Info(" \"TopCenter\""); + Msg::Info(" \"TopRight\""); + Msg::Info(" \"CenterLeft\""); + Msg::Info(" \"CenterCenter\""); + Msg::Info(" \"CenterRight\""); + return 0; } -void GetStoredViewport(int viewport[4], int index) +int GetFontSize() { - if(!GUI::available()) return; - if(index >= 0 && index < GUI::instance()->graph.size()){ - for(int i = 0; i < 4; i++) - viewport[i] = GUI::instance()->graph[index]->gl->getDrawContext()->viewport[i]; + if(CTX.fontsize > 0){ + return CTX.fontsize; + } + else{ + int w = Fl::w(); + if(w <= 1024) return 11; + else if(w <= 1280) return 12; + else if(w <= 1680) return 13; + else if(w <= 1920) return 14; + else return 15; } -} - -void Viewport2World(double win[3], double xyz[3]) -{ - GLint viewport[4]; - GLdouble model[16], proj[16]; - glGetIntegerv(GL_VIEWPORT, viewport); - glGetDoublev(GL_PROJECTION_MATRIX, proj); - glGetDoublev(GL_MODELVIEW_MATRIX, model); - gluUnProject(win[0], win[1], win[2], model, proj, viewport, &xyz[0], &xyz[1], &xyz[2]); -} - -void World2Viewport(double xyz[3], double win[3]) -{ - GLint viewport[4]; - GLdouble model[16], proj[16]; - glGetIntegerv(GL_VIEWPORT, viewport); - glGetDoublev(GL_PROJECTION_MATRIX, proj); - glGetDoublev(GL_MODELVIEW_MATRIX, model); - gluProject(xyz[0], xyz[1], xyz[2], model, proj, viewport, &win[0], &win[1], &win[2]); } diff --git a/Fltk/Draw.h b/Fltk/Draw.h index 1e171a44fae1dcdce87ff981d1eb27b0ba397266..15898d6fe5173eef447375aad1f8927b91161bd6 100644 --- a/Fltk/Draw.h +++ b/Fltk/Draw.h @@ -10,18 +10,15 @@ void SetOpenglContext(int index=0); void ClearOpengl(); - void Draw(); void Draw2d3d(int index=0); void DrawPlugin(void (*draw)(void *context)); - -void Draw_String(std::string); -void Draw_String(std::string, double style); -void Draw_String_Center(std::string); -void Draw_String_Right(std::string); - void GetStoredViewport(int viewport[4], int index=0); -void Viewport2World(double win[3], double xyz[3]); -void World2Viewport(double xyz[3], double win[3]); +int GetFontIndex(const char *fontname); +int GetFontEnum(int index); +const char *GetFontName(int index); +int GetFontAlign(const char *alignstr); +int GetFontSize(); + #endif diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index 6ace1a0aff2162e36f9c04407d58e53394143313..dad2f4dc45e0a9062f959f9940a7a3e5d40140be 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -128,6 +128,7 @@ GUI::GUI(int argc, char **argv) //graph.push_back(new graphicWindow(_fontsize)); //drawTransform *tr = new drawTransformScaled(2,0,0, 0,1,0, 0,0,1); //graph.back()->gl->getDrawContext()->setTransform(tr); + //graph.back()->win->size(300, 300); //graph.back()->win->show(); options = new optionWindow(_fontsize); @@ -715,90 +716,6 @@ void window_cb(Fl_Widget *w, void *data) } } -// Utility routines - -int GetFontIndex(const char *fontname) -{ - if(fontname){ - for(int i = 0; i < NUM_FONTS; i++) - if(!strcmp(menu_font_names[i].label(), fontname)) - return i; - } - Msg::Error("Unknown font \"%s\" (using \"Helvetica\" instead)", fontname); - Msg::Info("Available fonts:"); - for(int i = 0; i < NUM_FONTS; i++) - Msg::Info(" \"%s\"", menu_font_names[i].label()); - return 4; -} - -int GetFontEnum(int index) -{ - if(index >= 0 && index < NUM_FONTS) - return (long)menu_font_names[index].user_data(); - return FL_HELVETICA; -} - -const char *GetFontName(int index) -{ - if(index >= 0 && index < NUM_FONTS) - return menu_font_names[index].label(); - return "Helvetica"; -} - -int GetFontAlign(const char *alignstr) -{ - if(alignstr){ - if(!strcmp(alignstr, "BottomLeft") || !strcmp(alignstr, "Left") || - !strcmp(alignstr, "left")) - return 0; - else if(!strcmp(alignstr, "BottomCenter") || !strcmp(alignstr, "Center") || - !strcmp(alignstr, "center")) - return 1; - else if(!strcmp(alignstr, "BottomRight") || !strcmp(alignstr, "Right") || - !strcmp(alignstr, "right")) - return 2; - else if(!strcmp(alignstr, "TopLeft")) - return 3; - else if(!strcmp(alignstr, "TopCenter")) - return 4; - else if(!strcmp(alignstr, "TopRight")) - return 5; - else if(!strcmp(alignstr, "CenterLeft")) - return 6; - else if(!strcmp(alignstr, "CenterCenter")) - return 7; - else if(!strcmp(alignstr, "CenterRight")) - return 8; - } - Msg::Error("Unknown font alignment \"%s\" (using \"Left\" instead)", alignstr); - Msg::Info("Available font alignments:"); - Msg::Info(" \"Left\" (or \"BottomLeft\")"); - Msg::Info(" \"Center\" (or \"BottomCenter\")"); - Msg::Info(" \"Right\" (or \"BottomRight\")"); - Msg::Info(" \"TopLeft\""); - Msg::Info(" \"TopCenter\""); - Msg::Info(" \"TopRight\""); - Msg::Info(" \"CenterLeft\""); - Msg::Info(" \"CenterCenter\""); - Msg::Info(" \"CenterRight\""); - return 0; -} - -int GetFontSize() -{ - if(CTX.fontsize > 0){ - return CTX.fontsize; - } - else{ - int w = Fl::w(); - if(w <= 1024) return 11; - else if(w <= 1280) return 12; - else if(w <= 1680) return 13; - else if(w <= 1920) return 14; - else return 15; - } -} - void add_multiline_in_browser(Fl_Browser *o, const char *prefix, const char *str, int wrap) { diff --git a/Fltk/GUI.h b/Fltk/GUI.h index 23cc1828959e2cb3fd55a0f459b8a7871ebb4670..bbe383e9ccb8c99665eb89019065c54dc24c1fae 100644 --- a/Fltk/GUI.h +++ b/Fltk/GUI.h @@ -106,18 +106,10 @@ class GUI{ void callForSolverPlugin(int dim); }; -// callbacks void hide_cb(Fl_Widget *w, void *data); void redraw_cb(Fl_Widget *w, void *data); void window_cb(Fl_Widget *w, void *data); -// utility functions -int GetFontIndex(const char *fontname); -int GetFontEnum(int index); -const char *GetFontName(int index); -int GetFontAlign(const char *alignstr); -int GetFontSize(); - class Fl_Browser; void add_multiline_in_browser(Fl_Browser *o, const char *prefix, const char *str, int wrap=0); diff --git a/Fltk/Makefile b/Fltk/Makefile index 24d0d5d735ae2bd919e99067dd7c1655c4a3652e..a260371ce5567e590f8ed8e071175bea724ec352 100644 --- a/Fltk/Makefile +++ b/Fltk/Makefile @@ -173,7 +173,7 @@ optionWindow${OBJEXT}: optionWindow.cpp GUI.h optionWindow.h \ ../Post/ColorTable.h ../Common/OS.h ../Common/Context.h \ ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h colorbarWindow${OBJEXT}: colorbarWindow.cpp colorbarWindow.h \ - ../Post/ColorTable.h GUI.h ../Common/Context.h ../Geo/CGNSOptions.h \ + ../Post/ColorTable.h Draw.h ../Common/Context.h ../Geo/CGNSOptions.h \ ../Mesh/PartitionOptions.h fieldWindow${OBJEXT}: fieldWindow.cpp GUI.h Draw.h fieldWindow.h \ shortcutWindow.h fileDialogs.h ../Common/GmshDefines.h ../Geo/GModel.h \ @@ -340,9 +340,10 @@ partitionDialog${OBJEXT}: partitionDialog.cpp GUI.h shortcutWindow.h \ ../Mesh/PartitionOptions.h Draw${OBJEXT}: Draw.cpp GUI.h graphicWindow.h openglWindow.h \ ../Graphics/drawContext.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \ - ../Common/GmshDefines.h Draw.h ../Common/StringUtils.h \ - ../Graphics/gl2ps.h ../Common/Context.h ../Geo/CGNSOptions.h \ - ../Mesh/PartitionOptions.h + optionWindow.h spherePositionWidget.h colorbarWindow.h \ + ../Post/ColorTable.h ../Common/GmshDefines.h ../Common/GmshMessage.h \ + Draw.h ../Common/StringUtils.h ../Graphics/gl2ps.h ../Common/Context.h \ + ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h Solvers${OBJEXT}: Solvers.cpp GUI.h solverWindow.h menuWindow.h popupButton.h \ ../Common/GmshMessage.h ../Common/StringUtils.h Solvers.h \ ../Common/GmshSocket.h ../Common/OpenFile.h ../Post/PView.h \ diff --git a/Fltk/aboutWindow.cpp b/Fltk/aboutWindow.cpp index 7a568280c8066d6091394ddcb6e6f50b0295771e..dbbe20dc2030e328637205af6829626857ef4fb6 100644 --- a/Fltk/aboutWindow.cpp +++ b/Fltk/aboutWindow.cpp @@ -91,16 +91,18 @@ aboutWindow::aboutWindow(int fontsize) } { - Fl_Button *o = new Fl_Button(width/2 - BB - WB/2, height - BH - WB, BB, BH, "License"); + Fl_Button *o = new Fl_Button + (width/2 - BB - WB/2, height - BH - WB, BB, BH, "License"); o->callback(help_license_cb); } { - Fl_Button *o = new Fl_Button(width/2 + WB/2, height - BH - WB, BB, BH, "Credits"); + Fl_Button *o = new Fl_Button + (width/2 + WB/2, height - BH - WB, BB, BH, "Credits"); o->callback(help_credits_cb); } win->position(Fl::x() + Fl::w()/2 - width / 2, - Fl::y() + Fl::h()/2 - height / 2); + Fl::y() + Fl::h()/2 - height / 2); win->end(); } diff --git a/Fltk/clippingWindow.cpp b/Fltk/clippingWindow.cpp index ecfa93dc2ceece606944a85b6e6b82f2546148c3..d7c23451e6e0ea1d9025e5cd5fffc4ab88e1aabd 100644 --- a/Fltk/clippingWindow.cpp +++ b/Fltk/clippingWindow.cpp @@ -117,7 +117,8 @@ static void clip_update_cb(Fl_Widget *w, void *data) static void clip_invert_cb(Fl_Widget *w, void *data) { for(int i = 0; i < 4; i++) - GUI::instance()->clipping->value[i]->value(-GUI::instance()->clipping->value[i]->value()); + GUI::instance()->clipping->value[i]->value + (-GUI::instance()->clipping->value[i]->value()); clip_update_cb(NULL, NULL); } diff --git a/Fltk/colorbarWindow.cpp b/Fltk/colorbarWindow.cpp index bd96c81289d8cc7c7203215e8e97a5c56f04c36c..b7e2d1c0cb98b6e7e87dfd53498f5504cb9079af 100644 --- a/Fltk/colorbarWindow.cpp +++ b/Fltk/colorbarWindow.cpp @@ -11,7 +11,7 @@ #include <FL/fl_draw.H> #include "colorbarWindow.h" #include "ColorTable.h" -#include "GUI.h" // FIXME for GetFontSize +#include "Draw.h" #include "Context.h" extern Context_T CTX; diff --git a/Graphics/Makefile b/Graphics/Makefile index 218c2026d2453c71b93e854655748f97f150dbf9..6a07e362af7aca802de4a3685951aadc509fefb9 100644 --- a/Graphics/Makefile +++ b/Graphics/Makefile @@ -63,8 +63,8 @@ Iso${OBJEXT}: Iso.cpp ../Numeric/Numeric.h ../Numeric/NumericEmbedded.h ReadImg${OBJEXT}: ReadImg.cpp ReadImg.h ../Common/GmshMessage.h ../Post/PView.h \ ../Geo/SPoint3.h ../Post/PViewDataList.h ../Post/PViewData.h \ ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Common/ListUtils.h -drawContext${OBJEXT}: drawContext.cpp ../Common/GmshMessage.h ../Fltk/Draw.h \ - drawContext.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h Trackball.h \ +drawContext${OBJEXT}: drawContext.cpp ../Common/GmshMessage.h drawContext.h \ + ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h Trackball.h \ ../Common/Context.h ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h \ ../Numeric/Numeric.h ../Numeric/NumericEmbedded.h ../Geo/GModel.h \ ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \ @@ -87,51 +87,52 @@ drawMesh${OBJEXT}: drawMesh.cpp drawContext.h ../Geo/SBoundingBox3d.h \ ../Geo/SBoundingBox3d.h ../Geo/MElement.h ../Geo/MVertex.h \ ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/MEdge.h ../Geo/MVertex.h \ ../Geo/SVector3.h ../Geo/MFace.h ../Geo/MVertex.h ../Geo/SVector3.h \ - ../Numeric/FunctionSpace.h ../Numeric/GmshMatrix.h ../Fltk/Draw.h \ - ../Common/Context.h ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h \ - ../Common/OS.h gl2ps.h ../Common/VertexArray.h ../Common/SmoothData.h \ - ../Post/PView.h ../Post/PViewData.h + ../Numeric/FunctionSpace.h ../Numeric/GmshMatrix.h ../Common/Context.h \ + ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h ../Common/OS.h gl2ps.h \ + ../Common/VertexArray.h ../Common/SmoothData.h ../Post/PView.h \ + ../Post/PViewData.h drawGeom${OBJEXT}: drawGeom.cpp drawContext.h ../Geo/SBoundingBox3d.h \ - ../Geo/SPoint3.h ../Fltk/Draw.h ../Common/Context.h \ - ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h gl2ps.h \ - ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \ - ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h \ - ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/GPoint.h \ - ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h \ - ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint2.h ../Geo/GFace.h \ - ../Geo/GEntity.h ../Geo/GPoint.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h \ - ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h ../Geo/GRegion.h \ - ../Geo/GEntity.h ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h + ../Geo/SPoint3.h ../Common/Context.h ../Geo/CGNSOptions.h \ + ../Mesh/PartitionOptions.h gl2ps.h ../Common/VertexArray.h \ + ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/GModel.h ../Geo/GVertex.h \ + ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \ + ../Geo/SBoundingBox3d.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h \ + ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h \ + ../Geo/SPoint2.h ../Geo/GFace.h ../Geo/GEntity.h ../Geo/GPoint.h \ + ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/SPoint2.h ../Geo/SVector3.h \ + ../Geo/Pair.h ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/SPoint3.h \ + ../Geo/SBoundingBox3d.h drawPost${OBJEXT}: drawPost.cpp drawContext.h ../Geo/SBoundingBox3d.h \ ../Geo/SPoint3.h ../Common/GmshMessage.h ../Numeric/Numeric.h \ - ../Numeric/NumericEmbedded.h ../Fltk/Draw.h Iso.h ../Post/PView.h \ + ../Numeric/NumericEmbedded.h Iso.h ../Post/PView.h \ ../Post/PViewOptions.h ../Post/ColorTable.h ../Post/PViewData.h \ ../Common/VertexArray.h ../Geo/SVector3.h ../Geo/SPoint3.h \ ../Common/SmoothData.h ../Common/Context.h ../Geo/CGNSOptions.h \ ../Mesh/PartitionOptions.h gl2ps.h drawAxes${OBJEXT}: drawAxes.cpp drawContext.h ../Geo/SBoundingBox3d.h \ - ../Geo/SPoint3.h ../Fltk/Draw.h ../Geo/GModel.h ../Geo/GVertex.h \ - ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \ - ../Geo/SBoundingBox3d.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h \ - ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h \ - ../Geo/SPoint3.h ../Geo/SPoint2.h ../Geo/GFace.h ../Geo/GEntity.h \ - ../Geo/GPoint.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/SPoint2.h \ - ../Geo/SVector3.h ../Geo/Pair.h ../Geo/GRegion.h ../Geo/GEntity.h \ - ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Common/Context.h \ - ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h ../Numeric/Numeric.h \ + ../Geo/SPoint3.h ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h \ + ../Geo/Range.h ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/GPoint.h \ + ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h \ + ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \ + ../Geo/GFace.h ../Geo/GEntity.h ../Geo/GPoint.h ../Geo/GEdgeLoop.h \ + ../Geo/GEdge.h ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h \ + ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/SPoint3.h \ + ../Geo/SBoundingBox3d.h ../Common/Context.h ../Geo/CGNSOptions.h \ + ../Mesh/PartitionOptions.h ../Numeric/Numeric.h \ ../Numeric/NumericEmbedded.h gl2ps.h drawScales${OBJEXT}: drawScales.cpp drawContext.h ../Geo/SBoundingBox3d.h \ - ../Geo/SPoint3.h ../Fltk/Draw.h ../Post/PView.h ../Post/PViewOptions.h \ + ../Geo/SPoint3.h ../Post/PView.h ../Post/PViewOptions.h \ ../Post/ColorTable.h ../Post/PViewData.h ../Common/Context.h \ ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h gl2ps.h drawGraph2d${OBJEXT}: drawGraph2d.cpp drawContext.h ../Geo/SBoundingBox3d.h \ - ../Geo/SPoint3.h ../Fltk/Draw.h ../Post/PView.h ../Post/PViewOptions.h \ + ../Geo/SPoint3.h ../Post/PView.h ../Post/PViewOptions.h \ ../Post/ColorTable.h ../Post/PViewData.h gl2ps.h ../Common/Context.h \ ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h ../Numeric/Numeric.h \ ../Numeric/NumericEmbedded.h drawGlyph${OBJEXT}: drawGlyph.cpp drawContext.h ../Geo/SBoundingBox3d.h \ - ../Geo/SPoint3.h ../Numeric/Numeric.h ../Numeric/NumericEmbedded.h \ - ../Fltk/Draw.h ../Common/Context.h ../Geo/CGNSOptions.h \ + ../Geo/SPoint3.h ../Fltk/Draw.h ../Common/GmshDefines.h \ + ../Numeric/Numeric.h ../Numeric/NumericEmbedded.h \ + ../Common/StringUtils.h ../Common/Context.h ../Geo/CGNSOptions.h \ ../Mesh/PartitionOptions.h gl2ps.h gl2ps${OBJEXT}: gl2ps.cpp gl2ps.h gl2gif${OBJEXT}: gl2gif.cpp ../Common/MallocUtils.h gl2gif.h PixelBuffer.h \ diff --git a/Graphics/drawAxes.cpp b/Graphics/drawAxes.cpp index 6937c834882f585e107412cf208b0251b3ec86c6..a5c4bbcfa76d5af5757b561850b66370e390dd22 100644 --- a/Graphics/drawAxes.cpp +++ b/Graphics/drawAxes.cpp @@ -6,7 +6,6 @@ #include <string.h> #include <FL/gl.h> #include "drawContext.h" -#include "Draw.h" #include "GModel.h" #include "Context.h" #include "Numeric.h" @@ -14,7 +13,7 @@ extern Context_T CTX; -static int drawTics(int comp, int n, char *format, char *label, +static int drawTics(drawContext *ctx, int comp, int n, char *format, char *label, double p1[3], double p2[3], double perp[3], int mikado, double pixelfact) { @@ -28,7 +27,7 @@ static int drawTics(int comp, int n, char *format, char *label, glRasterPos3d(p2[0] + t[0] * w * 1.4, p2[1] + t[1] * w * 1.4, p2[2] + t[2] * w * 1.4); - Draw_String(label); + ctx->drawString(label); if(n < 2) return 0; @@ -87,8 +86,8 @@ static int drawTics(int comp, int n, char *format, char *label, else // display the coordinate sprintf(str, format, p[comp]); double winp[3], winr[3]; - World2Viewport(p, winp); - World2Viewport(r, winr); + ctx->world2Viewport(p, winp); + ctx->world2Viewport(r, winr); gl_font(CTX.gl_font_enum, CTX.gl_fontsize); if(fabs(winr[0] - winp[0]) < 2.) // center align winr[0] -= gl_width(str) / 2.; @@ -98,9 +97,9 @@ static int drawTics(int comp, int n, char *format, char *label, winr[1] -= gl_height() / 3.; else if(winr[1] < winp[1]) // top align winr[1] -= gl_height(); - Viewport2World(winr, r); + ctx->viewport2World(winr, r); glRasterPos3d(r[0], r[1], r[2]); - Draw_String(str); + ctx->drawString(str); } return n; @@ -203,7 +202,7 @@ void drawContext::drawAxes(int mode, int tics[3], char format[3][256], else{ perp[0] = 0.; perp[1] = dir[2]; perp[2] = -dir[1]; } - drawTics(-1, tics[0], format[0], label[0], orig, end, perp, mikado, pixelfact); + drawTics(this, -1, tics[0], format[0], label[0], orig, end, perp, mikado, pixelfact); drawAxis(xmin, ymin, zmin, xmax, ymax, zmax, tics[0], mikado); return; } @@ -215,11 +214,11 @@ void drawContext::drawAxes(int mode, int tics[3], char format[3][256], double dzm[3] = {(xmin != xmax) ? -1. : 0., (ymin != ymax) ? -1. : 0., 0.}; int nx = (xmin != xmax) ? - drawTics(0, tics[0], format[0], label[0], orig, xx, dxm, mikado, pixelfact) : 0; + drawTics(this, 0, tics[0], format[0], label[0], orig, xx, dxm, mikado, pixelfact) : 0; int ny = (ymin != ymax) ? - drawTics(1, tics[1], format[1], label[1], orig, yy, dym, mikado, pixelfact) : 0; + drawTics(this, 1, tics[1], format[1], label[1], orig, yy, dym, mikado, pixelfact) : 0; int nz = (zmin != zmax) ? - drawTics(2, tics[2], format[2], label[2], orig, zz, dzm, mikado, pixelfact) : 0; + drawTics(this, 2, tics[2], format[2], label[2], orig, zz, dzm, mikado, pixelfact) : 0; drawAxis(xmin, ymin, zmin, xmax, ymin, zmin, nx, mikado); drawAxis(xmin, ymin, zmin, xmin, ymax, zmin, ny, mikado); @@ -349,9 +348,9 @@ void drawContext::drawSmallAxes() glVertex2d(cx + zx, cy + zy); glEnd(); glRasterPos2d(cx + xx + o, cy + xy + o); - Draw_String("X"); + drawString("X"); glRasterPos2d(cx + yx + o, cy + yy + o); - Draw_String("Y"); + drawString("Y"); glRasterPos2d(cx + zx + o, cy + zy + o); - Draw_String("Z"); + drawString("Z"); } diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp index 1be038183c1be4c8138a2a6e39707988ae0c3126..9f6b64740442d08ae28000eb0e01f4cf10da3651 100644 --- a/Graphics/drawContext.cpp +++ b/Graphics/drawContext.cpp @@ -14,7 +14,6 @@ #endif #include "GmshMessage.h" -#include "Draw.h" #include "drawContext.h" #include "Trackball.h" #include "Context.h" @@ -419,7 +418,7 @@ void drawContext::initPosition() // store the projection and modelview matrices at this precise // moment (so that we can use them at any later time, even if the - // context has changed, i.e., even if we are out of Draw()) + // context has changed, i.e., even if we are out of draw()) glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); @@ -458,3 +457,23 @@ void drawContext::unproject(double x, double y, double p[3], double d[3]) d[1] /= len; d[2] /= len; } + +void drawContext::viewport2World(double win[3], double xyz[3]) +{ + GLint viewport[4]; + GLdouble model[16], proj[16]; + glGetIntegerv(GL_VIEWPORT, viewport); + glGetDoublev(GL_PROJECTION_MATRIX, proj); + glGetDoublev(GL_MODELVIEW_MATRIX, model); + gluUnProject(win[0], win[1], win[2], model, proj, viewport, &xyz[0], &xyz[1], &xyz[2]); +} + +void drawContext::world2Viewport(double xyz[3], double win[3]) +{ + GLint viewport[4]; + GLdouble model[16], proj[16]; + glGetIntegerv(GL_VIEWPORT, viewport); + glGetDoublev(GL_PROJECTION_MATRIX, proj); + glGetDoublev(GL_MODELVIEW_MATRIX, model); + gluProject(xyz[0], xyz[1], xyz[2], model, proj, viewport, &win[0], &win[1], &win[2]); +} diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h index 87824af945b92a4eaf6250c09fff9aa8d0b1dea8..2a19797c9d81e2b5a34ced3dc7d0b827d4c029fb 100644 --- a/Graphics/drawContext.h +++ b/Graphics/drawContext.h @@ -6,8 +6,11 @@ #ifndef _DRAW_CONTEXT_H_ #define _DRAW_CONTEXT_H_ +#include <string> #include "SBoundingBox3d.h" +class PView; + class drawTransform { public: drawTransform(){} @@ -77,6 +80,8 @@ class drawContext { void initRenderModel(); void initPosition(); void unproject(double x, double y, double p[3], double d[3]); + void viewport2World(double win[3], double xyz[3]); + void world2Viewport(double xyz[3], double win[3]); int fix2dCoordinates(double *x, double *y); void draw3d(); void draw2d(); @@ -95,6 +100,12 @@ class drawContext { void drawAxes(); void drawSmallAxes(); void drawScales(); + void drawString(std::string s, const char *font_name, int font_enum, + int font_size, int align); + void drawString(std::string s); + void drawStringCenter(std::string s); + void drawStringRight(std::string s); + void drawString(std::string s, double style); void drawSphere(double size, double x, double y, double z, int light); void drawCylinder(double width, double *x, double *y, double *z, int light); void drawTaperedCylinder(double width, double val1, double val2, diff --git a/Graphics/drawGeom.cpp b/Graphics/drawGeom.cpp index 2791a7baf997e889df51c602ed568f5e4a058913..bc80f4e226a78c920b12018cedc8424855dfb5e1 100644 --- a/Graphics/drawGeom.cpp +++ b/Graphics/drawGeom.cpp @@ -5,7 +5,6 @@ #include <FL/gl.h> #include "drawContext.h" -#include "Draw.h" #include "Context.h" #include "gl2ps.h" #include "VertexArray.h" @@ -75,7 +74,7 @@ class drawGVertex { glRasterPos3d(x + offset / _ctx->s[0], y + offset / _ctx->s[1], z + offset / _ctx->s[2]); - Draw_String(Num); + _ctx->drawString(Num); } if(select) { @@ -167,7 +166,7 @@ class drawGEdge { glRasterPos3d(x + offset / _ctx->s[0], y + offset / _ctx->s[1], z + offset / _ctx->s[2]); - Draw_String(Num); + _ctx->drawString(Num); } if(CTX.geom.tangents) { @@ -284,7 +283,7 @@ class drawGFace { glRasterPos3d(x + offset / _ctx->s[0], y + offset / _ctx->s[1], z + offset / _ctx->s[2]); - Draw_String(Num); + _ctx->drawString(Num); } if(CTX.geom.normals) { @@ -351,7 +350,7 @@ class drawGFace { glRasterPos3d(x + offset / _ctx->s[0], y + offset / _ctx->s[0], z + offset / _ctx->s[0]); - Draw_String(Num); + _ctx->drawString(Num); } if(CTX.geom.normals) { @@ -449,7 +448,7 @@ class drawGRegion { glRasterPos3d(x + offset / _ctx->s[0], y + offset / _ctx->s[1], z + offset / _ctx->s[2]); - Draw_String(Num); + _ctx->drawString(Num); } if(select) { diff --git a/Graphics/drawGlyph.cpp b/Graphics/drawGlyph.cpp index 1564fa674d58a5b6dedee259f9f3f6621e116751..521247331a08d42884bf97bf24489c6703af92a4 100644 --- a/Graphics/drawGlyph.cpp +++ b/Graphics/drawGlyph.cpp @@ -15,13 +15,114 @@ #endif #include "drawContext.h" -#include "Numeric.h" #include "Draw.h" +#include "GmshDefines.h" +#include "Numeric.h" +#include "StringUtils.h" #include "Context.h" #include "gl2ps.h" extern Context_T CTX; +void drawContext::drawString(std::string s, const char *font_name, int font_enum, + int font_size, int align) +{ + if(CTX.printing && !CTX.print.text) return; + + // change the raster position only if not creating TeX files + if(align > 0 && (!CTX.printing || CTX.print.format != FORMAT_TEX)){ + GLboolean valid; + glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); + if(valid == GL_TRUE){ + GLdouble pos[4]; + glGetDoublev(GL_CURRENT_RASTER_POSITION, pos); + double x[3], w[3] = {pos[0], pos[1], pos[2]}; + gl_font(font_enum, font_size); + float width = gl_width(s.c_str()); + float height = gl_height(); + switch(align){ + case 1: w[0] -= width/2.; break; // bottom center + case 2: w[0] -= width; break; // bottom right + case 3: w[1] -= height; break; // top left + case 4: w[0] -= width/2.; w[1] -= height; break; // top center + case 5: w[0] -= width; w[1] -= height; break; // top right + case 6: w[1] -= height/2.; break; // center left + case 7: w[0] -= width/2.; w[1] -= height/2.; break; // center center + case 8: w[0] -= width; w[1] -= height/2.; break; // center right + default: break; + } + viewport2World(w, x); + glRasterPos3d(x[0], x[1], x[2]); + } + } + + if(!CTX.printing){ + gl_font(font_enum, font_size); + gl_draw(s.c_str()); + } + else{ + if(CTX.print.format == FORMAT_TEX){ + std::string tmp = SanitizeTeXString(s.c_str(), CTX.print.tex_as_equation); + int opt; + switch(align){ + case 1: opt = GL2PS_TEXT_B; break; // bottom center + case 2: opt = GL2PS_TEXT_BR; break; // bottom right + case 3: opt = GL2PS_TEXT_TL; break; // top left + case 4: opt = GL2PS_TEXT_T; break; // top center + case 5: opt = GL2PS_TEXT_TR; break; // top right + case 6: opt = GL2PS_TEXT_CL; break; // center left + case 7: opt = GL2PS_TEXT_C; break; // center center + case 8: opt = GL2PS_TEXT_CR; break; // center right + default: opt = GL2PS_TEXT_BL; break; // bottom left + } + gl2psTextOpt(tmp.c_str(), font_name, font_size, opt, 0.); + } + else if(CTX.print.eps_quality && (CTX.print.format == FORMAT_PS || + CTX.print.format == FORMAT_EPS || + CTX.print.format == FORMAT_PDF || + CTX.print.format == FORMAT_SVG)){ + gl2psText(s.c_str(), font_name, font_size); + } + else{ + gl_font(font_enum, font_size); + gl_draw(s.c_str()); + } + } +} + +void drawContext::drawString(std::string s) +{ + drawString(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 0); +} + +void drawContext::drawStringCenter(std::string s) +{ + drawString(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 1); +} + +void drawContext::drawStringRight(std::string s) +{ + drawString(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 2); +} + +void drawContext::drawString(std::string s, double style) +{ + unsigned int bits = (unsigned int)style; + + if(!bits){ // use defaults + drawString(s); + } + else{ + int size = (bits & 0xff); + int font = (bits>>8 & 0xff); + int align = (bits>>16 & 0xff); + int font_enum = GetFontEnum(font); + const char *font_name = GetFontName(font); + if(!size) size = CTX.gl_fontsize; + drawString(s, font_name, font_enum, size, align); + } +} + void drawContext::drawSphere(double size, double x, double y, double z, int light) { if(light) glEnable(GL_LIGHTING); @@ -464,12 +565,12 @@ void drawContext::drawBox(double xmin, double ymin, double zmin, ymin + offset / s[1], zmin + offset / s[2]); sprintf(label, "(%g,%g,%g)", xmin, ymin, zmin); - Draw_String(label); + drawString(label); glRasterPos3d(xmax + offset / s[0], ymax + offset / s[1], zmax + offset / s[2]); sprintf(label, "(%g,%g,%g)", xmax, ymax, zmax); - Draw_String(label); + drawString(label); } } diff --git a/Graphics/drawGraph2d.cpp b/Graphics/drawGraph2d.cpp index f436642c40a73f710955d4aa8d3688bd15cae8a2..84166f708f8e37b584c339e6d128e344ea8e54c6 100644 --- a/Graphics/drawGraph2d.cpp +++ b/Graphics/drawGraph2d.cpp @@ -5,7 +5,6 @@ #include <FL/gl.h> #include "drawContext.h" -#include "Draw.h" #include "PView.h" #include "PViewOptions.h" #include "PViewData.h" @@ -46,7 +45,7 @@ void drawContext::drawText2d() data->getString2D(j, opt->TimeStep, str, x, y, style); fix2dCoordinates(&x, &y); glRasterPos2d(x, y); - Draw_String(str.c_str(), style); + drawString(str.c_str(), style); } } } @@ -144,8 +143,8 @@ static bool getGraphData(PView *p, std::vector<double> &x, double &xmin, return true; } -static void drawGraphAxes(PView *p, double xleft, double ytop, double width, - double height, double xmin, double xmax) +static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, + double width, double height, double xmin, double xmax) { PViewData *data = p->getData(); PViewOptions *opt = p->getOptions(); @@ -194,12 +193,12 @@ static void drawGraphAxes(PView *p, double xleft, double ytop, double width, else sprintf(label, "%s", data->getName().c_str()); glRasterPos2d(xleft, ytop + font_h + tic); - Draw_String_Center(label); + ctx->drawStringCenter(label); // x label sprintf(label, "%s", opt->AxesLabel[0]); glRasterPos2d(xleft + width / 2, ytop - height - 2 * font_h - 2 * tic); - Draw_String_Center(label); + ctx->drawStringCenter(label); // y tics and horizontal grid if(opt->NbIso > 0){ @@ -235,7 +234,7 @@ static void drawGraphAxes(PView *p, double xleft, double ytop, double width, if(opt->ShowScale){ sprintf(label, opt->Format, (i == nb) ? opt->TmpMin : (opt->TmpMax - i * dv)); glRasterPos2d(xleft - 2 * tic, ytop - i * dy - font_a / 3.); - Draw_String_Right(label); + ctx->drawStringRight(label); } } } @@ -283,16 +282,17 @@ static void drawGraphAxes(PView *p, double xleft, double ytop, double width, sprintf(label, opt->AxesFormat[0], xmin + i * (xmax - xmin) / (double)(nb - 1)); glRasterPos2d(xleft + i * dx, ybot - font_h - tic); - Draw_String_Center(label); + ctx->drawStringCenter(label); } } } } -static void addGraphPoint(PView *p, double xleft, double ytop, double width, - double height, double x, double y, double xmin, - double xmax, double ymin, double ymax, bool numeric) +static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, + double width, double height, double x, double y, + double xmin, double xmax, double ymin, double ymax, + bool numeric) { PViewOptions *opt = p->getOptions(); @@ -317,16 +317,17 @@ static void addGraphPoint(PView *p, double xleft, double ytop, double width, glRasterPos2d(px + 3, py + 3); char label[256]; sprintf(label, opt->Format, y); - Draw_String(label); + ctx->drawString(label); } else glVertex2d(px, py); } } -static void drawGraphCurves(PView *p, double xleft, double ytop, double width, - double height, std::vector<double> &x, double xmin, - double xmax, std::vector<std::vector<double> > &y) +static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double ytop, + double width, double height, std::vector<double> &x, + double xmin, double xmax, + std::vector<std::vector<double> > &y) { PViewOptions *opt = p->getOptions(); @@ -339,7 +340,7 @@ static void drawGraphCurves(PView *p, double xleft, double ytop, double width, if(opt->IntervalsType == PViewOptions::Numeric){ for(unsigned int i = 0; i < y.size(); i++) for(unsigned int j = 0; j < x.size(); j++) - addGraphPoint(p, xleft, ytop, width, height, x[j], y[i][j], + addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin, xmax, opt->TmpMin, opt->TmpMax, true); } @@ -349,7 +350,7 @@ static void drawGraphCurves(PView *p, double xleft, double ytop, double width, glBegin(GL_POINTS); for(unsigned int i = 0; i < y.size(); i++) for(unsigned int j = 0; j < x.size(); j++) - addGraphPoint(p, xleft, ytop, width, height, x[j], y[i][j], + addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin, xmax, opt->TmpMin, opt->TmpMax, false); glEnd(); } @@ -364,7 +365,7 @@ static void drawGraphCurves(PView *p, double xleft, double ytop, double width, } glBegin(GL_LINE_STRIP); for(unsigned int j = 0; j < x.size(); j++) - addGraphPoint(p, xleft, ytop, width, height, x[j], y[i][j], + addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin, xmax, opt->TmpMin, opt->TmpMax, false); glEnd(); if(opt->UseStipple){ @@ -375,7 +376,8 @@ static void drawGraphCurves(PView *p, double xleft, double ytop, double width, } } -static void drawGraph(PView *p, double xleft, double ytop, double width, double height) +static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop, + double width, double height) { PViewData *data = p->getData(); PViewOptions *opt = p->getOptions(); @@ -397,8 +399,8 @@ static void drawGraph(PView *p, double xleft, double ytop, double width, double std::vector<std::vector<double> > y; double xmin, xmax; if(!getGraphData(p, x, xmin, xmax, y)) return; - drawGraphAxes(p, xleft, ytop, width, height, xmin, xmax); - drawGraphCurves(p, xleft, ytop, width, height, x, xmin, xmax, y); + drawGraphAxes(ctx, p, xleft, ytop, width, height, xmin, xmax); + drawGraphCurves(ctx, p, xleft, ytop, width, height, x, xmin, xmax, y); } void drawContext::drawGraph2d() @@ -427,7 +429,7 @@ void drawContext::drawGraph2d() if(!opt->AutoPosition){ double x = opt->Position[0], y = opt->Position[1]; int center = fix2dCoordinates(&x, &y); - drawGraph(p, x - (center & 1 ? opt->Size[0] / 2. : 0), + drawGraph(this, p, x - (center & 1 ? opt->Size[0] / 2. : 0), y + (center & 2 ? opt->Size[1] / 2. : 0), opt->Size[0], opt->Size[1]); } @@ -440,7 +442,7 @@ void drawContext::drawGraph2d() double h = frach * winh - ysep; double x = viewport[0] + (1 - fracw) / 2. * winw; double y = viewport[1] + (1 - frach) / 2. * winh; - drawGraph(p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h); + drawGraph(this, p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h); } else if(graphs.size() == 2){ double fracw = 0.75, frach = 0.85; @@ -449,7 +451,7 @@ void drawContext::drawGraph2d() double x = viewport[0] + (1 - fracw) / 2. * winw; double y = viewport[1] + (1 - frach) / 3. * winh; if(i == 1) y += (h + ysep + (1 - frach) / 3. * winh); - drawGraph(p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h); + drawGraph(this, p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h); } else{ double fracw = 0.85, frach = 0.85; @@ -459,7 +461,7 @@ void drawContext::drawGraph2d() if(i == 1 || i == 3) x += (w + xsep + (1-fracw)/3. * winw); double y = viewport[1] + (1 - frach) / 3. * winh; if(i == 2 || i == 3) y += (h + ysep + (1 - frach) / 3. * winh); - drawGraph(p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h); + drawGraph(this, p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h); } } } diff --git a/Graphics/drawMesh.cpp b/Graphics/drawMesh.cpp index d7a44958c6bd39abf62ab8f4af25e6ff31d0a65c..8dd2b6f39317ee727d9d1f8f794eea7cca5e8cdf 100644 --- a/Graphics/drawMesh.cpp +++ b/Graphics/drawMesh.cpp @@ -10,7 +10,6 @@ #include "GmshDefines.h" #include "GModel.h" #include "MElement.h" -#include "Draw.h" #include "Context.h" #include "OS.h" #include "gl2ps.h" @@ -166,8 +165,9 @@ static int getLabelStep(int total) } template<class T> -static void drawElementLabels(GEntity *e, std::vector<T*> &elements, - int forceColor=0, unsigned int color=0) +static void drawElementLabels(drawContext *ctx, GEntity *e, + std::vector<T*> &elements, int forceColor=0, + unsigned int color=0) { unsigned col = forceColor ? color : getColorByEntity(e); glColor4ubv((GLubyte *) & col); @@ -194,7 +194,7 @@ static void drawElementLabels(GEntity *e, std::vector<T*> &elements, else sprintf(str, "%d", ele->getNum()); glRasterPos3d(pc.x(), pc.y(), pc.z()); - Draw_String(str); + ctx->drawString(str); } } } @@ -233,7 +233,8 @@ static void drawTangents(drawContext *ctx, std::vector<T*> &elements) } } -static void drawVertexLabel(GEntity *e, MVertex *v, int partition=-1) +static void drawVertexLabel(drawContext *ctx, GEntity *e, MVertex *v, + int partition=-1) { if(!v->getVisibility()) return; @@ -260,7 +261,7 @@ static void drawVertexLabel(GEntity *e, MVertex *v, int partition=-1) else glColor4ubv((GLubyte *) & CTX.color.mesh.vertex); glRasterPos3d(v->x(), v->y(), v->z()); - Draw_String(str); + ctx->drawString(str); } static void drawVerticesPerEntity(drawContext *ctx, GEntity *e) @@ -294,7 +295,7 @@ static void drawVerticesPerEntity(drawContext *ctx, GEntity *e) if(CTX.mesh.points_num) { int labelStep = getLabelStep(e->mesh_vertices.size()); for(unsigned int i = 0; i < e->mesh_vertices.size(); i++) - if(i % labelStep == 0) drawVertexLabel(e, e->mesh_vertices[i]); + if(i % labelStep == 0) drawVertexLabel(ctx, e, e->mesh_vertices[i]); } } @@ -321,7 +322,7 @@ static void drawVerticesPerElement(drawContext *ctx, GEntity *e, } } if(CTX.mesh.points_num) - drawVertexLabel(e, v); + drawVertexLabel(ctx, e, v); } } } @@ -645,7 +646,7 @@ class drawMeshGEdge { drawArrays(_ctx, e, e->va_lines, GL_LINES, false); if(CTX.mesh.lines_num) - drawElementLabels(e, e->lines); + drawElementLabels(_ctx, e, e->lines); if(CTX.mesh.points || CTX.mesh.points_num){ if(e->getAllElementsVisible()) @@ -744,9 +745,11 @@ class drawMeshGFace { if(CTX.mesh.surfaces_num) { if(CTX.mesh.triangles) - drawElementLabels(f, f->triangles, CTX.mesh.surfaces_faces, CTX.color.mesh.line); + drawElementLabels(_ctx, f, f->triangles, CTX.mesh.surfaces_faces, + CTX.color.mesh.line); if(CTX.mesh.quadrangles) - drawElementLabels(f, f->quadrangles, CTX.mesh.surfaces_faces, CTX.color.mesh.line); + drawElementLabels(_ctx, f, f->quadrangles, CTX.mesh.surfaces_faces, + CTX.color.mesh.line); } if(CTX.mesh.points || CTX.mesh.points_num){ @@ -871,16 +874,16 @@ class drawMeshGRegion { if(CTX.mesh.volumes_num) { if(CTX.mesh.tetrahedra) - drawElementLabels(r, r->tetrahedra, CTX.mesh.volumes_faces || + drawElementLabels(_ctx, r, r->tetrahedra, CTX.mesh.volumes_faces || CTX.mesh.surfaces_faces, CTX.color.mesh.line); if(CTX.mesh.hexahedra) - drawElementLabels(r, r->hexahedra, CTX.mesh.volumes_faces || + drawElementLabels(_ctx, r, r->hexahedra, CTX.mesh.volumes_faces || CTX.mesh.surfaces_faces, CTX.color.mesh.line); if(CTX.mesh.prisms) - drawElementLabels(r, r->prisms, CTX.mesh.volumes_faces || + drawElementLabels(_ctx, r, r->prisms, CTX.mesh.volumes_faces || CTX.mesh.surfaces_faces, CTX.color.mesh.line); if(CTX.mesh.pyramids) - drawElementLabels(r, r->pyramids, CTX.mesh.volumes_faces || + drawElementLabels(_ctx, r, r->pyramids, CTX.mesh.volumes_faces || CTX.mesh.surfaces_faces, CTX.color.mesh.line); } diff --git a/Graphics/drawPost.cpp b/Graphics/drawPost.cpp index cc7550251a115c3045bc6f9b7eb7dc5de456eb28..522a9c5b79ce91070b19c4dcf7b1968ef6dd19f0 100644 --- a/Graphics/drawPost.cpp +++ b/Graphics/drawPost.cpp @@ -9,7 +9,6 @@ #include "drawContext.h" #include "GmshMessage.h" #include "Numeric.h" -#include "Draw.h" #include "Iso.h" #include "PView.h" #include "PViewOptions.h" @@ -1120,7 +1119,7 @@ static std::string stringValue(int numComp, double d[9], double norm, char *form return std::string(label); } -static void drawNumberGlyphs(PView *p, int numNodes, int numComp, +static void drawNumberGlyphs(drawContext *ctx, PView *p, int numNodes, int numComp, double xyz[NMAX][3], double val[NMAX][9]) { PViewOptions *opt = p->getOptions(); @@ -1142,9 +1141,9 @@ static void drawNumberGlyphs(PView *p, int numNodes, int numComp, glColor4ubv((GLubyte *) & col); glRasterPos3d(pc.x(), pc.y(), pc.z()); if(opt->CenterGlyphs) - Draw_String_Center(stringValue(numComp, d, v, opt->Format)); + ctx->drawStringCenter(stringValue(numComp, d, v, opt->Format)); else - Draw_String(stringValue(numComp, d, v, opt->Format)); + ctx->drawString(stringValue(numComp, d, v, opt->Format)); } } else if(opt->GlyphLocation == PViewOptions::Vertex){ @@ -1155,9 +1154,9 @@ static void drawNumberGlyphs(PView *p, int numNodes, int numComp, glColor4ubv((GLubyte *) & col); glRasterPos3d(xyz[i][0], xyz[i][1], xyz[i][2]); if(opt->CenterGlyphs) - Draw_String_Center(stringValue(numComp, val[i], v, opt->Format)); + ctx->drawStringCenter(stringValue(numComp, val[i], v, opt->Format)); else - Draw_String(stringValue(numComp, val[i], v, opt->Format)); + ctx->drawString(stringValue(numComp, val[i], v, opt->Format)); } } } @@ -1229,7 +1228,7 @@ static void drawGlyphs(drawContext *ctx, PView *p) } changeCoordinates(p, ent, i, numNodes, numEdges, numComp, xyz, val); if(opt->IntervalsType == PViewOptions::Numeric) - drawNumberGlyphs(p, numNodes, numComp, xyz, val); + drawNumberGlyphs(ctx, p, numNodes, numComp, xyz, val); if(dim == 2 && opt->Normals) drawNormalVectorGlyphs(ctx, p, numNodes, xyz, val); else if(dim == 1 && opt->Tangents) @@ -1450,7 +1449,7 @@ class drawPView { std::string str; data->getString3D(i, opt->TimeStep, str, x, y, z, style); glRasterPos3d(x, y, z); - Draw_String(str, style); + _ctx->drawString(str, style); } } diff --git a/Graphics/drawScales.cpp b/Graphics/drawScales.cpp index 32ec1a68d485735fdf9251135fa85d223fa6e243..25d33566353d49f657f3a6df300fee183392af5a 100644 --- a/Graphics/drawScales.cpp +++ b/Graphics/drawScales.cpp @@ -5,7 +5,6 @@ #include <FL/gl.h> #include "drawContext.h" -#include "Draw.h" #include "PView.h" #include "PViewOptions.h" #include "PViewData.h" @@ -84,8 +83,8 @@ static void drawScaleBar(PView *p, double xmin, double ymin, double width, } } -static void drawScaleValues(PView *p, double xmin, double ymin, double width, - double height, double tic, int horizontal) +static void drawScaleValues(drawContext *ctx, PView *p, double xmin, double ymin, + double width, double height, double tic, int horizontal) { PViewOptions *opt = p->getOptions(); @@ -124,11 +123,11 @@ static void drawScaleValues(PView *p, double xmin, double ymin, double width, sprintf(label, opt->Format, v); if(horizontal){ glRasterPos2d(xmin + i * vbox, ymin + height + tic); - Draw_String_Center(label); + ctx->drawStringCenter(label); } else{ glRasterPos2d(xmin + width + tic, ymin + i * vbox - font_a / 3.); - Draw_String(label); + ctx->drawString(label); } } } @@ -142,18 +141,18 @@ static void drawScaleValues(PView *p, double xmin, double ymin, double width, sprintf(label, opt->Format, v); if(horizontal){ glRasterPos2d(xmin + box / 2. + i * vbox, ymin + height + tic); - Draw_String_Center(label); + ctx->drawStringCenter(label); } else{ glRasterPos2d(xmin + width + tic, ymin + box / 2. + i * vbox - font_a / 3.); - Draw_String(label); + ctx->drawString(label); } } } } -static void drawScaleLabel(PView *p, double xmin, double ymin, double width, - double height, double tic, int horizontal) +static void drawScaleLabel(drawContext *ctx, PView *p, double xmin, double ymin, + double width, double height, double tic, int horizontal) { PViewData *data = p->getData(); PViewOptions *opt = p->getOptions(); @@ -177,16 +176,16 @@ static void drawScaleLabel(PView *p, double xmin, double ymin, double width, if(horizontal){ glRasterPos2d(xmin + width / 2., ymin + height + tic + 1.4 * font_h); - Draw_String_Center(label); + ctx->drawStringCenter(label); } else{ glRasterPos2d(xmin, ymin - 2 * font_h); - Draw_String(label); + ctx->drawString(label); } } -static void drawScale(PView *p, double xmin, double ymin, double width, - double height, double tic, int horizontal) +static void drawScale(drawContext *ctx, PView *p, double xmin, double ymin, + double width, double height, double tic, int horizontal) { // use adaptive data if available PViewData *data = p->getData(true); @@ -210,8 +209,8 @@ static void drawScale(PView *p, double xmin, double ymin, double width, } drawScaleBar(p, xmin, ymin, width, height, tic, horizontal); - drawScaleValues(p, xmin, ymin, width, height, tic, horizontal); - drawScaleLabel(p, xmin, ymin, width, height, tic, horizontal); + drawScaleValues(ctx, p, xmin, ymin, width, height, tic, horizontal); + drawScaleLabel(ctx, p, xmin, ymin, width, height, tic, horizontal); } void drawContext::drawScales() @@ -249,7 +248,7 @@ void drawContext::drawScales() int c = fix2dCoordinates(&x, &y); if(c & 1) x -= w / 2.; if(c & 2) y += h / 2.; - drawScale(p, x, y, w, h, tic, CTX.post.horizontal_scales); + drawScale(this, p, x, y, w, h, tic, CTX.post.horizontal_scales); } else if(CTX.post.horizontal_scales){ double ysep = 20.; @@ -257,7 +256,7 @@ void drawContext::drawScales() if(scales.size() == 1){ double w = (viewport[2] - viewport[0]) / 2., h = bar_size; double x = xc - w / 2., y = viewport[1] + ysep; - drawScale(p, x, y, w, h, tic, 1); + drawScale(this, p, x, y, w, h, tic, 1); } else{ double xsep = maxw / 4. + (viewport[2] - viewport[0]) / 10.; @@ -267,7 +266,7 @@ void drawContext::drawScales() double x = xc - (i % 2 ? -xsep / 1.5 : w + xsep / 1.5); double y = viewport[1] + ysep + (i / 2) * (bar_size + tic + 2 * gl_height() + ysep); - drawScale(p, x, y, w, h, tic, 1); + drawScale(this, p, x, y, w, h, tic, 1); } } else{ @@ -277,7 +276,7 @@ void drawContext::drawScales() double ysep = (viewport[3] - viewport[1]) / 6.; double w = bar_size, h = viewport[3] - viewport[1] - 2 * ysep - dy; double x = viewport[0] + xsep, y = viewport[1] + ysep + dy; - drawScale(p, x, y, w, h, tic, 0); + drawScale(this, p, x, y, w, h, tic, 0); } else{ double ysep = (viewport[3] - viewport[1]) / 15.; @@ -285,7 +284,7 @@ void drawContext::drawScales() double h = (viewport[3] - viewport[1] - 3 * ysep - 2.5 * dy) / 2.; double x = viewport[0] + xsep + width_total + (i / 2) * xsep; double y = viewport[1] + ysep + dy + (1 - i % 2) * (h + 1.5 * dy + ysep); - drawScale(p, x, y, w, h, tic, 0); + drawScale(this, p, x, y, w, h, tic, 0); } // compute width width_prev = width; diff --git a/Plugin/Annotate.cpp b/Plugin/Annotate.cpp index 1fb5585b98afcc318055a243d08ab7ae8de516f3..7d6db6d105535dd9c9afad15e8cbc45a1deec20f 100644 --- a/Plugin/Annotate.cpp +++ b/Plugin/Annotate.cpp @@ -11,7 +11,7 @@ #include <FL/gl.h> #include "drawContext.h" #include "Draw.h" -#include "GUI.h" // FIXME for GetFontSize +#include "GUI.h" #endif extern Context_T CTX; @@ -61,7 +61,7 @@ void GMSH_AnnotatePlugin::draw(void *context) glColor4ubv((GLubyte *) & CTX.color.fg); if(AnnotateOptions_Number[3].def){ // 3D glRasterPos3d(X, Y, Z); - Draw_String(AnnotateOptions_String[0].def, style); + ctx->drawString(AnnotateOptions_String[0].def, style); // draw 10-pixel marker double d = 10 * ctx->pixel_equiv_x / ctx->s[0]; glBegin(GL_LINES); @@ -83,7 +83,7 @@ void GMSH_AnnotatePlugin::draw(void *context) glLoadIdentity(); ctx->fix2dCoordinates(&X, &Y); glRasterPos2d(X, Y); - Draw_String(AnnotateOptions_String[0].def, style); + ctx->drawString(AnnotateOptions_String[0].def, style); // draw 10-pixel marker glBegin(GL_LINES); glVertex2d(X-10,Y); glVertex2d(X+10,Y); diff --git a/Plugin/CutSphere.cpp b/Plugin/CutSphere.cpp index 96aacecd81316e1e763815b2721284b67028df5a..c1655be6c27aa32e652bc9e5b7b008990cc0da3b 100644 --- a/Plugin/CutSphere.cpp +++ b/Plugin/CutSphere.cpp @@ -17,7 +17,6 @@ #else # include <GL/glu.h> #endif - #include "Draw.h" #endif