Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

screenarea.h

00001 /* 00002 libwftk - Worldforge Toolkit - a widget library 00003 Copyright (C) 2003 Ron Steinke <rsteinke@w-link.net> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, SA. 00019 */ 00020 00021 #ifndef _SCREEN_AREA_H 00022 #define _SCREEN_AREA_H 00023 00024 #include <list> 00025 #include <string> 00026 #include <sigc++/object.h> 00027 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0 00028 #include <sigc++/signal_system.h> 00029 #else 00030 #include <sigc++/signal.h> 00031 #endif 00032 00033 #include <wftk/rect.h> 00034 #include <wftk/region.h> 00035 #include <wftk/refobj.h> 00036 #include <wftk/mouse.h> 00037 00038 namespace wftk { 00039 00040 class Surface; 00041 00046 class ScreenArea : virtual public SigC::Object, public RefCountObj 00047 { 00048 public: 00050 ScreenArea(); 00052 virtual ~ScreenArea(); 00053 00055 SigC::Signal0<void> deleted; 00057 SigC::Signal2<void,Uint16,Uint16> resized; 00058 00060 00064 bool show(); 00066 00070 bool hide(); 00071 00073 void raise(); 00075 void lower(); 00076 00078 void resize(const Rect&); 00080 void resize(Uint16 w, Uint16 h) {resize(Rect(rect_.x, rect_.y, w, h));} 00081 00083 bool isHidden() const {return hidden_;} 00084 00086 00091 void setParent(ScreenArea*); 00093 ScreenArea* parent() {return parent_;} 00095 const ScreenArea* parent() const {return parent_;} 00096 00098 bool contains(const ScreenArea&) const; 00099 00101 00106 ScreenArea* getContainer(const Point&); 00107 00109 struct PackingInfo { 00111 struct Expander { 00113 Uint16 pref; 00115 Uint16 min; 00117 bool expand; 00119 00128 unsigned char filler; 00129 00131 Expander() : pref(0), expand(true), filler(0) { 00132 // win32 uses min() as a preprocessor macro, have to init it here 00133 min = 0; 00134 } 00135 00136 // container functions 00137 00139 void extend(const Expander&); 00140 00142 void contain(const Expander&); 00143 00144 enum { 00146 FILL = 100, 00148 SUBTRACT = 5 00149 }; 00150 } x, y; 00152 class Weights { 00153 public: 00154 Weights() : expand_(0), shrink_(0), high_fill_(0), expand_frac_(0) {} 00155 00157 void extend(const Expander&); 00158 00160 void setExpand(Uint16 pref_size, Uint16 real_size); 00162 double padding(const Expander&) const; 00163 00164 private: 00166 Uint16 expand_; 00168 Uint16 shrink_; 00170 unsigned char high_fill_; 00172 double expand_frac_; 00173 }; 00174 }; 00176 const PackingInfo& getPackingInfo() const {return packing_info_;} 00177 00179 const Rect& getRect() const {return rect_;} 00181 const Region& getShape() const {return shape_;} 00183 const Region& getCoverage() const {return covered_;} 00184 00186 Rect screenRect() const 00187 {return parent_ ? parent_->globalCoord(getRect()) : getRect();} 00188 00190 Uint16 width() const {return rect_.w;} 00192 Uint16 height() const {return rect_.h;} 00193 00195 Rect globalCoord (const Rect& local) const; 00197 Rect localCoord (const Rect& global) const; 00198 00200 bool hasMouse() const; 00201 00202 // Event handlers for this widget's behavior, 00203 // non-widget-specific event handlers should connect to 00204 // the signals in Mouse or Focus, respectively 00205 00207 virtual bool mouseEvent(const Point& pos, const Point& rel, Mouse::Button mask) 00208 {return false;} 00210 virtual bool buttonEvent(Mouse::Button, bool pressed, const Point&) 00211 {return false;} 00213 virtual void gainedMouse() {} 00215 virtual void lostMouse() {} 00216 00218 std::string name() const; 00219 00220 protected: 00221 00223 00229 void removeChildren(); 00230 00232 void packingUpdate(); 00233 00235 00247 void setShape(const Region& shape, const Region& coverage); 00249 void setCoverage(const Region& coverage) {setShape(shape_, coverage);} 00250 00252 const Region& getExposed() const {return exposed_;} 00253 00255 bool dirty() const {return !hidden_ && !dirtyFull_.empty();} 00256 00258 void invalidate(const Region&); 00260 void invalidate() {invalidate(Rect(0, 0, rect_.w, rect_.h));} 00261 00263 00267 void blit(Surface& target, const Point& offset); 00268 00270 00275 virtual void draw(Surface&, const Point& offset, const Region&) {} 00276 00278 00283 virtual void drawAfter(Surface&, const Point& offset, const Region&) {} 00284 00286 virtual void handleResize(Uint16 w, Uint16 h) 00287 {setShape(Rect(0, 0, w, h), Region());} 00288 00290 virtual void setPackingInfo() 00291 {packing_info_.x = packing_info_.y = PackingInfo::Expander();} 00292 00294 virtual void packingUpdateParent() {if(parent_) parent_->packingUpdate();} 00295 00297 PackingInfo packing_info_; 00298 00299 private: 00300 // Unimplemented functions 00301 ScreenArea(const ScreenArea&); 00302 ScreenArea& operator=(const ScreenArea&); 00303 00311 void expose(Region& full, Region& remaining); 00312 00314 void invalidateRecurse(Region&); 00316 void doExpose(const Region&); 00317 00319 Rect rect_; 00321 00326 Region exposed_; 00328 00331 Region dirty_; 00333 00336 Region dirtyFull_; 00338 00341 Region shape_; 00343 00346 Region covered_; 00347 00351 ScreenArea *parent_; 00352 00354 bool hidden_; 00355 00356 typedef std::list<ScreenArea*> Children; 00358 Children childs_; 00359 00361 Children::iterator find(ScreenArea*); 00363 Region getFullObscure(); 00364 00365 }; 00366 00367 } // namespace wftk 00368 00369 #endif // _SCREEN_AREA_H

Generated Mon Sep 6 21:58:16 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.