Back to index

texmacs  1.0.7.15
grid_boxes.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : grid_boxes.cpp
00004 * DESCRIPTION: grid boxes for the graphics
00005 * COPYRIGHT  : (C) 2003  Henri Lesourd
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "env.hpp"
00013 #include "Graphics/grid.hpp"
00014 #include "Graphics/point.hpp"
00015 #include "Graphics/frame.hpp"
00016 #include "Boxes/graphics.hpp"
00017 #include "Boxes/composite.hpp"
00018 #include "Graphics/math_util.hpp"
00019 
00020 /******************************************************************************
00021 * Grid boxes
00022 ******************************************************************************/
00023 
00024 struct grid_box_rep: public box_rep {
00025   grid g;
00026   frame f;
00027   bool first_time;
00028   int ren_pixel;
00029   array<box> bs;
00030   SI un;
00031   grid_box_rep (
00032     path ip, grid g, frame f, SI un, point lim1, point lim2);
00033   void display (renderer ren);
00034   operator tree () { return (tree)g; }
00035   path find_lip () { return path (-1); }
00036   path find_rip () { return path (-1); }
00037   gr_selections graphical_select (SI x, SI y, SI dist);
00038   gr_selections graphical_select (SI x1, SI y1, SI x2, SI y2);
00039   int reindex (int i, int item, int n);
00040 };
00041 
00042 grid_box_rep::grid_box_rep (
00043   path ip2, grid g2, frame f2, SI un2, point lim1, point lim2):
00044     box_rep (ip2), g(g2), f(f2), un(un2)
00045 {
00046   first_time= true;
00047   point flim1= f(lim1), flim2= f(lim2);
00048   x1= x3= (SI) min (flim1[0], flim2[0]);
00049   y1= y3= (SI) min (flim1[1], flim2[1]);
00050   x2= x4= (SI) max (flim1[0], flim2[0]);
00051   y2= y4= (SI) max (flim1[1], flim2[1]);
00052 }
00053 
00054 void
00055 grid_box_rep::display (renderer ren) {
00056   int i;
00057   if (first_time || ren->pixel!=ren_pixel) {
00058     point p1= f [point (x1, y1)];
00059     point p2= f [point (x2, y2)];
00060     point l1= point (min (p1[0], p2[0]), min (p1[1], p2[1]));
00061     point l2= point (max (p1[0], p2[0]), max (p1[1], p2[1]));
00062     point e1= l1, e2= point (l1[0], l2[1]);
00063     point e3= l2, e4= point (l2[0], l1[1]);
00064     double L1, L2, L3, L4;
00065     L1= norm (e2 - e1);
00066     L2= norm (e3 - e2);
00067     L3= norm (e4 - e3);
00068     L4= norm (e1 - e4);
00069     point e1t= f (e1), e2t= f (e2);
00070     point e3t= f (e3), e4t= f (e4);
00071     double L1t, L2t, L3t, L4t;
00072     L1t= norm (e2t - e1t);
00073     L2t= norm (e3t - e2t);
00074     L3t= norm (e4t - e3t);
00075     L4t= norm (e1t - e4t);
00076     ASSERT (!fnull (L1t, 1e-6) && !fnull (L2t, 1e-6) &&
00077            !fnull (L3t, 1e-6) && !fnull (L4t, 1e-6),
00078            "one side of the grid has length zero");
00079     array<grid_curve> grads= g->get_curves (l1, l2);
00080 
00081     for (i=0; i<N(grads); i++) {
00082       curve c= f (grads[i]->c);
00083       bs << curve_box (
00084              decorate (ip), c, ren->pixel, named_color (grads[i]->col),
00085              array<bool> (0), 0, FILL_MODE_NONE, white, array<box> (0));
00086     }
00087     first_time= false;
00088     ren_pixel= ren->pixel;
00089   }
00090   for (i=0; i<N(bs); i++)
00091     bs[i]->display (ren);
00092 }
00093 
00094 gr_selections
00095 grid_box_rep::graphical_select (SI x, SI y, SI dist) {
00096   (void) x; (void) y; (void) dist;
00097   gr_selections res;
00098   return res;
00099 }
00100 
00101 gr_selections
00102 grid_box_rep::graphical_select (SI x1, SI y1, SI x2, SI y2) {
00103   (void) x1; (void) y1; (void) x2; (void) y2;
00104   gr_selections res;
00105   return res;
00106 }
00107 
00108 int
00109 grid_box_rep::reindex (int i, int item, int n) {
00110   (void) item; (void) n;
00111   return i;
00112 }
00113 
00114 /******************************************************************************
00115 * User interface
00116 ******************************************************************************/
00117 
00118 box
00119 grid_box (path ip, grid g, frame f, SI un, point lim1, point lim2) {
00120   return tm_new<grid_box_rep> (ip, g, f, un, lim1, lim2);
00121 }