Back to index

texmacs  1.0.7.15
tile_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tile_widget.cpp
00004 * DESCRIPTION: tile widgets
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
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 "renderer.hpp"
00013 #include "Widkit/attribute_widget.hpp"
00014 
00015 void abs_round (SI& x, SI& y);
00016 
00017 /******************************************************************************
00018 * Tiles
00019 ******************************************************************************/
00020 
00021 class tile_rep: public attribute_widget_rep {
00022 protected:
00023   int cols, rows;
00024 
00025 public:
00026   tile_rep (array<wk_widget> a, int cols);
00027   tile_rep (array<wk_widget> a, int cols, array<string> name);
00028   operator tree ();
00029 
00030   void handle_get_size (get_size_event ev);
00031   void handle_position (position_event ev);
00032   void handle_get_coord2 (get_coord2_event ev);
00033   void handle_set_coord2 (set_coord2_event ev);
00034 };
00035 
00036 tile_rep::tile_rep (array<wk_widget> a, int cols2):
00037   attribute_widget_rep (a, south_west),
00038   cols (max (1, cols2)), rows ((N(a)+cols-1)/cols) {}
00039 
00040 tile_rep::tile_rep (array<wk_widget> a, int cols2, array<string> n):
00041   attribute_widget_rep (a, n, south_west),
00042   cols (max (1, cols2)), rows ((N(a)+cols-1)/cols) {}
00043 
00044 tile_rep::operator tree () {
00045   int i;
00046   tree t (TUPLE, N(a)+2);
00047   t[0]= "tile";
00048   t[1]= as_string (cols);
00049   for (i=0; i<N(a); i++) t[i+2]= (tree) a[i];
00050   return t;
00051 }
00052 
00053 void
00054 tile_rep::handle_get_size (get_size_event ev) {
00055   int i;
00056   SI& w= ev->w;
00057   SI& h= ev->h;
00058 
00059   SI m1=0, m2=0, c1=0, c2=0;
00060   for (i=0; i<N(a); i++) {
00061     a[i] << get_coord2 ("extra width", c1, c2);
00062     m1= max (m1, c1); m2= max (m2, c2);
00063   }
00064   for (i=0; i<N(a); i++)
00065     a[i] << set_coord2 ("extra width", m1, m2);
00066 
00067   if (ev->mode==0) {
00068     SI ww= w, hh= h;
00069     this << get_size (ww, hh, 1);
00070     w= min (w, ww);
00071     h= min (h, hh);
00072     ww= w; hh= h;
00073     this << get_size (ww, hh, -1);
00074     w= max (w, ww);
00075     h= max (h, hh);
00076   }
00077   else {
00078     int i, ww=0, hh=0;
00079     for (i=0; i<N(a); i++) {
00080       SI www= w/cols, hhh= h/rows;
00081       abs_round (www, hhh);
00082       a[i] << get_size (www, hhh, ev->mode);
00083       ww= max (ww, www);
00084       hh= max (hh, hhh);
00085     }
00086     w= ww*cols+2*PIXEL; h= hh*rows+2*PIXEL;
00087   }
00088 }
00089 
00090 void
00091 tile_rep::handle_position (position_event ev) {
00092   (void) ev;
00093 
00094   int i;
00095   if (N(a)==0) return;
00096   for (i=0; i<N(a); i++) {
00097     int col= i%cols, row= (rows-1)-(i/cols);
00098     SI X1= (col*w)/cols;
00099     SI Y1= (row*h)/rows;
00100     SI X2= ((col+1)*w)/cols;
00101     SI Y2= ((row+1)*h)/rows;
00102     SI OX= (X1+X2)>>1;
00103     SI OY= (Y1+Y2)>>1;
00104     SI WX= X2-X1-2*PIXEL;
00105     SI HY= Y2-Y1-2*PIXEL;
00106     abs_round (OX, OY);
00107     abs_round (WX, HY);
00108     a[i] << emit_position (OX, OY, WX, HY, center);
00109   }
00110 }
00111 
00112 void
00113 tile_rep::handle_get_coord2 (get_coord2_event ev) {
00114   if (ev->which != "extra width") attribute_widget_rep::handle_get_coord2 (ev);
00115   else { ev->c1= 0; ev->c2= 0; }
00116 }
00117 
00118 void
00119 tile_rep::handle_set_coord2 (set_coord2_event ev) {
00120   if (ev->which != "extra width") attribute_widget_rep::handle_set_coord2 (ev);
00121 }
00122 
00123 /******************************************************************************
00124 * Interface
00125 ******************************************************************************/
00126 
00127 wk_widget
00128 tile (array<wk_widget> a, int cols) {
00129   return tm_new<tile_rep> (a, cols);
00130 }
00131 
00132 wk_widget
00133 tile (array<wk_widget> a, int cols, array<string> name) {
00134   return tm_new<tile_rep> (a, cols, name);
00135 }