130 lines
3.8 KiB
C
Raw Normal View History

2019-02-02 11:30:40 +08:00
#ifndef GUI_WND_H
#define GUI_WND_H
2017-12-06 21:43:47 +08:00
//Window attribution
2018-12-02 22:39:43 +08:00
#define GL_ATTR_VISIBLE 0x80000000L
#define GL_ATTR_DISABLED 0x40000000L
#define GL_ATTR_FOCUS 0x20000000L
2017-12-06 21:43:47 +08:00
2018-10-04 14:30:29 +08:00
typedef struct struct_font_info FONT_INFO;
typedef struct struct_color_rect COLOR_RECT;
2017-12-06 21:43:47 +08:00
class c_wnd;
class c_surface;
typedef enum
{
STATUS_NORMAL,
STATUS_PUSHED,
STATUS_FOCUSED,
STATUS_DISABLED
}WND_STATUS;
typedef struct struct_wnd_tree
{
c_wnd* p_wnd;
unsigned int resource_id;
2018-12-24 10:39:41 +08:00
const char* str;
2017-12-06 21:43:47 +08:00
short x;
short y;
short width;
short height;
struct struct_wnd_tree* p_child_tree;
}WND_TREE;
class c_wnd : public c_cmd_target
{
friend class c_dialog;
public:
c_wnd();
2018-12-02 22:39:43 +08:00
virtual ~c_wnd() {};
2017-12-06 21:43:47 +08:00
virtual const char* get_class_name() const { return "c_wnd"; }
2018-12-24 10:39:41 +08:00
virtual int connect(c_wnd *parent, unsigned short resource_id, const char* str,
2017-12-06 21:43:47 +08:00
short x, short y, short width, short height, WND_TREE* p_child_tree = NULL);
2018-12-24 10:39:41 +08:00
virtual c_wnd* connect_clone(c_wnd *parent, unsigned short resource_id, const char* str,
2017-12-06 21:43:47 +08:00
short x, short y, short width, short height, WND_TREE* p_child_tree = NULL);
void disconnect();
virtual c_wnd* clone() = 0;
virtual void on_init_children() {}
virtual void on_paint() {}
2018-12-02 22:39:43 +08:00
virtual void show_window();
2017-12-06 21:43:47 +08:00
unsigned short get_id() const { return m_resource_id; }
int get_z_order() { return m_z_order; }
c_wnd* get_wnd_ptr(unsigned short id) const;
unsigned int get_style() const { return m_style; }
virtual void modify_style(unsigned int add_style = 0, unsigned int remove_style = 0);
2018-12-24 10:39:41 +08:00
void set_str(const char* str) { m_str = str; }
2017-12-06 21:43:47 +08:00
int is_focus_wnd() const;
void set_font_color(unsigned int color) { m_font_color = color; }
unsigned int get_font_color() { return m_font_color; }
void set_bg_color(unsigned int color) { m_bg_color = color; }
unsigned int get_bg_color() { return m_bg_color; }
2018-10-04 14:30:29 +08:00
void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; }
const FONT_INFO* get_font_type() { return m_font_type; }
2017-12-06 21:43:47 +08:00
void set_wnd_pos(short x, short y, short width, short height);
void get_wnd_rect(c_rect &rect) const;
void get_screen_rect(c_rect &rect) const;
c_wnd* set_focus(c_wnd *new_active_child);
c_wnd* get_parent() const { return m_parent; }
c_wnd* get_last_child() const;
int unlink_child(c_wnd *child);
c_wnd* get_prev_sibling() const { return m_prev_sibling; }
c_wnd* get_next_sibling() const { return m_next_sibling; }
void notify_parent(unsigned short msg_id, unsigned int w_param, long l_param);
virtual int on_notify(unsigned short notify_code, unsigned short ctrl_id, long l_param);
virtual void on_touch_up(int x, int y);
virtual void on_touch_down(int x, int y);
c_wnd* get_active_child() const { return m_active_child; }
c_surface* get_surface() { return m_surface; }
void set_surface(c_surface* surface) { m_surface = surface; }
2017-12-06 21:43:47 +08:00
protected:
virtual void pre_create_wnd();
void add_child_2_head(c_wnd *child);
void add_child_2_tail(c_wnd *child);
void wnd2screen(int &x, int &y) const;
void wnd2screen(c_rect &rect) const;
void screen2wnd(short &x, short &y) const;
void screen2wnd(c_rect &rect) const;
int load_child_wnd(WND_TREE *p_child_tree);
int load_clone_child_wnd(WND_TREE *p_child_tree);
void set_active_child(c_wnd* child) { m_active_child = child; }
virtual void on_focus();
virtual void on_kill_focus();
protected:
WND_STATUS m_status;
unsigned int m_style;
c_rect m_wnd_rect;//position relative to parent wnd.
c_wnd* m_parent;
c_wnd* m_top_child;
c_wnd* m_prev_sibling;
c_wnd* m_next_sibling;
2018-12-24 10:39:41 +08:00
const char* m_str;
2017-12-06 21:43:47 +08:00
2018-11-09 15:01:48 +08:00
const FONT_INFO* m_font_type;
2017-12-06 21:43:47 +08:00
unsigned int m_font_color;
unsigned int m_bg_color;
unsigned short m_resource_id;
int m_z_order;
c_wnd* m_active_child;
c_surface* m_surface;
private:
c_wnd(const c_wnd &win);
c_wnd& operator=(const c_wnd &win);
};
#endif