Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ExitDlg.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: ExitDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12 */
13 
14 #include "MemDebug.h"
15 #include "ExitDlg.h"
16 #include "MenuScreen.h"
17 #include "MusicDirector.h"
18 #include "Starshatter.h"
19 #include "FormatUtil.h"
20 
21 #include "Game.h"
22 #include "Keyboard.h"
23 #include "Button.h"
24 #include "RichTextBox.h"
25 #include "DataLoader.h"
26 
27 // +--------------------------------------------------------------------+
28 // DECLARE MAPPING FUNCTIONS:
29 
30 DEF_MAP_CLIENT(ExitDlg, OnApply);
31 DEF_MAP_CLIENT(ExitDlg, OnCancel);
32 
33 // +--------------------------------------------------------------------+
34 
36 : FormWindow(s, 0, 0, s->Width(), s->Height()),
37 manager(mgr), exit_latch(false),
38 credits(0), apply(0), cancel(0),
39 def_rect(def.GetRect())
40 {
41  Init(def);
42 }
43 
45 {
46 }
47 
48 void
50 {
51  if (apply)
52  return;
53 
55 
56  apply = (Button*) FindControl(1);
58 
59  cancel = (Button*) FindControl(2);
61 }
62 
63 // +--------------------------------------------------------------------+
64 
65 void
67 {
68  if (credits && credits->GetLineCount() > 0) {
70 
71  if (credits->GetTopIndex() >= credits->GetLineCount()-1) {
72  credits->ScrollTo(0);
73  }
74  }
75 
76  if (Keyboard::KeyDown(VK_RETURN)) {
77  OnApply(0);
78  }
79 
80  if (Keyboard::KeyDown(VK_ESCAPE)) {
81  if (!exit_latch)
82  OnCancel(0);
83  }
84  else {
85  exit_latch = false;
86  }
87 }
88 
89 // +--------------------------------------------------------------------+
90 
91 void
93 {
94  if (!IsShown()) {
95  Rect r = def_rect;
96 
97  if (r.w > screen->Width()) {
98  int extra = r.w - screen->Width();
99  r.w -= extra;
100  }
101 
102  if (r.h > screen->Height()) {
103  int extra = r.h - screen->Height();
104  r.h -= extra;
105  }
106 
107  r.x = (screen->Width() - r.w) / 2;
108  r.y = (screen->Height() - r.h) / 2;
109 
110  MoveTo(r);
111 
112  exit_latch = true;
115 
116  DataLoader* loader = DataLoader::GetLoader();
117  BYTE* block = 0;
118 
119  loader->SetDataPath(0);
120  loader->LoadBuffer("credits.txt", block, true);
121 
122  if (block && credits) {
123  credits->SetText((const char*) block);
124  }
125 
126  loader->ReleaseBuffer(block);
127  }
128 
130 }
131 
132 // +--------------------------------------------------------------------+
133 
134 void
136 {
138 
139  if (stars) {
140  ::Print("Exit Confirmed.\n");
141  stars->Exit();
142  }
143 }
144 
145 void
147 {
148  manager->ShowMenuDlg();
150 }
151 
152 // +--------------------------------------------------------------------+