~ubuntu-branches/ubuntu/intrepid/gmsh/intrepid

« back to all changes in this revision

Viewing changes to Fltk/Opengl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Emmet Hikory
  • Date: 2007-05-07 10:01:37 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070507100137-6j0rzz1ucbn0m2jt
Tags: 2.0.7-1ubuntu1
* Merged with Debian unstable.  Remaining Ubuntu changes:
  - Add .desktop file
  - Add icon
* Added XSBC-Original-Maintainer
* Removed Application Category from gmsh.desktop
* Link against GLU (fixes FTBFS)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: Opengl.cpp,v 1.57 2006/01/06 00:34:23 geuzaine Exp $
 
1
// $Id: Opengl.cpp,v 1.72 2006/12/12 01:39:15 geuzaine Exp $
2
2
//
3
 
// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 
3
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
23
23
#include "GmshUI.h"
24
24
#include "Numeric.h"
25
25
#include "Context.h"
26
 
#include "Geo.h"
27
 
#include "Mesh.h"
28
26
#include "Draw.h"
 
27
#include "SelectBuffer.h"
29
28
#include "GUI.h"
30
29
#include "gl2ps.h"
31
30
 
32
31
extern GUI *WID;
33
 
extern Mesh M;
34
32
extern Context_T CTX;
35
33
 
36
34
// Draw specialization
37
35
 
38
36
void SetOpenglContext(void)
39
37
{
 
38
  if(!WID) return;
40
39
  WID->make_opengl_current();
41
40
}
42
41
 
43
42
void Draw(void)
44
43
{
 
44
  if(!WID) return;
45
45
  WID->redraw_opengl();
46
46
}
47
47
 
69
69
 
