Skip to content

Commit b3cc6ce

Browse files
committed
Moved more stuff to the GUI namespace! :)
1 parent e71fab5 commit b3cc6ce

23 files changed

+229
-194
lines changed

GUIApp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ void App::run(Window* window_) {
112112
DispPoint click_pos(event.button.x, event.button.y);
113113
DispPoint rel_pos(event.motion.xrel, event.motion.yrel);
114114

115-
list<GUIController*> focus_copy(captured_focus.begin(), captured_focus.end());
115+
list<Controller*> focus_copy(captured_focus.begin(), captured_focus.end());
116116

117-
for (list<GUIController*>::iterator it = focus_copy.begin();
117+
for (list<Controller*>::iterator it = focus_copy.begin();
118118
it != focus_copy.end(); ++it) {
119119

120-
GUIController *captured = *it;
120+
Controller *captured = *it;
121121

122122
DispPoint new_pos(click_pos);
123123

@@ -214,7 +214,7 @@ void App::run(Window* window_) {
214214
for (view_list_t::iterator it = captured_focus.begin();
215215
it != captured_focus.end(); ++it) {
216216

217-
GUIController *captured = *it;
217+
Controller *captured = *it;
218218

219219
bool handled = captured->handle_key_down(event.key.keysym);
220220
if (!handled) {}
@@ -247,7 +247,7 @@ void App::run(Window* window_) {
247247
for (view_list_t::iterator it = captured_focus.begin();
248248
it != captured_focus.end(); ++it) {
249249

250-
GUIController *captured = *it;
250+
Controller *captured = *it;
251251

252252
bool handled = captured->handle_key_up(event.key.keysym);
253253
if (!handled) {}

GUIApp.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
#include <SDL/SDL.h> // To ensure it is #included by main.
2121

2222

23+
namespace GUI {
24+
2325
// Throw an instance of GUIQuit to safely tell the application to exit.
2426
// (This is the same as calling GUIApp::quit())
2527
class GUIQuit {};
2628

27-
class GUIController;
2829

2930
struct GUITimer_command {
3031
GUITimer_command(double interval_) : interval(interval_) {
@@ -35,9 +36,9 @@ struct GUITimer_command {
3536
virtual void execute_command(){}
3637
};
3738

38-
namespace GUI {
3939

4040
class Window;
41+
class Controller;
4142

4243
class App {
4344
public:
@@ -65,9 +66,9 @@ class App {
6566

6667
// Provides a Controller with the ability to receive mouse/keyboard input.
6768
// (Views receive mouse input by defualt when hovered over.)
68-
void give_focus(GUIController* view) { captured_focus.insert(view); }
69-
bool has_focus(GUIController* view) { return captured_focus.count(view) != 0; }
70-
void release_focus(GUIController* view) { captured_focus.erase(view); }
69+
void give_focus(Controller* view) { captured_focus.insert(view); }
70+
bool has_focus(Controller* view) { return captured_focus.count(view) != 0; }
71+
void release_focus(Controller* view) { captured_focus.erase(view); }
7172

7273

7374
// Equivalent to a user clicking the "x" or pressing cmd-q.
@@ -84,7 +85,7 @@ class App {
8485
int fps_cap;
8586
bool cap_frame_rate;
8687

87-
typedef std::set<GUIController*> view_list_t;
88+
typedef std::set<Controller*> view_list_t;
8889
view_list_t captured_focus;
8990

9091

GUIButton.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class QuitAction {
2525
};
2626

2727

28-
class Button : public GUIImageView {
28+
class Button : public ImageView {
2929
public:
3030

3131
Button()
32-
: GUIImageView(GUIImage("GUIImages/button.bmp")),
32+
: ImageView(GUIImage("GUIImages/button.bmp")),
3333
is_pressed(false), is_hovered(false),
3434
image(GUIImage("GUIImages/button.bmp")), hovered_image(GUIImage("GUIImages/button2.bmp")),
3535
clicked_image(GUIImage("GUIImages/button3.bmp"))
@@ -117,17 +117,17 @@ class TextButton : public Button {
117117
public:
118118
TextButton(const std::string &button_text_ = "")
119119
{
120-
button_text = new GUITextView(get_w()-30, get_h());
120+
button_text = new TextView(get_w()-30, get_h());
121121
button_text->set_text(button_text_);
122122
button_text->set_text_size(16);
123123
attach_subview(button_text, DispPoint(get_w()-button_text->get_w(), 0));
124124
}
125125

126-
GUITextView* get_text_view() { return button_text; }
126+
TextView* get_text_view() { return button_text; }
127127
void set_text(const std::string &button_text_) { button_text->set_text(button_text_); }
128128

129129
public:
130-
GUITextView *button_text;
130+
TextView *button_text;
131131
};
132132

133133

GUIController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
using GUI::App;
1616

17-
void GUIController::capture_focus() {
17+
void GUI::Controller::capture_focus() {
1818

1919
if (App::get()->has_focus(this)) return;
2020

2121
App::get()->give_focus(this);
2222

2323
got_focus();
2424
}
25-
void GUIController::lose_focus() {
25+
void GUI::Controller::lose_focus() {
2626
if (!App::get()->has_focus(this)) return; //throw GUIError("Can't lose_focus if didn't already have it.");
2727

2828
App::get()->release_focus(this);

GUIController.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include "Compatibility.h"
1313
#include "GUIUtility.h"
1414

15+
namespace GUI {
16+
1517
// This class is seperated out from GUIView to allow creation of a class to
1618
// receive mouse/key events without having to associate it with a displayed view.
17-
class GUIController {
19+
class Controller {
1820

1921
public:
20-
virtual ~GUIController() {}
22+
virtual ~Controller() {}
2123

2224
// Mouse Events. Following three functions all work the same:
2325
// Return true if the mouse-event is finished being handled, false otherwise.
@@ -52,5 +54,6 @@ class GUIController {
5254
void lose_focus();
5355
};
5456

57+
} // namespace GUI
5558

5659
#endif

GUIImageView.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
#include "GUIImage.h"
1212
#include "GameDisplay.h"
1313

14-
using GUI::View;
14+
namespace GUI {
1515

16-
GUIImageView::GUIImageView(const GUIImage &image_src)
16+
ImageView::ImageView(const GUIImage &image_src)
1717
: View(image_src.getw(), image_src.geth())
1818
{
1919
draw_onto_self(image_src, DispPoint(0,0));
2020
}
2121

22-
GUIImage GUIImageView::get_image() {
22+
GUIImage ImageView::get_image() {
2323

2424
return GUIImage::create_copy(get_image_ptr());
2525
}
26+
27+
} // namespace GUI

GUIImageView.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
#include "GUIView.h"
1313

1414
class GUIImage;
15-
class GUIImageView : public GUI::View {
15+
16+
namespace GUI {
17+
18+
class ImageView : public GUI::View {
1619
public:
1720

18-
GUIImageView(const GUIImage &image_src);
21+
ImageView(const GUIImage &image_src);
1922

2023
GUIImage get_image();
2124

2225
//private:
2326
// void attach_subview(GUIView* view, DispPoint pos);
2427
};
2528

29+
} // namespace GUI
2630

2731
#endif /* GUIIMAGEVIEW_H */

GUIMsgNew.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
#include <iostream>
1717
using std::cout; using std::endl;
18-
using GUI::App;
19-
using GUI::Button;
20-
using GUI::View;
2118

2219
const SDL_Color color = {0xbb, 0xbb, 0xbb, 0};
2320

24-
GUIMsgNew::GUIMsgNew(int w_, int h_, const std::string& msg_, Button_ctrs_t buttons_)
25-
:View(w_,h_), msg_text(new GUITextView(w_-10, h_-10)), buttons(buttons_)
21+
22+
namespace GUI {
23+
24+
MsgNew::MsgNew(int w_, int h_, const std::string& msg_, Button_ctrs_t buttons_)
25+
:View(w_,h_), msg_text(new TextView(w_-10, h_-10)), buttons(buttons_)
2626
{
2727
attach_subview(msg_text, DispPoint(get_w()/2 - msg_text->get_w()/2, 5));
2828

@@ -36,25 +36,25 @@ GUIMsgNew::GUIMsgNew(int w_, int h_, const std::string& msg_, Button_ctrs_t butt
3636

3737
}
3838

39-
void GUIMsgNew::set_msg(const std::string msg_) {
39+
void MsgNew::set_msg(const std::string msg_) {
4040

4141
msg_text->set_text(msg_);
4242

4343
}
44-
void GUIMsgNew::add_button(Button* button) {
44+
void MsgNew::add_button(Button* button) {
4545

4646
attach_subview(button, DispPoint(get_w() - 180 - (int)buttons.size()*180, get_h()- 30));
4747
buttons.push_back(button);
4848
}
4949

5050

5151

52-
GUIMsgNew_Scroll_In::GUIMsgNew_Scroll_In(int w_, int h_, const std::string& msg_, Button_ctrs_t buttons_)
53-
:GUIMsgNew(w_,h_, msg_, buttons_)
52+
MsgNew_Scroll_In::MsgNew_Scroll_In(int w_, int h_, const std::string& msg_, Button_ctrs_t buttons_)
53+
:MsgNew(w_,h_, msg_, buttons_)
5454
{ }
5555

5656

57-
void GUIMsgNew_Scroll_In::pop_up(int timeout)
57+
void MsgNew_Scroll_In::pop_up(int timeout)
5858
{
5959
// Store a copy of the screen for the scroll away.
6060
GUIImage temp_screen(get_w(), get_h());
@@ -109,9 +109,10 @@ void GUIMsgNew_Scroll_In::pop_up(int timeout)
109109

110110

111111

112-
void GUIMsgNew::pop_up_modal()
113-
{
114-
pop_up();
115-
116-
}
112+
//void MsgNew_Scroll_In::pop_up_modal()
113+
//{
114+
// pop_up();
115+
//}
116+
117+
} // namespace GUI
117118

GUIMsgNew.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
#include <string>
1515
#include <vector>
1616

17-
class GUITextView;
1817

1918
namespace GUI {
19+
2020
class Button;
21-
}
21+
class TextView;
2222

23-
class GUIMsgNew : public GUI::View {
23+
class MsgNew : public View {
2424
public:
25-
typedef std::vector<GUI::Button*> Button_ctrs_t;
25+
typedef std::vector<Button*> Button_ctrs_t;
2626

2727
// Size of button_texts must == num_buttons
28-
GUIMsgNew(int w_, int h_, const std::string& msg = "", Button_ctrs_t buttons = Button_ctrs_t());
28+
MsgNew(int w_, int h_, const std::string& msg = "", Button_ctrs_t buttons = Button_ctrs_t());
2929

3030
void set_msg(const std::string msg_);
3131

@@ -34,24 +34,27 @@ class GUIMsgNew : public GUI::View {
3434
virtual void pop_up(int timeout = -1) = 0; // ms until window disappears.
3535

3636
// Note, this is not yet implemented.
37-
virtual void pop_up_modal(); // stop everything else.
37+
// virtual void pop_up_modal(); // stop everything else.
3838

3939
private:
4040

41-
std::vector<GUI::Button*> buttons;
42-
GUITextView *msg_text;
41+
std::vector<Button*> buttons;
42+
TextView *msg_text;
4343
};
4444

45-
class GUIMsgNew_Scroll_In : public GUIMsgNew {
45+
class MsgNew_Scroll_In : public MsgNew {
4646
public:
47-
typedef std::vector<GUI::Button*> Button_ctrs_t;
47+
typedef std::vector<Button*> Button_ctrs_t;
4848

4949
// Size of button_texts must == num_buttons
50-
GUIMsgNew_Scroll_In(int w_, int h_, const std::string& msg = "", Button_ctrs_t buttons = Button_ctrs_t());
50+
MsgNew_Scroll_In(int w_, int h_, const std::string& msg = "", Button_ctrs_t buttons = Button_ctrs_t());
5151

5252
virtual void pop_up(int timeout = -1) = 0; // ms until window disappears.
5353

54+
// virtual void pop_up_modal(); // stop everything else.
55+
5456
};
5557

58+
} // namespace GUI
5659

5760
#endif

GUIScrollView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class GUIScrollView : public View {
6262
bool clicked;
6363
DispPoint click;
6464
};
65-
class ScrollArrow : public GUIImageView {
65+
class ScrollArrow : public ImageView {
6666
public:
6767
ScrollArrow(bool up_down_, const GUIImage& image)
68-
: GUIImageView(image), up_down(up_down_) { }
68+
: ImageView(image), up_down(up_down_) { }
6969

7070
virtual bool handle_mouse_down(DispPoint coord);
7171
virtual bool handle_mouse_up(DispPoint coord);

0 commit comments

Comments
 (0)