From c4e9fdda792e8c2dbd8b917ffac99a1be22fb678 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 3 Dec 2008 08:07:46 +0000 Subject: [PATCH] fix on screen msg for multi-views --- Fltk/Draw.cpp | 26 ----------------------- Fltk/Draw.h | 1 - Fltk/GUI.cpp | 46 +++++++++++++++++++++------------------- Fltk/GUI.h | 7 +++--- Fltk/menuWindow.cpp | 3 ++- Fltk/openglWindow.cpp | 27 +++++++++++++++++++++++ Fltk/openglWindow.h | 7 ++++-- Graphics/drawContext.cpp | 1 - 8 files changed, 62 insertions(+), 56 deletions(-) diff --git a/Fltk/Draw.cpp b/Fltk/Draw.cpp index 579062a7fd..c4a3070193 100644 --- a/Fltk/Draw.cpp +++ b/Fltk/Draw.cpp @@ -173,32 +173,6 @@ void Draw_String(std::string s, double style) } } -void Draw_OnScreenMessages(int index) -{ - if(!GUI::available()) return; - - glColor4ubv((GLubyte *) & CTX.color.text); - gl_font(CTX.gl_font_enum, CTX.gl_fontsize); - double h = gl_height(); - - if(index >= 0 && index < GUI::instance()->graph.size()){ - drawContext *ctx = GUI::instance()->graph[index]->gl->getDrawContext(); - - if(strlen(GUI::instance()->onscreen_buffer[0])){ - double w = gl_width(GUI::instance()->onscreen_buffer[0]); - glRasterPos2d(ctx->viewport[2] / 2. - w / 2., - ctx->viewport[3] - 1.2 * h); - gl_draw(GUI::instance()->onscreen_buffer[0]); - } - if(strlen(GUI::instance()->onscreen_buffer[1])){ - double w = gl_width(GUI::instance()->onscreen_buffer[1]); - glRasterPos2d(ctx->viewport[2] / 2. - w / 2., - ctx->viewport[3] - 2.4 * h); - gl_draw(GUI::instance()->onscreen_buffer[1]); - } - } -} - void GetStoredViewport(int viewport[4], int index) { if(!GUI::available()) return; diff --git a/Fltk/Draw.h b/Fltk/Draw.h index d6d8463407..1e171a44fa 100644 --- a/Fltk/Draw.h +++ b/Fltk/Draw.h @@ -19,7 +19,6 @@ 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 Draw_OnScreenMessages(int index=0); void GetStoredViewport(int viewport[4], int index=0); void Viewport2World(double win[3], double xyz[3]); diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index 507202b755..6ace1a0aff 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -49,10 +49,6 @@ static int globalShortcut(int event) GUI::GUI(int argc, char **argv) { - // initialize on-screen message buffer - onscreen_buffer[0][0] = '\0'; - onscreen_buffer[1][0] = '\0'; - // set X display if(strlen(CTX.display)) Fl::display(CTX.display); @@ -554,6 +550,24 @@ void GUI::resetVisibility() visibility_cb(NULL, NULL); } +int GUI::getLastGraphIndex() +{ + unsigned int index = 0; + if(graph.size() > 1) + for(Fl_Window *w = Fl::first_window(); w; w = Fl::next_window(w)) + for(index = 0; index < GUI::instance()->graph.size(); index++) + if(w == graph[index]->win || w == graph[index]->gl) + return index; + return 0; +} + +char GUI::selectEntity(int type) +{ + return graph[getLastGraphIndex()]->gl->selectEntity + (type, selectedVertices, selectedEdges, selectedFaces, selectedRegions, + selectedElements); +} + void GUI::setStatus(const char *msg, int num) { if(num == 0 || num == 1){ @@ -566,15 +580,17 @@ void GUI::setStatus(const char *msg, int num) } } else if(num == 2){ + int index = getLastGraphIndex(); int n = strlen(msg); int i = 0; while(i < n) if(msg[i++] == '\n') break; - strncpy(onscreen_buffer[0], msg, sizeof(onscreen_buffer[0]) - 1); + graph[index]->gl->screenMessage[0] = std::string(msg); + if(i) + graph[index]->gl->screenMessage[0].resize(i - 1); if(i < n) - strncpy(onscreen_buffer[1], &msg[i], sizeof(onscreen_buffer[1]) - 1); + graph[index]->gl->screenMessage[1] = std::string(&msg[i]); else - onscreen_buffer[1][0] = '\0'; - onscreen_buffer[0][i-1] = '\0'; + graph[index]->gl->screenMessage[1].clear(); Draw(); } } @@ -621,20 +637,6 @@ void GUI::callForSolverPlugin(int dim) if(sp) sp->popupPropertiesForPhysicalEntity(dim); } -char GUI::selectEntity(int type) -{ - unsigned int index = 0; - if(graph.size() > 1) - for(Fl_Window *w = Fl::first_window(); w; w = Fl::next_window(w)) - for(index = 0; index < GUI::instance()->graph.size(); index++) - if(w == graph[index]->win || w == graph[index]->gl) - goto done; - done: - return graph[index]->gl->selectEntity - (type, selectedVertices, selectedEdges, selectedFaces, selectedRegions, - selectedElements); -} - // Callbacks void hide_cb(Fl_Widget *w, void *data) diff --git a/Fltk/GUI.h b/Fltk/GUI.h index bcbb0109db..23cc182895 100644 --- a/Fltk/GUI.h +++ b/Fltk/GUI.h @@ -43,7 +43,6 @@ class GUI{ int _fontsize; static GUI *_instance; public: - char onscreen_buffer[2][256]; std::vector<GVertex*> selectedVertices; std::vector<GEdge*> selectedEdges; std::vector<GFace*> selectedFaces; @@ -97,12 +96,14 @@ class GUI{ void resetVisibility(); // store current window positions and sizes in CTX void storeCurrentWindowsInfo(); + // get the index of the last graphic window that received an event + int getLastGraphIndex(); + // select an entity in the most recent graphic window + char selectEntity(int type); // display status message void setStatus(const char *msg, int num); // create the window for physical context dependant definitions void callForSolverPlugin(int dim); - // select an entity in the most recent graphic window - char selectEntity(int type); }; // callbacks diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp index 3be33213a3..ade5888027 100644 --- a/Fltk/menuWindow.cpp +++ b/Fltk/menuWindow.cpp @@ -1230,7 +1230,8 @@ static void action_point_line_surface_volume(int action, int mode, const char *w add_physical(what, List1, CTX.filename); break; case 8: - add_charlength(List1, CTX.filename, GUI::instance()->meshContext->input[0]->value()); + add_charlength(List1, CTX.filename, + GUI::instance()->meshContext->input[0]->value()); break; case 9: add_recosurf(List1, CTX.filename); diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp index 455f17bbc6..674d6f872e 100644 --- a/Fltk/openglWindow.cpp +++ b/Fltk/openglWindow.cpp @@ -86,6 +86,31 @@ openglWindow::~openglWindow() delete _ctx; } +void openglWindow::drawScreenMessage() +{ + if(screenMessage[0].empty() && screenMessage[1].empty()) + return; + + glColor4ubv((GLubyte *) & CTX.color.text); + gl_font(CTX.gl_font_enum, CTX.gl_fontsize); + double h = gl_height(); + + if(screenMessage[0].size()){ + const char *txt = screenMessage[0].c_str(); + double w = gl_width(txt); + glRasterPos2d(_ctx->viewport[2] / 2. - w / 2., + _ctx->viewport[3] - 1.2 * h); + gl_draw(txt); + } + if(screenMessage[1].size()){ + const char *txt = screenMessage[1].c_str(); + double w = gl_width(txt); + glRasterPos2d(_ctx->viewport[2] / 2. - w / 2., + _ctx->viewport[3] - 2.4 * h); + gl_draw(txt); + } +} + void openglWindow::draw() { static int locked = 0; @@ -163,6 +188,7 @@ void openglWindow::draw() glVertex3d(_point[0], _point[1], _point[2]); glEnd(); _ctx->draw2d(); + drawScreenMessage(); CTX.mesh.draw = 1; CTX.post.draw = 1; } @@ -171,6 +197,7 @@ void openglWindow::draw() ClearOpengl(); _ctx->draw3d(); _ctx->draw2d(); + drawScreenMessage(); } locked = 0; diff --git a/Fltk/openglWindow.h b/Fltk/openglWindow.h index 730b393567..e8d88c559e 100644 --- a/Fltk/openglWindow.h +++ b/Fltk/openglWindow.h @@ -7,6 +7,7 @@ #define _OPENGL_WINDOW_H_ #include <vector> +#include <string> #include <FL/Fl_Gl_Window.H> #include <FL/Fl_Box.H> #include "drawContext.h" @@ -47,8 +48,7 @@ class openglWindow : public Fl_Gl_Window { drawContext *_ctx; double _point[3]; int _selection, _trySelection, _trySelectionXYWH[4]; - void draw(); - int handle(int); + void drawScreenMessage(); bool processSelectionBuffer(int type, bool multipleSelection, bool meshSelection, int x, int y, int w, int h, @@ -57,9 +57,12 @@ class openglWindow : public Fl_Gl_Window { std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, std::vector<MElement*> &elements); + void draw(); + int handle(int); public: bool addPointMode, lassoMode, selectionMode; int endSelection, undoSelection, invertSelection, quitSelection; + std::string screenMessage[2]; openglWindow(int x, int y, int w, int h, const char *l=0); ~openglWindow(); drawContext *getDrawContext(){ return _ctx; } diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp index 2995673792..1be038183c 100644 --- a/Graphics/drawContext.cpp +++ b/Graphics/drawContext.cpp @@ -199,7 +199,6 @@ void drawContext::draw2d() drawGraph2d(); drawText2d(); - Draw_OnScreenMessages(); if(CTX.post.draw) drawScales(); if(CTX.small_axes) -- GitLab