00001 /********************************************************************************/ 00002 /* */ 00003 /* Netrinjo-Engine - a library for game-development */ 00004 /* Copyright (C) 1999-2006 by Tobias Nadler and Georg Schnattinger */ 00005 /* */ 00006 /* This library is free software; you can redistribute it and/or */ 00007 /* modify it under the terms of the GNU Lesser General Public */ 00008 /* License as published by the Free Software Foundation; either */ 00009 /* version 2.1 of the License, or (at your option) any later version. */ 00010 /* */ 00011 /* This library is distributed in the hope that it will be useful, */ 00012 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00013 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 00014 /* Lesser General Public License for more details. */ 00015 /* */ 00016 /* You should have received a copy of the GNU Lesser General Public */ 00017 /* License along with this library; if not, write to the Free Software */ 00018 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00019 /* */ 00020 /********************************************************************************/ 00021 00022 #ifndef GUISURFACE_H 00023 #define GUISURFACE_H 00024 00025 #include "guielement.h" 00026 00033 class TiXmlElement; 00034 00049 class DECLSPEC GuiSurface : public GuiElement 00050 { 00051 public: 00061 DECLSPEC GuiSurface( const SDL_Rect &r, GuiElement *p, const char *name ); 00067 DECLSPEC GuiSurface( TiXmlElement *el, GuiElement *p ); 00068 virtual DECLSPEC ~GuiSurface(); 00069 00070 virtual const char *getClassName() { return "GuiSurface"; } 00071 00075 virtual bool hasSurface() const { return nUnuseCounter == 0; } 00081 DECLSPEC void incUnuseRef() { if( nUnuseCounter++ == 0 ) setDrawRectDirty(); } 00083 DECLSPEC void decUnuseRef() { if( nUnuseCounter && --nUnuseCounter == 0 ) setDrawRectDirty(); } 00084 00085 static void newguiobject(void *presult, BasicObject *o, void *xmldata) 00086 { 00087 GuiElement *r = new GuiSurface((TiXmlElement*)xmldata, (GuiElement*)o); 00088 *(GuiElement**)presult = r; 00089 } 00090 protected: 00091 virtual DECLSPEC Uint32 onResize(); 00095 virtual SdlSurface * getDestSurface() {return surfDest;} 00096 virtual DECLSPEC void onInit(); 00097 virtual DECLSPEC Uint32 onFrame(SdlSurface *dest); 00098 virtual void incRequireOnFrame() {GuiElement::incRequireOnFrame(); incUnuseRef();} 00099 virtual void decRequireOnFrame() {GuiElement::decRequireOnFrame(); decUnuseRef();} 00100 00101 private: 00102 // reference counter 00103 unsigned int nUnuseCounter; 00104 // Optimization 00105 // the surface to draw on 00106 SdlSurface *surfDest; 00107 }; 00108 00109 #endif