diff --git a/Common/Options.cpp b/Common/Options.cpp index 0c9f8980b1fcf4b97c260b1e8268a616b479320c..8fd577b3f457cbe510d10acec1d27bb3b38c8e65 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -41,6 +41,7 @@ #if defined(HAVE_FLTK) #include <FL/Fl_Tooltip.H> #include "FlGui.h" +#include "drawContextFltk.h" #include "graphicWindow.h" #include "optionWindow.h" #include "manipWindow.h" @@ -1121,10 +1122,11 @@ std::string opt_general_graphics_font(OPT_ARGS_STR) if(action & GMSH_SET) CTX::instance()->glFont = val; #if defined(HAVE_FLTK) - int index = drawContext::global()->getFontIndex(CTX::instance()->glFont.c_str()); + drawContextFltk dc; + int index = dc.getFontIndex(CTX::instance()->glFont.c_str()); if(action & GMSH_SET){ - CTX::instance()->glFont = drawContext::global()->getFontName(index); - CTX::instance()->glFontEnum = drawContext::global()->getFontEnum(index); + CTX::instance()->glFont = dc.getFontName(index); + CTX::instance()->glFontEnum = dc.getFontEnum(index); } if(FlGui::available() && (action & GMSH_GUI)){ FlGui::instance()->options->general.choice[1]->value(index); @@ -1138,10 +1140,11 @@ std::string opt_general_graphics_font_title(OPT_ARGS_STR) if(action & GMSH_SET) CTX::instance()->glFontTitle = val; #if defined(HAVE_FLTK) - int index = drawContext::global()->getFontIndex(CTX::instance()->glFontTitle.c_str()); + drawContextFltk dc; + int index = dc.getFontIndex(CTX::instance()->glFontTitle.c_str()); if(action & GMSH_SET){ - CTX::instance()->glFontTitle = drawContext::global()->getFontName(index); - CTX::instance()->glFontEnumTitle = drawContext::global()->getFontEnum(index); + CTX::instance()->glFontTitle = dc.getFontName(index); + CTX::instance()->glFontEnumTitle = dc.getFontEnum(index); } if(FlGui::available() && (action & GMSH_GUI)){ FlGui::instance()->options->general.choice[6]->value(index); diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index f2388dcd8a407ea5bb1952cfdff3041447e61e41..f5a42c16181fd3430c6c40cb67946b44f6bfea0c 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -15,9 +15,8 @@ typedef unsigned long intptr_t; #include <FL/Fl_Tooltip.H> #include <FL/Fl_Shared_Image.H> #include <FL/Fl_File_Icon.H> -#include <FL/x.H> -#include <FL/gl.h> #include "FlGui.h" +#include "drawContextFltk.h" #include "graphicWindow.h" #include "optionWindow.h" #include "fieldWindow.h" @@ -62,136 +61,6 @@ void FlGui::wait(){ Fl::wait(); } // wait (at most time seconds) for any events, then process them void FlGui::wait(double time){ Fl::wait(time); } -class drawContextFltk : public drawContextGlobal{ - public: - void draw() - { - if(!FlGui::available()) return; - for(unsigned int i = 0; i < FlGui::instance()->graph.size(); i++){ - for(unsigned int j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++){ - FlGui::instance()->graph[i]->gl[j]->make_current(); - FlGui::instance()->graph[i]->gl[j]->redraw(); - // to initialize the camera distance from model - drawContext * ctx = FlGui::instance()->graph[i]->gl[j]->getDrawContext(); - ctx->camera.update(); - } - } - FlGui::instance()->check(); - } - void drawCurrentOpenglWindow(bool make_current) - { - if(!FlGui::available()) return; - openglWindow *gl = FlGui::instance()->getCurrentOpenglWindow(); - if(make_current) gl->make_current(); - gl->redraw(); - glFlush(); - FlGui::instance()->check(); - } - 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 (intptr_t)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::instance()->fontSize > 0){ - return CTX::instance()->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 setFont(int fontid, int fontsize) - { - gl_font(fontid, fontsize); - } - double getStringWidth(const char *str) - { - return gl_width(str); - } - int getStringHeight() - { - return gl_height(); - } - int getStringDescent() - { - return gl_descent(); - } - void drawString(const char *str) - { - gl_draw(str); - } - void resetFontTextures() - { -#if defined(__APPLE__) - gl_texture_pile_height(1); // force font texture recomputation -#endif - } -}; - static int globalShortcut(int event) { if(!FlGui::available()) return 0; diff --git a/Fltk/drawContextFltk.h b/Fltk/drawContextFltk.h new file mode 100644 index 0000000000000000000000000000000000000000..3cbcb259f230b51bb50156d8722bf0da6db6649a --- /dev/null +++ b/Fltk/drawContextFltk.h @@ -0,0 +1,147 @@ +// Gmsh - Copyright (C) 1997-2012 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to <gmsh@geuz.org>. + +#ifndef _DRAW_CONTEXT_FLTK_H_ +#define _DRAW_CONTEXT_FLTK_H_ + +#include <FL/x.H> +#include <FL/gl.h> +#include "FlGui.h" +#include "drawContext.h" +#include "graphicWindow.h" +#include "optionWindow.h" +#include "Context.h" + +class drawContextFltk : public drawContextGlobal{ + public: + void draw() + { + if(!FlGui::available()) return; + for(unsigned int i = 0; i < FlGui::instance()->graph.size(); i++){ + for(unsigned int j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++){ + FlGui::instance()->graph[i]->gl[j]->make_current(); + FlGui::instance()->graph[i]->gl[j]->redraw(); + // to initialize the camera distance from model + drawContext * ctx = FlGui::instance()->graph[i]->gl[j]->getDrawContext(); + ctx->camera.update(); + } + } + FlGui::instance()->check(); + } + void drawCurrentOpenglWindow(bool make_current) + { + if(!FlGui::available()) return; + openglWindow *gl = FlGui::instance()->getCurrentOpenglWindow(); + if(make_current) gl->make_current(); + gl->redraw(); + glFlush(); + FlGui::instance()->check(); + } + 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 (intptr_t)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::instance()->fontSize > 0){ + return CTX::instance()->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 setFont(int fontid, int fontsize) + { + gl_font(fontid, fontsize); + } + double getStringWidth(const char *str) + { + return gl_width(str); + } + int getStringHeight() + { + return gl_height(); + } + int getStringDescent() + { + return gl_descent(); + } + void drawString(const char *str) + { + gl_draw(str); + } + void resetFontTextures() + { +#if defined(__APPLE__) + gl_texture_pile_height(1); // force font texture recomputation +#endif + } +}; + +#endif diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h index 37febe748f3d1045917456018cdb1657556fb427..8c654ab1676e580438b70f5d48e8b6d4541d407b 100644 --- a/Graphics/drawContext.h +++ b/Graphics/drawContext.h @@ -193,7 +193,8 @@ class drawContext { void drawAxes(int mode, double tics[3], std::string format[3], std::string label[3], double bb[6], int mikado, double value_bb[6]); void drawAxes(int mode, double tics[3], std::string format[3], - std::string label[3], SBoundingBox3d &bb, int mikado, SBoundingBox3d &value_bb); + std::string label[3], SBoundingBox3d &bb, int mikado, + SBoundingBox3d &value_bb); void drawAxes(); void drawSmallAxes(); void drawTrackball(); @@ -205,7 +206,8 @@ class drawContext { void drawStringRight(const std::string &s); void drawString(const std::string &s, double style); void drawSphere(double R, double x, double y, double z, int n1, int n2, int light); - void drawEllipsoid(double x, double y, double z, float v0[3], float v1[3], float v2[3], int light); + void drawEllipsoid(double x, double y, double z, float v0[3], float v1[3], + float v2[3], int light); void drawEllipse(double x, double y, double z, float v0[3], float v1[3], int light); void drawSphere(double size, double x, double y, double z, int light); void drawCylinder(double width, double *x, double *y, double *z, int light);