00001 #ifndef CANVAS_CLASS 00002 #define CANVAS_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : canvas * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * Models a rectangular worker object on which paintable objects can * 00012 * be placed. * 00013 * * 00014 ******************************************************************************* 00015 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00016 * redistribute it and/or modify it under the terms of the GNU General Public * 00017 * License as published by the Free Software Foundation; either version 2 of * 00018 * the License or (at your option) any later version. This is online at: * 00019 * http://www.fsf.org/copyleft/gpl.html * 00020 * Please send any updates to: fred@gruntose.com * 00021 \*****************************************************************************/ 00022 00023 #include "manager.h" 00024 #include "picture.h" 00025 #include "resources.h" 00026 #include "worker.h" 00027 00028 const c_rectangle default_world = c_rectangle(0, 0, 1000, 1000); 00029 00030 class WP_PASSIVE_CLASS_STYLE canvas : public worker, private c_rectangle_warper 00031 { 00032 public: 00033 canvas(manager &root, const c_rectangle &initial_size, 00034 const c_rectangle &initial_world = default_world, 00035 const color &foreground = colors::WHITE, 00036 const color &background = colors::BLACK, 00037 origin_vertex world_corner = BOTTOM_LEFT); 00038 // Creates a canvas attached to the "root". The location of the canvas 00039 // in universal coordinates is "position". The world coordinate system 00040 // is specified by "initial_world", where an implicit ordering is used 00041 // to define the coordinate system: the first vertex of the rectangle is 00042 // the origin, while the second is the extent of the world coordinates 00043 // away from that origin. When one is manipulating the canvas itself, 00044 // this is in terms of universal coordinates, but when things on the 00045 // canvas are referred to, those things are in world coordinates. 00046 00047 virtual ~canvas(); 00048 00049 IMPLEMENT_CLASS_NAME("canvas"); 00050 00051 // Contents Redisplaying Methods: 00052 00053 void redraw(); 00054 // Causes the canvas to repaint its entire contents. 00055 00056 virtual void redraw_part(const c_rectangle &to_redraw); 00057 // Causes the portion of the canvas that intersects with the rectangle 00058 // (in universal coordinates) to be redrawn. 00059 00060 // Coordinate System Methods: 00061 00062 c_rectangle world() const; 00063 // observes the frame of reference for the things internal to this canvas 00064 // (such as the things painted on it). 00065 c_rectangle universe() const; 00066 // observes the frame of reference that is external to this object. 00067 00068 // the "device" coordinates below are relative to the origin of the canvas. 00069 c_point world_to_device(const c_point &in_world) const; 00070 c_point device_to_world(const c_point &in_device) const; 00071 00072 c_rectangle world_to_device(const c_rectangle &in_world) const; 00073 c_rectangle device_to_world(const c_rectangle &in_device) const; 00074 00075 // Contents Management Functions: 00076 00077 int elements(); 00078 // the number of paintables currently attached to this canvas. 00079 void add(drawable *to_add); 00080 // attaches a new object (hopefully a paintable one, but drawables are 00081 // allowed since we want to allow pictures to be added). 00082 void remove(drawable *to_add); 00083 // detaches an object from the canvas. the request is ignored if the 00084 // object is not found. 00085 void update(); 00086 // reorders the set of paintables attached to the canvas so that the 00087 // layers are accurate. a call to draw() is required to make sure that 00088 // any changes are displayed. 00089 00090 // Miscellaneous Methods: 00091 00092 resources &details(); 00093 // Accesses the repository for windowing system dependent information. 00094 00095 static void exposer(window_handle, canvas *me, XmAnyCallbackStruct *parms); 00096 static void resizer(window_handle, canvas *me, XmAnyCallbackStruct *parms); 00097 static void inputer(window_handle, canvas *me, XmAnyCallbackStruct *parms); 00098 00099 private: 00100 resources _details; 00101 picture contents; 00102 00103 window_handle create_canvas_handle(manager &root, const c_point &origin); 00104 }; 00105 00106 #endif
1.5.1