1 // Crimson Fields -- a game of tactical warfare
2 // Copyright (C) 2000-2007 Jens Granseuer
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
19 ///////////////////////////////////////////////////////////////
20 // window.h
21 ///////////////////////////////////////////////////////////////
22 
23 #ifndef _INCLUDE_WINDOW_H
24 #define _INCLUDE_WINDOW_H
25 
26 #include "surface.h"
27 #include "list.h"
28 #include "font.h"
29 #include "widget.h"
30 
31 // window flags
32 #define WIN_CLOSE_ESC      0x0001   // close window on 'ESC'
33 #define WIN_CLOSE_UNFOCUS  0x0002   // close window on clicks outside
34                                     // the window surface
35 #define WIN_CENTER         0x0004   // center window on screen
36 
37 // flags used by the extended window classes
38 #define WIN_FONT_BIG       0x0010  // use large window font
39 
40 #define WIN_FILE_SAVE      0x0020  // save flag for file window
41 #define WIN_FILE_LOAD      0x0040  // load flag for file window
42 
43 #define WIN_PROG_ABORT     0x0020  // create abort button for progress window
44 #define WIN_PROG_DEFAULT   0x0040  // set WIDGET_DEFAULT for abort button
45 
46 #define WIN_DESTROYED      0x8000  // window has been closed, clean me up!
47 
48 class View;
49 
50 class Window : public Surface, public Node {
51 public:
52   Window( short x, short y, unsigned short w, unsigned short h,
53           unsigned short flags, View *view );
54   virtual ~Window( void );
55 
56   virtual void Draw( void );
57   void DrawBack( const Rect &rect );
DrawBack(short x,short y,unsigned short w,unsigned short h)58   virtual void DrawBack( short x, short y, unsigned short w, unsigned short h )
59                { DrawBack( Rect(x, y, w, h) ); }
DrawBack(void)60   void DrawBack( void ) { DrawBack( 0, 0, w, h ); }
61   void Show( void );
62   void Show( const Rect &rect );
63   int SetSize( unsigned short w, unsigned short h );
64   int SetSize( short x, short y, unsigned short w, unsigned short h );
SetSize(const Rect & s)65   int SetSize( const Rect &s ) { return SetSize(s.x, s.y, s.w, s.h); }
66 
67   void AddWidget( Widget *widget );
68   Widget *RemoveWidget( Widget *widget );
69   void RemoveAllWidgets( void );
70 
71   virtual GUI_Status HandleEvent( const SDL_Event &event );
72   virtual GUI_Status EventLoop( void );
73   virtual void VideoModeChange( void );
74 
GetView(void)75   View *GetView( void ) const { return view; }
SmallFont(void)76   Font *SmallFont( void ) const { return sfont; }
LargeFont(void)77   Font *LargeFont( void ) const { return lfont; }
SetSmallFont(Font * font)78   void SetSmallFont( Font *font ) { sfont = font; }
SetLargeFont(Font * font)79   void SetLargeFont( Font *font ) { lfont = font; }
80   const Color &GetFGPen( void ) const;
81   const Color &GetBGPen( void ) const;
82 
Close(void)83   virtual void Close( void ) { flags |= WIN_DESTROYED; }
Closed(void)84   bool Closed( void ) const { return (flags & WIN_DESTROYED) != 0; }
85 
86 protected:
87   Window( unsigned short flags, View *view );
88 
89   Widget *widgets;
90   View *view;
91   Font *sfont, *lfont;
92 
93   unsigned short flags;
94 
95 private:
96   void Init( unsigned short flags, View *view );
97 };
98 
99 #include "view.h"
100 
101 #endif  /* _INCLUDE_WINDOW_H */
102 
103