From 8898ad9b25fca6afe2374d293a981db02a83d7e9 Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Thu, 31 May 2012 14:46:27 +0000 Subject: Committing the documentation to svn to have it accessible online --- Doc/doxygen/html/_slider_8cpp_source.html | 674 ++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 Doc/doxygen/html/_slider_8cpp_source.html (limited to 'Doc/doxygen/html/_slider_8cpp_source.html') diff --git a/Doc/doxygen/html/_slider_8cpp_source.html b/Doc/doxygen/html/_slider_8cpp_source.html new file mode 100644 index 0000000..a5dcfcb --- /dev/null +++ b/Doc/doxygen/html/_slider_8cpp_source.html @@ -0,0 +1,674 @@ + + + + + +Starshatter_Open: D:/SRC/StarshatterSVN/nGenEx/Slider.cpp Source File + + + + + + + + + + + + + +
+
+ + + + + + +
+
Starshatter_Open +
+
Open source Starshatter engine
+
+
+ + + + + +
+
+ +
+
+
+ +
+ + + + +
+ +
+ +
+
+
Slider.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: Slider.cpp
+
7  AUTHOR: John DiCamillo
+
8 
+
9 
+
10  OVERVIEW
+
11  ========
+
12  Slider/Gauge ActiveWindow class
+
13 */
+
14 
+
15 #include "MemDebug.h"
+
16 #include "Slider.h"
+
17 #include "Video.h"
+
18 #include "Font.h"
+
19 
+
20 // +--------------------------------------------------------------------+
+
21 
+
22 Slider::Slider(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid)
+
23 : ActiveWindow(p->GetScreen(), ax, ay, aw, ah, aid, 0, p)
+
24 {
+
25  captured = false;
+
26  dragging = false;
+
27 
+ + +
30 
+
31  active = true;
+
32  border = true;
+
33  num_leds = 1;
+
34  orientation = 0;
+
35 
+
36  range_min = 0;
+
37  range_max = 100;
+
38  step_size = 10;
+
39  show_thumb = 0;
+
40  thumb_size = -1;
+
41 
+
42  nvalues = 1;
+
43  ZeroMemory(value, sizeof(value));
+
44 
+
45  marker[0] = -1;
+
46  marker[1] = -1;
+
47 
+
48  char buf[32];
+
49  sprintf_s(buf, "Slider %d", id);
+
50  desc = buf;
+
51 }
+
52 
+
53 Slider::Slider(Screen* s, int ax, int ay, int aw, int ah, DWORD aid)
+
54 : ActiveWindow(s, ax, ay, aw, ah, aid)
+
55 {
+
56  captured = false;
+
57  dragging = false;
+
58 
+ + +
61 
+
62  active = true;
+
63  border = true;
+
64  num_leds = 1;
+
65  orientation = 0;
+
66 
+
67  range_min = 0;
+
68  range_max = 100;
+
69  step_size = 10;
+
70  show_thumb = 0;
+
71  thumb_size = -1;
+
72 
+
73  nvalues = 1;
+
74  ZeroMemory(value, sizeof(value));
+
75 
+
76  marker[0] = -1;
+
77  marker[1] = -1;
+
78 
+
79  char buf[32];
+
80  sprintf_s(buf, "Slider %d", id);
+
81  desc = buf;
+
82 }
+
83 
+ +
85 {
+
86 }
+
87 
+
88 // +--------------------------------------------------------------------+
+
89 
+
90 void
+ +
92 {
+
93  int x = 0;
+
94  int y = 0;
+
95  int w = rect.w;
+
96  int h = rect.h;
+
97 
+
98  if (w < 1 || h < 1 || !shown)
+
99  return;
+
100 
+
101  Rect ctrl_rect(x,y,w,h);
+
102 
+
103  // draw the border:
+
104  if (border) {
+
105  Color oc = ShadeColor(border_color, 1);
+
106  DrawRect(0,0,w-1,h-1,oc);
+
107  DrawRect(1,1,w-2,h-2,oc);
+
108 
+
109  ctrl_rect.Deflate(2,2);
+
110  }
+
111 
+
112  // draw the bevel:
+
113  FillRect(ctrl_rect, back_color);
+
114  DrawStyleRect(ctrl_rect, WIN_SUNK_FRAME);
+
115 
+
116  // HORIZONTAL
+
117  if (orientation == 0) {
+
118  // draw the leds:
+
119  int led_width = ((w - 6) / (num_leds)) - 1;
+
120  int led_height = ((h - 5) / (nvalues)) - 1;
+
121 
+
122  if (nvalues < 2) {
+
123  int fill_width = (int) ((double)(w-4) * FractionalValue());
+
124  int num_lit = fill_width / (led_width+1);
+
125 
+
126  Color fc = ShadeColor(fill_color, 1);
+
127 
+
128  if (num_leds == 1) {
+
129  FillRect(2,2,2+fill_width,h-3,fc);
+
130  }
+
131  else {
+
132  int x0 = 2;
+
133 
+
134  for (int i = 0; i < num_lit; i++) {
+
135  FillRect(x0,2,x0+led_width,h-3,fc);
+
136  x0 += led_width + 1;
+
137  }
+
138  }
+
139 
+
140  // draw the thumb:
+
141  if (thumb_size) {
+
142  if (thumb_size < 0) thumb_size = h;
+
143 
+
144  thumb_pos = 2+fill_width;
+
145 
+
146  Rect thumb_rect(thumb_pos-thumb_size/2, 0, thumb_size, h);
+
147 
+
148  if (thumb_rect.x < 0)
+
149  thumb_rect.x = 0;
+
150 
+
151  else if (thumb_rect.x > w-thumb_size)
+
152  thumb_rect.x = w-thumb_size;
+
153 
+
154  if (show_thumb) {
+
155  FillRect(thumb_rect, back_color);
+
156  DrawStyleRect(thumb_rect, WIN_RAISED_FRAME);
+
157  }
+
158  }
+
159  }
+
160 
+
161  else {
+
162  Color fc = ShadeColor(fill_color, 1);
+
163 
+
164  int y0 = 3;
+
165 
+
166  for (int i = 0; i < nvalues; i++) {
+
167  int fill_width = (int) ((double)(w-6) * FractionalValue(i));
+
168  FillRect(3,y0,3+fill_width,y0+led_height,fc);
+
169 
+
170  y0 += led_height+1;
+
171  }
+
172  }
+
173 
+
174  // draw the markers:
+
175  if (marker[0] >= 0) {
+
176  int m = marker[0];
+
177  Color c = ShadeColor(base_color, 1.6); // full highlight
+
178  DrawLine(m-3, 1, m+4, 1, c);
+
179  c = ShadeColor(base_color, 1.3); // soft highlight
+
180  DrawLine(m-3, 2, m-3, 4, c);
+
181  DrawLine(m-2, 4, m-2, 6, c);
+
182  DrawLine(m-1, 6, m-1, 8, c);
+
183  DrawLine(m , 8, m , 10, c);
+
184  c = base_color; // body
+
185  DrawLine(m-2, 2, m-2, 4, c);
+
186  DrawLine(m-1, 2, m-1, 6, c);
+
187  DrawLine(m , 2, m , 8, c);
+
188  DrawLine(m+1, 2, m+1, 6, c);
+
189  DrawLine(m+2, 2, m+2, 4, c);
+
190  c = ShadeColor(base_color, 0.5); // shadow
+
191  DrawLine(m+1, 6, m+1, 8, c);
+
192  DrawLine(m+2, 4, m+2, 6, c);
+
193  DrawLine(m+3, 2, m+3, 4, c);
+
194  }
+
195 
+
196  if (marker[1] >= 0) {
+
197  int m = marker[0];
+
198  Color c = ShadeColor(base_color, 0.5); // shadow
+
199  DrawLine(m-3, h-2, m+4, h-2, c);
+
200  DrawLine(m+1, h-6, m+1, h-8, c);
+
201  DrawLine(m+2, h-4, m+2, h-6, c);
+
202  DrawLine(m+3, h-2, m+3, h-4, c);
+
203  c = ShadeColor(base_color, 1.3); // soft highlight
+
204  DrawLine(m-3, h-2, m-3, h-4, c);
+
205  DrawLine(m-2, h-4, m-2, h-6, c);
+
206  DrawLine(m-1, h-6, m-1, h-8, c);
+
207  DrawLine(m , h-8, m , h-10, c);
+
208  c = base_color; // body
+
209  DrawLine(m-2, h-2, m-2, h-4, c);
+
210  DrawLine(m-1, h-2, m-1, h-6, c);
+
211  DrawLine(m , h-2, m , h-8, c);
+
212  DrawLine(m+1, h-2, m+1, h-6, c);
+
213  DrawLine(m+2, h-2, m+2, h-4, c);
+
214  }
+
215  }
+
216 
+
217  // VERTICAL
+
218  else {
+
219  // draw the leds:
+
220  int led_width = ((w - 5) / (nvalues)) - 1;
+
221 
+
222  if (num_leds > 1) {
+
223  }
+
224  else {
+
225  if (nvalues < 2) {
+
226  led_width = w - 4;
+
227  int led_height = (int) ((double)(h-4) * FractionalValue());
+
228 
+
229  Color fc = ShadeColor(fill_color, 1);
+
230  FillRect(2, h-2-led_height, 2+led_width, h-2, fc);
+
231 
+
232  // draw the thumb:
+
233  if (thumb_size) {
+
234  if (thumb_size < 0) thumb_size = w;
+
235 
+
236  thumb_pos = h-2-led_height;
+
237 
+
238  Rect thumb_rect(0, thumb_pos-(thumb_size/2), w, thumb_size);
+
239 
+
240  if (thumb_rect.y < 0)
+
241  thumb_rect.y = 0;
+
242 
+
243  else if (thumb_rect.y > h-thumb_size)
+
244  thumb_rect.y = h-thumb_size;
+
245 
+
246  if (show_thumb) {
+
247  FillRect(thumb_rect, back_color);
+
248  DrawStyleRect(thumb_rect, WIN_RAISED_FRAME);
+
249  }
+
250  }
+
251  }
+
252 
+
253  else {
+
254  Color fc = ShadeColor(fill_color, 1);
+
255 
+
256  int x0 = 3;
+
257 
+
258  for (int i = 0; i < nvalues; i++) {
+
259  int led_height = (int) ((double)(h-6) * FractionalValue(i));
+
260  FillRect(x0,h-3-led_height,x0+led_width,h-3,fc);
+
261 
+
262  x0 += led_width+1;
+
263  }
+
264  }
+
265  }
+
266  }
+
267 }
+
268 
+
269 // +--------------------------------------------------------------------+
+
270 
+ +
272 {
+
273  return active;
+
274 }
+
275 
+
276 void Slider::SetActive(bool bNewValue)
+
277 {
+
278  active = bNewValue;
+
279 }
+
280 
+ +
282 {
+
283  return border;
+
284 }
+
285 
+
286 void Slider::SetBorder(bool bNewValue)
+
287 {
+
288  border = bNewValue;
+
289 }
+
290 
+ +
292 {
+
293  return border_color;
+
294 }
+
295 
+ +
297 {
+
298  border_color = newValue;
+
299 }
+
300 
+ +
302 {
+
303  return fill_color;
+
304 }
+
305 
+ +
307 {
+
308  fill_color = cNewValue;
+
309 }
+
310 
+ +
312 {
+
313  return num_leds;
+
314 }
+
315 
+
316 void Slider::SetNumLeds(int nNewValue)
+
317 {
+
318  if (nNewValue >= 0) {
+
319  num_leds = nNewValue;
+
320  }
+
321 }
+
322 
+ +
324 {
+
325  return orientation;
+
326 }
+
327 
+
328 void Slider::SetOrientation(int nNewValue)
+
329 {
+
330  if (nNewValue == 0 || nNewValue == 1) {
+
331  orientation = nNewValue;
+
332  }
+
333 }
+
334 
+ +
336 {
+
337  return range_min;
+
338 }
+
339 
+
340 void Slider::SetRangeMin(int nNewValue)
+
341 {
+
342  range_min = nNewValue;
+
343 }
+
344 
+ +
346 {
+
347  return range_max;
+
348 }
+
349 
+
350 void Slider::SetRangeMax(int nNewValue)
+
351 {
+
352  range_max = nNewValue;
+
353 }
+
354 
+ +
356 {
+
357  return step_size;
+
358 }
+
359 
+
360 void Slider::SetStepSize(int nNewValue)
+
361 {
+
362  if (nNewValue < range_max - range_min)
+
363  step_size = nNewValue;
+
364 }
+
365 
+ +
367 {
+
368  return show_thumb?true:false;
+
369 }
+
370 
+
371 void Slider::SetShowThumb(bool bNewValue)
+
372 {
+
373  show_thumb = bNewValue;
+
374 }
+
375 
+ +
377 {
+
378  return thumb_size;
+
379 }
+
380 
+
381 void Slider::SetThumbSize(int nNewValue)
+
382 {
+
383  if (nNewValue < range_max - range_min)
+
384  thumb_size = nNewValue;
+
385 }
+
386 
+ +
388 {
+
389  return nvalues;
+
390 }
+
391 
+
392 int Slider::GetValue(int index)
+
393 {
+
394  if (index >= 0 && index < nvalues)
+
395  return value[index];
+
396 
+
397  return 0;
+
398 }
+
399 
+
400 void Slider::SetValue(int nNewValue, int index)
+
401 {
+
402  if (index >= 0 && index < MAX_VAL) {
+
403  value[index] = nNewValue;
+
404 
+
405  if (index >= nvalues)
+
406  nvalues = index+1;
+
407  }
+
408 }
+
409 
+
410 void Slider::SetMarker(int nNewValue, int index)
+
411 {
+
412  if (index >= 0 && index < 2) {
+
413  marker[index] = nNewValue;
+
414  }
+
415 }
+
416 
+
417 double Slider::FractionalValue(int index)
+
418 {
+
419  if (index >= 0 && index < nvalues)
+
420  return ((double) (value[index]-range_min)) / ((double) (range_max-range_min));
+
421 
+
422  return 0;
+
423 }
+
424 
+
425 // +--------------------------------------------------------------------+
+
426 
+
427 void Slider::StepUp(int index)
+
428 {
+
429  if (index >= 0 && index < nvalues) {
+
430  value[index] += step_size;
+
431 
+
432  if (value[index] > range_max)
+
433  value[index] = range_max;
+
434  }
+
435 }
+
436 
+
437 void Slider::StepDown(int index)
+
438 {
+
439  if (index >= 0 && index < nvalues) {
+
440  value[index] -= step_size;
+
441 
+
442  if (value[index] < range_min)
+
443  value[index] = range_min;
+
444  }
+
445 }
+
446 
+
447 // +--------------------------------------------------------------------+
+
448 
+
449 int Slider::OnMouseMove(int x, int y)
+
450 {
+
451  bool dirty = false;
+
452 
+
453  if (captured)
+
454  {
+
455  ActiveWindow* test = GetCapture();
+
456 
+
457  if (test != this)
+
458  {
+
459  captured = false;
+
460  dirty = true;
+
461  }
+
462 
+
463  else if (dragging)
+
464  {
+
465  mouse_x = x - rect.x;
+
466  if (mouse_x < 0) mouse_x = 0;
+
467  else if (mouse_x > rect.w) mouse_x = rect.w;
+
468 
+
469  mouse_y = rect.h - (y - rect.y);
+
470  if (mouse_y < 0) mouse_y = 0;
+
471  else if (mouse_y > rect.h) mouse_y = rect.h;
+
472 
+
473  // HORIZONTAL
+
474  if (orientation == 0) {
+
475  SetValue((int) ((double) mouse_x/rect.w * (range_max-range_min) + range_min));
+
476  }
+
477 
+
478  // VERTICAL
+
479  else {
+
480  SetValue((int) ((double) mouse_y/rect.h * (range_max-range_min) + range_min));
+
481  }
+
482 
+
483  dirty = true;
+
484  }
+
485  }
+
486 
+
487  if (dirty)
+
488  OnClick();
+
489 
+
490  return ActiveWindow::OnMouseMove(x,y);
+
491 }
+
492 
+
493 int Slider::OnLButtonDown(int x, int y)
+
494 {
+
495  if (!active)
+
496  return 0;
+
497 
+
498  if (!captured)
+
499  captured = SetCapture();
+
500 
+
501  mouse_x = x - rect.x;
+
502  mouse_y = y - rect.y;
+
503 
+
504  // HORIZONTAL
+
505  if (orientation == 0) {
+
506  if (mouse_x < thumb_pos-thumb_size/2) {
+
507  StepDown();
+
508  }
+
509 
+
510  else if (mouse_x > thumb_pos+thumb_size/2) {
+
511  StepUp();
+
512  }
+
513 
+
514  else {
+
515  dragging = true;
+
516  }
+
517  }
+
518 
+
519  // VERTICAL
+
520  else {
+
521  if (mouse_y < thumb_pos-thumb_size/2) {
+
522  StepUp();
+
523  }
+
524 
+
525  else if (mouse_y > thumb_pos+thumb_size/2) {
+
526  StepDown();
+
527  }
+
528 
+
529  else {
+
530  dragging = true;
+
531  }
+
532  }
+
533 
+
534  if (!dragging)
+
535  OnClick();
+
536 
+
537  return ActiveWindow::OnLButtonDown(x,y);
+
538 }
+
539 
+
540 int Slider::OnLButtonUp(int x, int y)
+
541 {
+
542  if (!active)
+
543  return 0;
+
544 
+
545  if (captured) {
+
546  ReleaseCapture();
+
547  captured = 0;
+
548  dragging = false;
+
549  }
+
550 
+
551  return ActiveWindow::OnLButtonUp(x,y);
+
552 }
+
553 
+ +
555 {
+
556  return ActiveWindow::OnClick();
+
557 }
+
+
+ + + + -- cgit v1.1