-
Notifications
You must be signed in to change notification settings - Fork 6
/
NewNewGUITextView.h
71 lines (49 loc) · 1.64 KB
/
NewNewGUITextView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// NewTextView.h
// Deep
//
// Created by Nathan Daly on 1/4/13.
// Copyright (c) 2013 Lions Entertainment. All rights reserved.
//
#ifndef Deep_NewTextView_h
#define Deep_NewTextView_h
#include "GUIView.h"
//#include <vector>
#include <list>
namespace GUI {
struct LetterData {
LetterData(char c_, int size_, SDL_Color color_)
: c(c_), size(size_), color(color_)
{ }
char c; // unused when assinging data for a TextView.
int size;
SDL_Color color;
bool operator<(const LetterData& rhs) const;
};
//---------------
extern const SDL_Color text_color_black_c;
class NewTextView : public GUI::View {
public:
NewTextView(int w, int h, int size = 30, SDL_Color color = text_color_black_c);
virtual void draw();
// Set the size and/or color for the text.
// If start/end Index are ignored, will apply to all text.
// Any new text created will always use the last added letter data.
// (the character is irrelevant in data.)
void set_letter_data(const LetterData& data,
size_t startIdx = 0, size_t endIdx = std::string::npos);
void set_text(const std::string& text);
void add_text(const std::string& text, int index);
void append_text(const std::string& text);
std::string get_text() const;
// NOTE: for index_at_pos, make each letter a subview, and have mouse click
// just return its index? Not a bad idea.
private:
typedef std::list<LetterData> letter_ctr_t;
letter_ctr_t text;
LetterData prev;
// DispPoint pos_at_index(size_t i);
int index_at_pos(DispPoint pos_);
};
} // namespace GUI
#endif