2019-04-17 15:00:47 +08:00
|
|
|
#ifndef WND_H
|
|
|
|
#define 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
|
2019-04-17 15:00:47 +08:00
|
|
|
#define GL_ATTR_DISABLED 0x40000000L
|
|
|
|
#define GL_ATTR_FOCUS 0x20000000L
|
2019-05-24 10:20:40 +08:00
|
|
|
#define GL_ATTR_PRIORITY 0x10000000L// Handle touch action at high priority
|
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;
|
|
|
|
|
2019-04-17 15:00:47 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
KEY_FORWARD,
|
|
|
|
KEY_BACKWARD,
|
|
|
|
KEY_ENTER
|
|
|
|
}KEY_TYPE;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TOUCH_DOWN,
|
|
|
|
TOUCH_UP
|
|
|
|
}TOUCH_ACTION;
|
|
|
|
|
2017-12-06 21:43:47 +08:00
|
|
|
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; }
|
2019-05-24 10:20:40 +08:00
|
|
|
void set_style(unsigned int style);
|
2017-12-06 21:43:47 +08:00
|
|
|
|
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;
|
|
|
|
|
2019-04-17 15:00:47 +08:00
|
|
|
c_wnd* set_child_focus(c_wnd *focus_child);
|
2017-12-06 21:43:47 +08:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2019-05-24 10:20:40 +08:00
|
|
|
void notify_parent(unsigned int msg_id, unsigned int ctrl_id, int param);
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2019-05-24 10:20:40 +08:00
|
|
|
virtual bool on_touch(int x, int y, TOUCH_ACTION action);// return true: handled; false: not be handled.
|
|
|
|
virtual bool on_key(KEY_TYPE key);// return false: skip handling by parent;
|
2017-12-06 21:43:47 +08:00
|
|
|
|
|
|
|
c_surface* get_surface() { return m_surface; }
|
2017-12-13 22:29:28 +08:00
|
|
|
void set_surface(c_surface* surface) { m_surface = surface; }
|
2017-12-06 21:43:47 +08:00
|
|
|
protected:
|
2019-04-17 15:00:47 +08:00
|
|
|
virtual void pre_create_wnd() {};
|
2017-12-06 21:43:47 +08:00
|
|
|
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);
|
2019-04-17 15:00:47 +08:00
|
|
|
void set_active_child(c_wnd* child) { m_focus_child = child; }
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2019-04-17 15:00:47 +08:00
|
|
|
virtual void on_focus() {};
|
|
|
|
virtual void on_kill_focus() {};
|
2017-12-06 21:43:47 +08:00
|
|
|
protected:
|
|
|
|
WND_STATUS m_status;
|
|
|
|
unsigned int m_style;
|
2019-05-24 10:20:40 +08:00
|
|
|
c_rect m_wnd_rect;// position relative to parent wnd.
|
2017-12-06 21:43:47 +08:00
|
|
|
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;
|
2019-04-17 15:00:47 +08:00
|
|
|
c_wnd* m_focus_child;//current focused wnd
|
2017-12-06 21:43:47 +08:00
|
|
|
c_surface* m_surface;
|
|
|
|
private:
|
|
|
|
c_wnd(const c_wnd &win);
|
|
|
|
c_wnd& operator=(const c_wnd &win);
|
|
|
|
};
|
|
|
|
#endif
|