Back to index

texmacs  1.0.7.15
decoration_boxes.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : misc.cpp
00004 * DESCRIPTION: Decoration boxes (mostly for use on the screen)
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 "Boxes/composite.hpp"
00013 #include "Boxes/construct.hpp"
00014 #include "scheme.hpp"
00015 
00016 bool in_presentation_mode ();
00017 
00018 /******************************************************************************
00019 * Specific boxes
00020 ******************************************************************************/
00021 
00022 struct specific_box_rep: public box_rep {
00023   box b;
00024   bool printer_flag;
00025   specific_box_rep (path ip, box b2, bool flag, font fn):
00026     box_rep (ip), b (b2), printer_flag (flag) {
00027       x1=x2=y1=0;
00028       y2=fn->yx;
00029       x3= b->x3; y3= b->y3;
00030       x4= b->x4; y4= b->y4;
00031     }
00032   operator tree () {
00033     return tuple ("specific", (tree) b, as_string (printer_flag)); }
00034   void display (renderer ren) {
00035     if (ren->is_printer () == printer_flag)
00036       if (printer_flag || !in_presentation_mode ()) {
00037        rectangles rs;
00038        b->redraw (ren, path (), rs);
00039       }
00040   }
00041 };
00042 
00043 /******************************************************************************
00044 * Flag boxes
00045 ******************************************************************************/
00046 
00047 struct flag_box_rep: public composite_box_rep {
00048   color light, old_bg;
00049   flag_box_rep (path ip, box b, SI h, SI lw, color dark, color light);
00050   operator tree () { return tree (TUPLE, "flag"); }
00051   void pre_display (renderer &ren);
00052   void post_display (renderer &ren);
00053 };
00054 
00055 void
00056 flag_box_rep::pre_display (renderer &ren) {
00057   old_bg= ren->get_background ();
00058   ren->set_background (light);
00059 }
00060 
00061 void
00062 flag_box_rep::post_display (renderer &ren) {
00063   ren->set_background (old_bg);
00064 }
00065 
00066 flag_box_rep::flag_box_rep (
00067   path ip, box b, SI h, SI lw, color dark, color light2):
00068   composite_box_rep (ip), light (light2)
00069 {
00070   SI sep= h/5, H= b->h() + 2*sep, w= b->w() + 2*sep, W= H/4;
00071   path dip= decorate_middle (ip);
00072   array<SI> x(5), y(5);
00073   x[0]= 0; y[0]= 0;
00074   x[1]= w; y[1]= 0;
00075   x[2]= w+W; y[2]= H/2;
00076   x[3]= w; y[3]= H;
00077   x[4]= 0; y[4]= H;
00078   insert (line_box (dip, 0, 0, 0, h, lw, dark), 0, 0);
00079   insert (polygon_box (dip, x, y, lw, light, dark), 0, h);
00080   insert (b, sep - b->x1, h + sep - b->y1);
00081   position ();
00082   finalize ();
00083 }
00084 
00085 /******************************************************************************
00086 * Info boxes
00087 ******************************************************************************/
00088 
00089 struct info_box_rep: public composite_box_rep {
00090   info_box_rep (path ip, SI h, SI lw, color dark, color light);
00091   operator tree () { return tree (TUPLE, "info"); }
00092 };
00093 
00094 info_box_rep::info_box_rep (
00095   path ip, SI h, SI lw, color dark, color light):
00096   composite_box_rep (ip)
00097 {
00098   SI d= h/5;
00099   path dip= decorate_middle (ip);
00100   array<SI> x(4), y(4);
00101   x[0]= 0; y[0]= -d;
00102   x[1]= d; y[1]= 0;
00103   x[2]= 0; y[2]= d;
00104   x[3]= -d; y[3]= 0;
00105   insert (line_box (dip, 0, 0, 0, h-d, lw, dark), 0, 0);
00106   insert (polygon_box (dip, x, y, lw, light, dark), 0, h);
00107   position ();
00108   finalize ();
00109 }
00110 
00111 /******************************************************************************
00112 * Scrollbar boxes
00113 ******************************************************************************/
00114 
00115 struct scrollbar_box_rep: public composite_box_rep {
00116   bool vertical;
00117   SI span;
00118   tree t;
00119   scrollbar_box_rep (path ip, box b, bool vertical2, SI span2, tree t2):
00120     composite_box_rep (ip), vertical (vertical2), span (span2), t (t2) {
00121       insert (b, 0, 0); position (); finalize (); }
00122   operator tree () { return tuple ("scrollbar", (tree) bs[0]); }
00123   tree action (tree type, SI x, SI y, SI delta);
00124 };
00125 
00126 tree
00127 scrollbar_box_rep::action (tree type, SI x, SI y, SI delta) {
00128   (void) type; (void) delta;
00129   tree u= t;
00130   if (vertical) {
00131     double p= 100.0;
00132     SI Y1= y1 + (span>>1);
00133     SI Y2= y2 - (span>>1);
00134     if (Y1 < Y2) p= 100.0 * ((double) (y-Y1)) / ((double) (Y2-Y1));
00135     p= min (100.0, max (0.0, p));
00136     u= tree (as_string (p) * "%");
00137   }
00138   else {
00139     double p= 0.0;
00140     SI X1= x1 + (span>>1);
00141     SI X2= x2 - (span>>1);
00142     if (X1 < X2) p= 100.0 * ((double) (x-X1)) / ((double) (X2-X1));
00143     p= max (0.0, min (100.0, p));
00144     u= tree (as_string (p) * "%");
00145   }
00146   if (u != t && is_accessible (obtain_ip (t)))
00147     {
00148       object fun= symbol_object ("tree-set");
00149       object cmd= list_object (fun, t, u);
00150       exec_delayed (scheme_cmd (cmd));
00151     }
00152   return "done";
00153 }
00154 
00155 /******************************************************************************
00156 * box construction routines
00157 ******************************************************************************/
00158 
00159 box
00160 specific_box (path ip, box b, bool printer_flag, font fn) {
00161   return tm_new<specific_box_rep> (ip, b, printer_flag, fn);
00162 }
00163 
00164 box flag_box (path ip, box b, SI h, SI lw, color dark, color light) {
00165   return tm_new<flag_box_rep> (ip, b, h, lw, dark, light);
00166 }
00167 
00168 box
00169 flag_box (path ip, string s, font fn, color dark, color light) {
00170   box b= text_box (decorate_right (ip), 0, s, fn, dark);
00171   return flag_box (ip, b, fn->wfn, fn->wline, dark, light);
00172 }
00173 
00174 box info_box (path ip, SI h, SI lw, color dark, color light) {
00175   return tm_new<info_box_rep> (ip, h, lw, dark, light);
00176 }
00177 
00178 box
00179 scrollbar_box (path ip, box b, bool vertical, SI span, tree t) {
00180   return tm_new<scrollbar_box_rep> (ip, b, vertical, span, t);
00181 }