From 4aae60621793a8861cb11a6b047b8787ce98b0fb Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 4 Feb 2001 10:23:56 +0000
Subject: [PATCH] XOR Zoom

---
 Fltk/Colorbar_Window.cpp |  31 ++++-----
 Fltk/GUI.cpp             |   4 +-
 Fltk/Main.cpp            |   6 +-
 Fltk/Message.cpp         |   4 +-
 Fltk/Opengl_Window.cpp   | 140 +++++++++++++++++++++------------------
 Graphics/Iso.cpp         |   5 +-
 Graphics/Post.cpp        |  11 ++-
 README                   |   4 +-
 8 files changed, 109 insertions(+), 96 deletions(-)

diff --git a/Fltk/Colorbar_Window.cpp b/Fltk/Colorbar_Window.cpp
index 65b58c2205..2d6567c0d1 100644
--- a/Fltk/Colorbar_Window.cpp
+++ b/Fltk/Colorbar_Window.cpp
@@ -1,4 +1,4 @@
-// $Id: Colorbar_Window.cpp,v 1.5 2001-02-03 15:55:18 geuzaine Exp $
+// $Id: Colorbar_Window.cpp,v 1.6 2001-02-04 10:23:56 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -240,12 +240,12 @@ void Colorbar_Window::redraw_range(int a, int b){
    fl_font(FL_HELVETICA, font_height);
    fl_color(FL_WHITE);
    if (help_flag){
-     int i=0, xx=11*font_height;
+     int i=0, xx=13*font_height;
      fl_draw("1, 2, ..., 6", 10,10+(i+1)*font_height); 
      fl_draw(    "select predefined colormap", xx,10+(i+1)*font_height); i++;
      fl_draw("mouse1", 10,10+(i+1)*font_height); 
      fl_draw(    "draw red or hue channel", xx,10+(i+1)*font_height); i++;
-     fl_draw("mouse2", 10,10+(i+1)*font_height); 
+     fl_draw("mouse2 or Shift+mouse1", 10,10+(i+1)*font_height); 
      fl_draw(    "draw green or saturation channel", xx,10+(i+1)*font_height); i++;
      fl_draw("mouse3", 10,10+(i+1)*font_height); 
      fl_draw(    "draw blue or value channel", xx,10+(i+1)*font_height); i++;
@@ -482,16 +482,15 @@ int Colorbar_Window::handle(int event){
       move_marker = 1;
 
     // determine which curve to modify
-    if (Fl::event_state(FL_CTRL)) {
+    if (Fl::event_state(FL_CTRL))
       p4 = 1;
-    }
-    else {
-      switch(ibut){
-      case 1 : p1 = 1 ; break ;
-      case 2 : p2 = 1 ; break ;
-      case 3 : p3 = 1 ; break ;
-      }
-    }
+    else if(ibut == 1 && !Fl::event_state(FL_SHIFT))
+      p1 = 1 ;
+    else if(ibut == 2 ||
+	    ibut == 1 && Fl::event_state(FL_SHIFT))
+      p2 = 1 ;
+    else
+      p3 = 1 ;
     pentry = x_to_index(xpos);
     modify = 1;
     break;
@@ -500,11 +499,9 @@ int Colorbar_Window::handle(int event){
     ibut = Fl::event_button();
     xpos = Fl::event_x();
     ypos = Fl::event_y();
-    switch(ibut){
-    case 1 : p1 = 0 ; break ;
-    case 2 : p2 = 0 ; break ;
-    case 3 : p3 = 0 ; break ;
-    }
+    p1 = 0 ;
+    p2 = 0 ;
+    p3 = 0 ;
     p4 = 0;
     break;
 
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 4145871159..88344aef43 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.35 2001-02-03 18:33:45 geuzaine Exp $
+// $Id: GUI.cpp,v 1.36 2001-02-04 10:23:56 geuzaine Exp $
 
 // To make the interface as visually consistent as possible, please:
 // - use the BH, BW, WB, IW values for button heights/widths, window borders, etc.
@@ -1696,7 +1696,7 @@ void GUI::create_view_window(int num){
   if(!init_view_window){
     init_view_window = 1 ;
 
-    int width = 32*CTX.fontsize;
+    int width = 34*CTX.fontsize;
     int height = 5*WB+7*BH + 7*CTX.fontsize;
     
     view_window = new Fl_Window(width,height);
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index d534f3da79..62127d1c8d 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -1,4 +1,4 @@
-// $Id: Main.cpp,v 1.14 2001-02-03 18:33:45 geuzaine Exp $
+// $Id: Main.cpp,v 1.15 2001-02-04 10:23:56 geuzaine Exp $
 
 #include <signal.h>
 
@@ -20,10 +20,6 @@
 
 GUI *WID = NULL;
 
-#ifdef __CYGWIN__
- WinMainCRTStartup() { mainCRTStartup(); }
-#endif
-
 int main(int argc, char *argv[]){
   int     i, nbf;
  
diff --git a/Fltk/Message.cpp b/Fltk/Message.cpp
index d33ab0c7a1..fc4f3aaa8c 100644
--- a/Fltk/Message.cpp
+++ b/Fltk/Message.cpp
@@ -1,4 +1,4 @@
-// $Id: Message.cpp,v 1.10 2001-01-13 15:48:31 geuzaine Exp $
+// $Id: Message.cpp,v 1.11 2001-02-04 10:23:56 geuzaine Exp $
 
 #include <signal.h>
 #ifndef WIN32
@@ -109,7 +109,7 @@ void Msg(int level, char *fmt, ...){
     }
     else{
       strcpy(buff1, "@C1");
-      if(str && window<0) strcat(buff1, str);
+      if(str) strcat(buff1, str);
       vsprintf(buff2, fmt, args); 
       strcat(buff1,buff2);
       fprintf(stderr, "%s\n", &buff1[3]);
diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp
index dfe380ce78..583ef65e4d 100644
--- a/Fltk/Opengl_Window.cpp
+++ b/Fltk/Opengl_Window.cpp
@@ -1,4 +1,4 @@
-// $Id: Opengl_Window.cpp,v 1.9 2001-02-03 13:10:26 geuzaine Exp $
+// $Id: Opengl_Window.cpp,v 1.10 2001-02-04 10:23:56 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -22,6 +22,9 @@ void Filter_SelectionBuffer(int n, GLuint *typ, GLuint *ient, Vertex **thev,
 void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2,
             GLdouble Xc1, GLdouble Xc2, GLdouble Yc1, GLdouble Yc2);
 
+static int    ZOOM = 0 ;
+static double ZOOM_X0, ZOOM_Y0, ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2;
+
 void Opengl_Window::draw() {
   if(!valid()){
     valid(1);
@@ -37,42 +40,56 @@ void Opengl_Window::draw() {
     glViewport(CTX.viewport[0], CTX.viewport[1],
 	       CTX.viewport[2], CTX.viewport[3]);
   }
-  Orthogonalize(0,0);
-  glClearColor(UNPACK_RED(CTX.color.bg)/255.,
-               UNPACK_GREEN(CTX.color.bg)/255.,
-               UNPACK_BLUE(CTX.color.bg)/255.,
-               0.);
-  glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
-  Draw3d();
-  Draw2d();
+  if(!ZOOM){
+    Orthogonalize(0,0);
+    glClearColor(UNPACK_RED(CTX.color.bg)/255.,
+		 UNPACK_GREEN(CTX.color.bg)/255.,
+		 UNPACK_BLUE(CTX.color.bg)/255.,
+		 0.);
+    glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
+    Draw3d();
+    Draw2d();
+  }
+  else{
+    glPopMatrix();
+    glDisable(GL_DEPTH_TEST);
+    glDisable(GL_LIGHTING);
+    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.);
+    glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
+    glEnable(GL_BLEND);
+    glBegin(GL_LINE_STRIP);
+    glVertex2d(ZOOM_X0, ZOOM_Y0);
+    glVertex2d(ZOOM_X1, ZOOM_Y0);
+    glVertex2d(ZOOM_X1, ZOOM_Y1);
+    glVertex2d(ZOOM_X0, ZOOM_Y1);
+    glVertex2d(ZOOM_X0, ZOOM_Y0);
+    glEnd();
+    glBegin(GL_LINE_STRIP);
+    glVertex2d(ZOOM_X0, ZOOM_Y0);
+    glVertex2d(ZOOM_X2, ZOOM_Y0);
+    glVertex2d(ZOOM_X2, ZOOM_Y2);
+    glVertex2d(ZOOM_X0, ZOOM_Y2);
+    glVertex2d(ZOOM_X0, ZOOM_Y0);
+    glEnd();
+    glDisable(GL_BLEND);
+    glEnable(GL_DEPTH_TEST);
+    glPopMatrix();
+    glMatrixMode(GL_PROJECTION);
+    glPopMatrix();
+    glMatrixMode(GL_MODELVIEW);
+    ZOOM = 0;
+  }
 }
 
-static double O1,O2,O3,O4;
-
 void Opengl_Window::draw_overlay() {
-  /*
-  if(!valid()){
-    valid(1);
-    CTX.viewport[0] = 0 ; CTX.viewport[1] = 0 ;
-    CTX.viewport[2] = w() ; CTX.viewport[3] = h() ;
-    glViewport(CTX.viewport[0], CTX.viewport[1],
-	       CTX.viewport[2], CTX.viewport[3]);
-  }
-  Orthogonalize(0,0);
-  glClearIndex(0);
-  glClear(GL_COLOR_BUFFER_BIT);  
-  glLineWidth(1.);
-  glClearIndex(0);
-  glClear(GL_COLOR_BUFFER_BIT);  
-  glIndexi((CTX.color.bg<CTX.color.fg)?FL_WHITE:FL_BLACK);
-  glBegin(GL_LINE_STRIP);
-  glVertex2d(O1, O2);
-  glVertex2d(O1+O3, O2);
-  glVertex2d(O1+O3, O2+O4);
-  glVertex2d(O1, O2+O4);
-  glVertex2d(O1, O2);
-  glEnd();
-  */
 }
 
 void Opengl_Window::clear_overlay() {
@@ -89,8 +106,7 @@ int Opengl_Window::handle(int event) {
   static int      xpos, ypos, xmov, ymov, ibut, hits;
   static int      ZoomClick=0, FirstClick=0;
   static GLdouble xc1, yc1, xc2, yc2, xt1, yt1, xscale1, yscale1;
-  static GLdouble xb, yb, xc, yc, xe, ye, xz, yz;
-  static GLdouble movzx, movzy;
+  static GLdouble xb, yb, xc, yc, xe, ye;
   static Vertex   *v=NULL, *ov;
   static Curve    *c=NULL, *oc;
   static Surface  *s=NULL, *os;
@@ -171,15 +187,14 @@ int Opengl_Window::handle(int event) {
     ymov = Fl::event_y() - ypos;
 
     if(ZoomClick) {
-      printf("should draw the zoom... %d %d %d %d\n", xpos, ypos, xmov, ymov);
-      xz = CTX.vxmin + ((double)Fl::event_x()/(double)w()) * (CTX.vxmax - CTX.vxmin);
-      yz = CTX.vymax - ((double)Fl::event_y()/(double)h()) * (CTX.vymax - CTX.vymin);
-      movzx = xz - xb; movzy = yz - yb;
-      O1 = xb;
-      O2 = yb;
-      O3 = movzx;
-      O4 = movzx;
-      redraw_overlay();
+      ZOOM_X0 = xb;
+      ZOOM_Y0 = yb;
+      ZOOM_X1 = CTX.vxmin + ((double)xpos/(double)w()) * (CTX.vxmax - CTX.vxmin);
+      ZOOM_Y1 = CTX.vymax - ((double)ypos/(double)h()) * (CTX.vymax - CTX.vymin);
+      ZOOM_X2 = CTX.vxmin + ((double)Fl::event_x()/(double)w()) * (CTX.vxmax - CTX.vxmin);
+      ZOOM_Y2 = CTX.vymax - ((double)Fl::event_y()/(double)h()) * (CTX.vymax - CTX.vymin);
+      ZOOM = 1;
+      redraw();
     }
     else {
       clear_overlay();
@@ -247,33 +262,30 @@ int Opengl_Window::handle(int event) {
   case FL_MOVE:
     xmov = Fl::event_x()-xpos;
     ymov = Fl::event_y()-ypos;
-    WID->make_opengl_current();
-    Process_SelectionBuffer(Fl::event_x(), Fl::event_y(), &hits, ii, jj);
-    ov = v; oc = c; os = s; v = NULL; c = NULL; s = NULL;
-    Filter_SelectionBuffer(hits,ii,jj,&v,&c,&s,&M);
 
-    if(ov != v || oc != c || os != s) { 
-      BeginHighlight();
-      HighlightEntity(v,c,s,0);
-      EndHighlight(0);
+    if(ZoomClick) {
+      ZOOM_X0 = xb;
+      ZOOM_Y0 = yb;
+      ZOOM_X1 = CTX.vxmin + ((double)xpos/(double)w()) * (CTX.vxmax - CTX.vxmin);
+      ZOOM_Y1 = CTX.vymax - ((double)ypos/(double)h()) * (CTX.vymax - CTX.vymin);
+      ZOOM_X2 = CTX.vxmin + ((double)Fl::event_x()/(double)w()) * (CTX.vxmax - CTX.vxmin);
+      ZOOM_Y2 = CTX.vymax - ((double)Fl::event_y()/(double)h()) * (CTX.vymax - CTX.vymin);
+      ZOOM = 1;
+      redraw();
     }
-
-#if 0
-    // l'overlay ne marche pas, meme dans les demos de fltk!
-    // soumettre un bug ?
-    if(ov != v || oc != c || os != s) { 
-      WID->make_overlay_current();
+    else {
+      WID->make_opengl_current();
+      Process_SelectionBuffer(Fl::event_x(), Fl::event_y(), &hits, ii, jj);
+      ov = v; oc = c; os = s; v = NULL; c = NULL; s = NULL;
+      Filter_SelectionBuffer(hits,ii,jj,&v,&c,&s,&M);
+      
       if(ov != v || oc != c || os != s) { 
-	glClearIndex(0);
-	glClear(GL_COLOR_BUFFER_BIT);  
-	glIndexi((CTX.color.bg<CTX.color.fg)?FL_WHITE:FL_BLACK);
 	BeginHighlight();
 	HighlightEntity(v,c,s,0);
 	EndHighlight(0);
       }
-      WID->make_opengl_current();
     }
-#endif
+
     xpos += xmov; 
     ypos += ymov; 
     return 1;
diff --git a/Graphics/Iso.cpp b/Graphics/Iso.cpp
index 9fe7c8ff83..9d29d8b495 100644
--- a/Graphics/Iso.cpp
+++ b/Graphics/Iso.cpp
@@ -1,4 +1,4 @@
-// $Id: Iso.cpp,v 1.7 2001-01-29 22:33:41 remacle Exp $
+// $Id: Iso.cpp,v 1.8 2001-02-04 10:23:56 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "Mesh.h"
@@ -62,6 +62,9 @@ void CutTriangle1D(double *X, double *Y, double *Z, double *Val,
 
 }
 
+// Il faut refaire cette routine pour que l'orientation des elements
+// soit respectee.
+
 void CutTriangle2D(double *X, double *Y, double *Z, double *Val, 
                    double V1, double V2, double Vmin, double Vmax,
                    double *Xp2, double *Yp2, double *Zp2, int *Np2, double *Vp2){
diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp
index c29750d21f..902d8dfb3c 100644
--- a/Graphics/Post.cpp
+++ b/Graphics/Post.cpp
@@ -1,4 +1,4 @@
-// $Id: Post.cpp,v 1.12 2001-01-29 22:33:41 remacle Exp $
+// $Id: Post.cpp,v 1.13 2001-02-04 10:23:56 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -114,9 +114,14 @@ void Draw_Post (void) {
 	  glEnable(GL_POLYGON_OFFSET_FILL) ;
 
         // force this
-        if(v->IntervalsType == DRAW_POST_CONTINUOUS)
+        if(v->IntervalsType == DRAW_POST_CONTINUOUS){
           glShadeModel(GL_SMOOTH); 
-        
+	  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
+        }
+	else{// there is a bug in CutTriangle2D!! See Iso.cpp
+	  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
+	}
+
         switch(v->RangeType){
         case DRAW_POST_DEFAULT : ValMin = v->Min ; ValMax = v->Max ; break;
         case DRAW_POST_CUSTOM  : ValMin = v->CustomMin ; ValMax = v->CustomMax ; break;
diff --git a/README b/README
index a938aea863..776c13b51b 100644
--- a/README
+++ b/README
@@ -2,8 +2,8 @@
 Some easy rules to make the code easy to read/debug/maintain:
 
 - *please* enable full warnings for your compiler (e.g. gcc -Wall)
-- *always* use Msg() to print information/erros/etc.
-- indent your files and suppress the tabs (untabify)
+- *always* use Msg() to print information/errors/etc.
+- indent your files and, if working on Windows, suppress the tabs (untabify)
 
 
 To download the latset full source by CVS, type
-- 
GitLab