Adonthell  0.4
win_base.cc
1 /*
2  $Id: win_base.cc,v 1.4 2004/10/25 06:55:01 ksterker Exp $
3 
4  (C) Copyright 2000, 2001 Joel Vennin
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details
13 */
14 
15 
16 #include "win_base.h"
17 #include "win_manager.h"
18 #include "win_container.h"
19 
21 {
22  manager_ = NULL;
23 
24  wb_father_= NULL;
25 
26  pad_y_ = pad_x_ = 0;
27 
28  move(0,0);
29 
30  set_visible(false);
31 
32  set_focus(false);
33 
34  set_activate(false);
35 
36  set_brightness(false);
37 
38  set_trans(false);
39 
40  set_can_be_selected(true);
41 
42  set_align(ALIGN_NONE);
43 }
44 
45 win_base::~win_base()
46 {
47  if (manager_) manager_->remove (this);
48  manager_ = NULL;
49 }
50 
51 void win_base::set_container(win_container * wc)
52 {
53  wb_father_=wc;
54 
55  update_position();
56 
57  update_align();
58 }
59 
60 void win_base::update_position()
61 {
62 
63  if(wb_father_) {
64  drawing_area::move(wb_father_->real_x() + x() + pad_x(), wb_father_->real_y() + y() + pad_y() );
65  }
66  else {
67  drawing_area::move( x() + pad_x(), y() + pad_y() );
68  }
69 }
70 
72 {
73 
74  x_= tx;
75 
76  y_= ty;
77 
78  update_position();
79 }
80 
82 {
83  drawing_area::resize(tl, th);
84 
85  win_border::update();
86 
87  win_background::update();
88 }
89 
91 {
92  if(win_event::update())
93  {
94  // if(focus_) ADDME: ajouter l'appel a update_input
95  on_update();
96 
97  return true;
98  }
99  return false;
100 }
101 
103 {
104  return (focus_ && activate_);
105 }
106 
108 {
109  on_draw();
110 
111  if(visible_) on_draw_visible();
112 
113  return visible_;
114 }
115 
116 
117 
118 void win_base::update_align()
119 {
120  switch(align_)
121  {
122  case ALIGN_LEFT:
123  move((wb_father_) ? ((win_container*)wb_father_)->space_with_border() : 0 , y() );
124  break;
125  case ALIGN_RIGHT:
126  move(((wb_father_) ? wb_father_->length() : screen::length())-((wb_father_)?((win_container*)wb_father_)->space_with_border() : 0 ) - length() , y() );
127  break;
128  case ALIGN_CENTER:
129  if(((wb_father_)?wb_father_->length():screen::length())>length())
130  move((((wb_father_)?wb_father_->length():screen::length()) - length()) >>1,y());
131  break;
132  }
133 }
134 
135 void win_base::set_manager (win_manager *m)
136 {
137  manager_ = m;
138 }
139 
s_int16 real_y() const
Return the vertical position of the win_*.
Definition: win_base.h:108
virtual void move(s_int16 tx, s_int16 ty)
Move the win_*.
Definition: win_base.cc:71
#define u_int16
16 bits long unsigned integer
Definition: types.h:32
void set_visible(const bool b)
Set the visible parameter.
Definition: win_base.h:136
s_int16 real_x() const
Return the horizontal position of the win_*.
Definition: win_base.h:100
void resize(u_int16 nl, u_int16 nh)
Resize the drawing_area.
Definition: drawing_area.h:116
static u_int16 length()
Returns the length of the screen.
Definition: screen.h:63
s_int16 y() const
Return the relative vertical position of the win_*.
Definition: win_base.h:76
virtual void set_trans(const bool b)
Set the transluency parameter.
Definition: win_base.h:180
s_int16 & pad_y()
Return the pad vertical position of the win_*.
Definition: win_base.h:92
virtual bool update()
Update process.
Definition: win_base.cc:90
u_int16 length() const
Returns the length of the drawing_area.
Definition: drawing_area.h:89
The window manager takes care of basic GUI functions, such as input focus, window state updates and d...
Definition: win_manager.h:61
virtual bool input_update()
Input Update process
Definition: win_base.cc:102
virtual void resize(u_int16 tl, u_int16 th)
Rezise the win_*.
Definition: win_base.cc:81
void remove(win_base *wnd)
Remove a window from the window manager.
Definition: win_manager.cc:119
#define s_int16
16 bits long signed integer
Definition: types.h:41
void set_align(const u_int8 a)
Set alignement of win_*.
Definition: win_base.h:201
void set_focus(const bool b)
Set the focus parameter.
Definition: win_base.h:166
void set_can_be_selected(const bool b)
Set the object to be selected A win_obj can be selectable or not when it is inside a win_select...
Definition: win_base.h:222
s_int16 & pad_x()
Return the pad horizontal position of the win_*.
Definition: win_base.h:84
virtual void set_brightness(const bool b)
Set the transluency parameter.
Definition: win_base.h:194
void move(s_int16 nx, s_int16 ny)
Move the drawing_area.
Definition: drawing_area.h:106
Declares the win_manager class.
win_base()
Default constructor:
Definition: win_base.cc:20
s_int16 x() const
Return the relative horizontal position of the win_*.
Definition: win_base.h:68
void set_activate(const bool b)
Set the activate parameter When a win_* is setup on, the keys queue is cleared.
Definition: win_base.h:152
virtual bool draw()
Draw process.
Definition: win_base.cc:107