Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Screen.cpp
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: Screen.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  General Screen class - maintains and displays a list of windows
13 */
14 
15 #include "MemDebug.h"
16 #include "Screen.h"
17 #include "Bitmap.h"
18 #include "Color.h"
19 #include "Window.h"
20 #include "Mouse.h"
21 #include "Pcx.h"
22 #include "Video.h"
23 
24 // +--------------------------------------------------------------------+
25 
27 : width(0), height(0), video(v), clear(0), closed(0)
28 {
29  if (video) {
30  width = video->Width();
31  height = video->Height();
32  }
33 
34  Mouse::Create(this);
35 }
36 
38 {
39  Mouse::Close();
40 
41  closed = 1;
43 }
44 
45 // +--------------------------------------------------------------------+
46 
47 bool
49 {
50  if (!c || closed) return false;
51 
52  if (c->X() < 0) return false;
53  if (c->Y() < 0) return false;
54  if (c->X() + c->Width() > Width()) return false;
55  if (c->Y() + c->Height() > Height()) return false;
56 
57  if (!window_list.contains(c))
59 
60  return true;
61 }
62 
63 bool
65 {
66  if (!c || closed) return false;
67 
68  return window_list.remove(c) == c;
69 }
70 
71 // +--------------------------------------------------------------------+
72 
73 void
74 Screen::ClearAllFrames(bool clear_all)
75 {
76  if (clear_all)
77  clear = -1;
78  else
79  clear = 0;
80 }
81 
82 void
83 Screen::ClearNextFrames(int num_frames)
84 {
85  if (clear >= 0 && clear < num_frames)
86  clear = num_frames;
87 }
88 
89 // +--------------------------------------------------------------------+
90 
91 bool
93 {
94  if (video)
95  return video->SetBackgroundColor(c);
96  else
97  return false;
98 }
99 
100 // +--------------------------------------------------------------------+
101 
102 bool
103 Screen::Resize(int w, int h)
104 {
105  // scale all root-level windows to new screen size:
106 
108  while (++iter) {
109  Window* win = iter.value();
110 
111  double w_x = win->GetRect().x / (double) width;
112  double w_y = win->GetRect().y / (double) height;
113  double w_w = win->GetRect().w / (double) width;
114  double w_h = win->GetRect().h / (double) height;
115 
116  Rect r;
117 
118  r.x = (int) (w_x * w);
119  r.y = (int) (w_y * h);
120  r.w = (int) (w_w * w);
121  r.h = (int) (w_h * h);
122 
123  win->MoveTo(r);
124  }
125 
126  width = w;
127  height = h;
128 
129  return true;
130 }
131 
132 // +--------------------------------------------------------------------+
133 
134 bool
136 {
137  if (clear && !video->ClearAll())
138  return false;
139 
140  video->StartFrame();
141 
143  while (++iter) {
144  Window* win = iter.value();
145 
146  if (win->IsShown()) {
147  win->Paint();
148  }
149  }
150 
151  Mouse::Paint();
152 
153  video->EndFrame();
154 
155  if (clear > 0) clear--;
156  return true;
157 }
158 
159 
160 
161