70
70
void Draw_String(char *s, char *font_name, int font_enum, int font_size, int align)
71
71
{
72
 
  if(align > 0){
73
 
    // change the raster position only if not creating TeX files
74
 
    if(CTX.print.gl_fonts || (CTX.print.format != FORMAT_TEX)){
75
 
      GLboolean valid;
76
 
      glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
77
 
      if(valid == GL_TRUE){
78
 
        GLdouble pos[4];
79
 
        glGetDoublev(GL_CURRENT_RASTER_POSITION, pos);
80
 
        double x[3], w[3] = {pos[0], pos[1], pos[2]};
81
 
        gl_font(font_enum, font_size);
82
 
        float width = gl_width(s);
83
 
        float height = gl_height();
84
 
        switch(align){
85
 
        case 1: w[0] -= width/2.;                     break; // bottom center
86
 
        case 2: w[0] -= width;                        break; // bottom right
87
 
        case 3:                    w[1] -= height;    break; // top left
88
 
        case 4: w[0] -= width/2.;  w[1] -= height;    break; // top center
89
 
        case 5: w[0] -= width;     w[1] -= height;    break; // top right
90
 
        case 6:                    w[1] -= height/2.; break; // center left
91
 
        case 7: w[0] -= width/2.;  w[1] -= height/2.; break; // center center
92
 
        case 8: w[0] -= width;     w[1] -= height/2.; break; // center right
93
 
        default: break;
94
 
        }
95
 
        Viewport2World(w, x);
96
 
        glRasterPos3d(x[0], x[1], x[2]);
 
72
  if(CTX.printing && !CTX.print.text) return;
 
73
 
 
74
  // change the raster position only if not creating TeX files
 
75
  if(align > 0 && (!CTX.printing || CTX.print.format != FORMAT_TEX)){
 
76
    GLboolean valid;
 
77
    glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
 
78
    if(valid == GL_TRUE){
 
79
      GLdouble pos[4];
 
80
      glGetDoublev(GL_CURRENT_RASTER_POSITION, pos);
 
81
      double x[3], w[3] = {pos[0], pos[1], pos[2]};
 
82
      gl_font(font_enum, font_size);
 
83
      float width = gl_width(s);
 
84
      float height = gl_height();
 
85
      switch(align){
 
86
      case 1: w[0] -= width/2.;                     break; // bottom center
 
87
      case 2: w[0] -= width;                        break; // bottom right
 
88
      case 3:                    w[1] -= height;    break; // top left
 
89
      case 4: w[0] -= width/2.;  w[1] -= height;    break; // top center
 
90
      case 5: w[0] -= width;     w[1] -= height;    break; // top right
 
91
      case 6:                    w[1] -= height/2.; break; // center left
 
92
      case 7: w[0] -= width/2.;  w[1] -= height/2.; break; // center center
 
93
      case 8: w[0] -= width;     w[1] -= height/2.; break; // center right
 
94
      default: break;
97
95
      }
 
96
      Viewport2World(w, x);
 
97
      glRasterPos3d(x[0], x[1], x[2]);
98
98
    }
99
99
  }
100
100
  
101
 
  if(CTX.print.gl_fonts) {
 
101
  if(!CTX.printing){
102
102
    gl_font(font_enum, font_size);
103
103
    gl_draw(s);
104
104
  }
105
 
  else { // ps, pdf or *tex output
106
 
    if(CTX.print.format == FORMAT_JPEGTEX ||
107
 
       CTX.print.format == FORMAT_PNGTEX)
108
 
      return;
 
105
  else{
109
106
    if(CTX.print.format == FORMAT_TEX){
110
107
      char tmp[1024];
111
108
      SanitizeTeXString(s, tmp);
123
120
      }
124
121
      gl2psTextOpt(tmp, font_name, font_size, opt, 0.);
125
122
    }
126
 
    else
 
123
    else if(CTX.print.eps_quality && (CTX.print.format == FORMAT_PS ||
 
124
                                      CTX.print.format == FORMAT_EPS ||
 
125
                                      CTX.print.format == FORMAT_PDF ||
 
126
                                      CTX.print.format == FORMAT_SVG)){
127
127
      gl2psText(s, font_name, font_size);
 
128
    }
 
129
    else{
 
130
      gl_font(font_enum, font_size);
 
131
      gl_draw(s);
 
132
    }
128
133
  }
129
134
}
130
135
 
163
168
 
164
169
void Draw_OnScreenMessages()
165
170
{
 
171
  if(!WID) return;
 
172
 
166
173
  glColor4ubv((GLubyte *) & CTX.color.text);
167
174
  gl_font(CTX.gl_font_enum, CTX.gl_fontsize);
168
175
  double h = gl_height();
181
188
 
182
189
// Select entity routine
183
190
 
184
 
char SelectEntity(int type, int *n,
185
 
                  Vertex *v[SELECTION_MAX_HITS], 
186
 
                  Curve *c[SELECTION_MAX_HITS], 
187
 
                  Surface *s[SELECTION_MAX_HITS])
 
191
char SelectEntity(int type, 
 
192
                  std::vector<GVertex*> &vertices,
 
193
                  std::vector<GEdge*> &edges,
 
194
                  std::vector<GFace*> &faces,
 
195
                  std::vector<GRegion*> &regions,
 
196
                  std::vector<MElement*> &elements)
188
197
{
 
198
  if(!WID) return 'q';
 
199
 
189
200
  WID->g_opengl_window->take_focus(); // force keyboard focus in GL window 
190
201
  WID->g_opengl_window->SelectionMode = true; // enable lasso selection
191
202
 
194
205
  WID->quit_selection = 0;
195
206
  WID->end_selection = 0;
196
207
  WID->undo_selection = 0;
 
208
  WID->invert_selection = 0;
197
209
 
198
210
  while(1) {
199
 
    *n = 0;
200
 
    for(int i = 0; i < SELECTION_MAX_HITS; i++){
201
 
      v[i] = NULL;
202
 
      c[i] = NULL;
203
 
      s[i] = NULL;
204
 
    }
205
 
 
 
211
    vertices.clear();
 
212
    edges.clear();
 
213
    faces.clear();
 
214
    regions.clear();
 
215
    elements.clear();
206
216
    WID->wait();
207
217
    if(WID->quit_selection) {
208
218
      WID->selection = ENT_NONE;
223
233
    }
224
234
    if(WID->try_selection) {
225
235
      bool add = (WID->try_selection > 0) ? true : false;
226
 
      bool multi = (WID->try_selection > 1) ? true : false;
 
236
      bool multi = (abs(WID->try_selection) > 1) ? true : false;
227
237
      WID->try_selection = 0;
228
238
      if(WID->selection == ENT_NONE){ // just report the mouse click
229
239
        WID->g_opengl_window->SelectionMode = false;
230
240
        return 'c';
231
241
      }
232
 
      else{
233
 
        *n = Process_SelectionBuffer(WID->selection, multi,
 
242
      else if(ProcessSelectionBuffer(WID->selection, multi, true,
234
243
                                     WID->try_selection_xywh[0],
235
244
                                     WID->try_selection_xywh[1], 
236
245
                                     WID->try_selection_xywh[2],
237
246
                                     WID->try_selection_xywh[3], 
238
 
                                     v, c, s, &M);
239
 
        if(*n){
240
 
          if(add){
241
 
            for(int i = 0; i < *n; i++)
242
 
              HighlightEntity(v[i], c[i], s[i], 1);
243
 
            Draw();
244
 
          }
245
 
          // don't call ZeroHighlight here if we (try to) deselect:
246
 
          // deselection is not supported in all cases, so it's better
247
 
          // to de-highlight the entities in the callback
248
 
          WID->selection = ENT_NONE;
249
 
          WID->g_opengl_window->SelectionMode = false;
250
 
          if(add)
251
 
            return 'l';
252
 
          else
253
 
            return 'r';
254
 
        }
 
247
                                     vertices, edges, faces, regions,
 
248
                                     elements)){
 
249
        WID->selection = ENT_NONE;
 
250
        WID->g_opengl_window->SelectionMode = false;
 
251
        if(add)
 
252
          return 'l';
 
253
        else
 
254
          return 'r';
255
255
      }
256
256
    }
257
257
  }