-
Notifications
You must be signed in to change notification settings - Fork 2
/
text_field.h
127 lines (111 loc) · 4.42 KB
/
text_field.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* text_field.h -*- C++ -*-
* by Trinity Quirk <[email protected]>
* last updated 17 Jan 2021, 09:59:19 tquirk
*
* CuddlyGL OpenGL widget toolkit
* Copyright (C) 2021 Trinity Annabelle Quirk
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* This file contains the text field declaration. We're subclassing
* the label, since it already has font handling built in. We'll be
* adding keyboard handling and a moving cursor.
*
* Things to do
*
*/
#ifndef __INC_CUDDLY_TEXT_FIELD_H__
#define __INC_CUDDLY_TEXT_FIELD_H__
#include <chrono>
#include <mutex>
#include "label.h"
namespace ui
{
class text_field : public label
{
protected:
GLuint cursor_pos, blink, max_length;
GLuint repeat_initial, repeat_delay;
GLuint cursor_vao, cursor_vbo, cursor_ebo, cursor_element_count;
glm::mat4 cursor_transform;
std::chrono::high_resolution_clock::time_point cursor_clock;
bool cursor_visible, cursor_active;
std::mutex repeat_mutex;
using ui::label::get_size;
virtual int get_size(GLuint, GLuint *) const override;
using ui::label::set_size;
virtual void set_size(GLuint, GLuint) override;
virtual int get_cursor(GLuint, GLuint *) const;
virtual void set_cursor(GLuint, GLuint);
virtual int get_repeat(GLuint, GLuint *) const;
virtual void set_repeat(GLuint, GLuint);
virtual void set_font(GLuint, ui::base_font *) override;
virtual void set_string(GLuint, const std::string&) override;
virtual void set_image(GLuint, const ui::image&) final;
static void focus_callback(active *, void *, void *);
static void key_down_callback(active *, void *, void *);
static void key_up_callback(active *, void *, void *);
static void key_timeout(active *, void *);
int get_cursor_pos(GLuint *) const;
void set_cursor_pos(GLuint);
int get_cursor_blink(GLuint *) const;
void set_cursor_blink(GLuint);
int get_initial_repeat(GLuint *) const;
void set_initial_repeat(GLuint);
int get_secondary_repeat(GLuint *) const;
void set_secondary_repeat(GLuint);
void apply_key(const ui::key_call_data *);
void reset_cursor(void);
void activate_cursor(void);
void deactivate_cursor(void);
void first_char(void);
void previous_char(void);
void next_char(void);
void last_char(void);
void insert_char(uint32_t);
void remove_previous_char(void);
void remove_next_char(void);
virtual void get_string_size(const std::u32string&,
GLuint&, GLuint&, GLuint&);
virtual int get_raw_cursor_pos(void);
void set_cursor_transform(int);
int calculate_field_length(void);
virtual void generate_string_image(void) override;
virtual void calculate_widget_size(void) override;
void generate_cursor(void);
virtual vertex_buffer *generate_points(void) override;
void init(composite *);
public:
explicit text_field(composite *);
template<typename... Args>
text_field(composite *c, Args... args)
: rect(0, 0), active(0, 0), label(c), cursor_transform()
{
this->init(c);
this->set(args...);
};
virtual ~text_field();
using ui::label::get;
virtual int get(GLuint, GLuint, GLuint *) const override;
using ui::label::set;
virtual void set(GLuint, GLuint, GLuint) override;
GET_VA;
SET_VA;
virtual void draw(GLuint, const glm::mat4&) override;
static void (*focus_hook)(bool);
};
}
#endif /* __INC_CUDDLY_TEXT_FIELD_H__ */