00001 #ifndef PAINTABLE_IMPLEMENTATION_FILE 00002 #define PAINTABLE_IMPLEMENTATION_FILE 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : paintable * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "canvas.h" 00019 #include "paintable.h" 00020 #include "wp_implementation.h" 00021 00022 #include <basis/guards.h> 00023 00024 paintable::paintable(canvas &to_draw_on, const c_point &origin, 00025 const color &fgnd, bool attach) 00026 : drawable(origin, fgnd), _filled(false), _attach(attach), 00027 _canvas(to_draw_on) 00028 { foreground(fgnd); } 00029 00030 paintable::~paintable() { 00031 // erase(); // causes weird abort on non-pointer paintables! 00032 } 00033 00034 canvas &paintable::target() const { return _canvas; } 00035 00036 void paintable::set_filled(bool filled_now) { _filled = filled_now; } 00037 00038 bool paintable::filled() const { return _filled; } 00039 00040 color paintable::foreground() const { return drawable::foreground(); } 00041 00042 void paintable::draw() 00043 { 00044 plot(_foreground); 00045 if (!visible()) { 00046 if (_attach) attach(); 00047 set_visible(); 00048 } 00049 } 00050 00051 void paintable::erase() 00052 { 00053 color b = _canvas.background(); 00054 plot(b); 00055 if (visible()) { 00056 set_invisible(); 00057 if (_attach) detach(); 00058 } 00059 } 00060 00061 void paintable::attach() 00062 { 00063 /* 00064 for (int i = 0; i < _canvas.elements(); i++) 00065 if (_canvas.contents.get(i) == this) { 00066 LOG("paintable::attach: adding worker again!"); 00067 return; 00068 } 00069 */ 00070 _canvas.add(this); 00071 } 00072 00073 void paintable::detach() { _canvas.remove(this); } 00074 00075 void paintable::foreground(const color &new_foreground) 00076 { 00077 color fg(new_foreground); 00078 _canvas.colormap().add(fg); 00079 drawable::foreground(fg); 00080 } 00081 00082 void paintable::set_origin(const c_point &new_origin) 00083 { 00084 bool was_visible(visible()); 00085 if (was_visible) erase(); 00086 drawable::set_origin(new_origin); 00087 if (was_visible) draw(); 00088 } 00089 00090 00091 #endif //PAINTABLE_IMPLEMENTATION_FILE 00092
1.5.1