Back to index

texmacs  1.0.7.15
xpm_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : xpm_widget.cpp
00004 * DESCRIPTION: Xpm widgets for output only
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 "image_files.hpp"
00014 #include "Widkit/basic_widget.hpp"
00015 #include "Widkit/layout.hpp"
00016 
00017 /******************************************************************************
00018 * Xpm widgets
00019 ******************************************************************************/
00020 
00021 class xpm_widget_rep: public basic_widget_rep {
00022   url  name;
00023   bool transparent;
00024   SI   dx, dy;
00025   int  ww, hh;
00026 
00027 public:
00028   xpm_widget_rep (url name, bool trans, int dx, int dy);
00029   operator tree ();
00030 
00031   void handle_get_size (get_size_event ev);
00032   void handle_repaint (repaint_event ev);
00033 };
00034 
00035 xpm_widget_rep::xpm_widget_rep (
00036   url name2, bool t2, int dx2, int dy2):
00037     basic_widget_rep (center), name (name2),
00038     transparent (t2), dx (dx2), dy (dy2)
00039 {
00040   xpm_size (name, ww, hh);
00041   ww= ((ww+1) >> 1) << 1;
00042   hh= ((hh+1) >> 1) << 1;
00043 }
00044 
00045 xpm_widget_rep::operator tree () {
00046   return tree (TUPLE, "xpm", as_string (name));
00047 }
00048 
00049 void
00050 xpm_widget_rep::handle_get_size (get_size_event ev) {
00051   ev->w = ww*PIXEL+ 2*dx;
00052   ev->h = hh*PIXEL+ 2*dy;
00053   abs_round (ev->w, ev->h);  
00054 }
00055 
00056 void
00057 xpm_widget_rep::handle_repaint (repaint_event ev) { (void) ev;
00058   renderer ren= win->get_renderer ();
00059   if (!transparent) layout_default (ren, -(w>>1), -(h>>1), w>>1, h>>1);
00060   ren->xpm (name, -(ww>>1)*PIXEL, (hh>>1)*PIXEL);
00061 }
00062 
00063 /******************************************************************************
00064 * Interface
00065 ******************************************************************************/
00066 
00067 wk_widget
00068 xpm_wk_widget (url name, bool transp) {
00069   return tm_new<xpm_widget_rep> (name, transp, PIXEL, PIXEL);
00070 }