mre下的控件实现(二、Widget基础类)
//widget.h 所有控件的基类
//mre本身只有简单的GDI函数,没有控件,在mre里写应用都
//要自己实现自己的control,这里把control的基类widget实现了。
#ifndef __WIDGET_H__
#define __WIDGET_H__#include "typedef.h"#define MAX_WIDGET_CHILD 0x20struct _Widget;
typedef struct _Widget Widget;struct _Base;
typedef struct _Base Base;enum _ControlType
{CONTROL_TYPE_VIEW,CONTROL_TYPE_BUTTON,CONTROL_TYPE_LABEL,CONTROL_TYPE_NR
};
typedef enum _ControlType ControlType;typedef int (*OnKeyEventFunc) (Widget* thiz, int event, int keycode);
typedef int (*OnPenEventFunc) (Widget* thiz, int event, int x, int y);
typedef int (*OnPaintFunc) (Widget* thiz);
typedef int (*OnDestroyFunc)(Widget* thiz);typedef struct _Rect
{int x_pos;int y_pos;int width;int height;
} Rect;struct _Widget
{OnKeyEventFunc on_key_event;OnPenEventFunc on_pen_event;OnPaintFunc on_paint;OnDestroyFunc on_destroy;Widget* parent;Widget* child[MAX_WIDGET_CHILD];Base* base;void* extra;
};static _INLINE_ int widget_on_key_evt(Widget* thiz, int event, int keycode)
{if(NULL != thiz)thiz->on_key_event( thiz, event, keycode);
}static _INLINE_ int widget_on_pen_evt(Widget* thiz, int event, int x, int y)
{if(NULL != thiz)thiz->on_pen_event( thiz, event, x, y);
}static _INLINE_ int widget_on_paint(Widget* thiz)
{if(NULL != thiz)thiz->on_paint( thiz);
}static _INLINE_ int widget_on_destroy(Widget* thiz)
{if(NULL != thiz)thiz->on_destroy( thiz);
}/** 函数名:widget_init* 说明:初始化widget,主要是初始化base* 参数说明:*/
void widget_init(Widget* thiz, ControlType type, int id, Rect rect, int* layer);
void widget_deinit(Widget* thiz);/** 函数名:widget_add_child* 说明:增加子控件* 参数说明:*/
int widget_add_child(Widget* thiz, Widget* child);/** 函数名:widget_set_back_color* 说明:设置背景颜色* 参数说明:*/
void widget_set_back_color(Widget* thiz, vm_graphic_color color);/** 函数名:widget_get_back_color* 说明:获取背景颜色* 参数说明:*/
vm_graphic_color widget_get_back_color(Widget* thiz);/** 函数名:widget_set_fore_color* 说明:设置前景颜色* 参数说明:*/
void widget_set_fore_color(Widget* thiz, vm_graphic_color color);/** 函数名:widget_get_fore_color* 说明:获取前景颜色* 参数说明:*/
vm_graphic_color widget_get_fore_color(Widget* thiz);/** 函数名:widget_set_visible* 说明:设置是否可见* 参数说明:*/
void widget_set_visible(Widget* thiz,int visible);/** 函数名:widget_is_visible* 说明:获取是否可见* 参数说明:*/
int widget_is_visible(Widget* thiz);/** 函数名:widget_set_focus* 说明:设置字体大小* 参数说明:*/
void widget_set_focus(Widget* thiz, int focus);/** 函数名:widget_is_focus* 说明:是否是当前焦点* 参数说明:*/
int widget_is_focus(Widget* thiz);/** 函数名:widget_get_parent* 说明:获取父窗体* 参数说明:*/
Widget* widget_get_parent(Widget* thiz);/** 函数名:widget_get_type* 说明:获取窗体类型* 参数说明:*/
ControlType widget_get_type(Widget* thiz);/** 函数名:widget_is_point_in_area* 说明:判断坐标点是否在控件区域内* 参数说明:*/
int widget_is_point_in_area(Widget* thiz, int x_pos, int y_pos);/** 函数名:widget_set_layer_index* 说明:设置图层下标* 参数说明:*/
void widget_set_layer_index(Widget* thiz, int layer_index);/** 函数名:widget_get_layer_index* 说明:获取图层下标* 参数说明:*/
int widget_get_layer_index(Widget* thiz);/** 函数名:widget_get_layer* 说明:获取图层数组* 参数说明:*/
int* widget_get_layer(Widget* thiz);/** 函数名:widget_get_x_pos* 说明:获取相对x坐标* 参数说明:*/
int widget_get_x_pos(Widget* thiz);/** 函数名:widget_get_x_pos_abs* 说明:获取绝对x坐标* 参数说明:*/
int widget_get_x_pos_abs(Widget* thiz);/** 函数名:widget_get_y_pos* 说明:获取相对y坐标* 参数说明:*/
int widget_get_y_pos(Widget* thiz);/** 函数名:widget_get_y_pos_abs* 说明:获取绝对y坐标* 参数说明:*/
int widget_get_y_pos_abs(Widget* thiz);/** 函数名:widget_get_width* 说明:增加窗体宽度* 参数说明:*/
int widget_get_width(Widget* thiz);/** 函数名:widget_get_height* 说明:获取窗体高度* 参数说明:*/
int widget_get_height(Widget* thiz);#endif /*__WIDGET_H__*/
//widget.c 窗体(控件)公共的接口#include "widget.h"struct _Base
{int id;int offset_x;int offset_y;Rect rect;ControlType type;int tab_order;int visible;int focus;int backdraw;vm_graphic_color fore_color;vm_graphic_color back_color;VMINT *layer;VMINT layer_index;
};void widget_init(Widget* thiz, ControlType type, int id, Rect rect, int* layer)
{thiz->base = WBH_MALLOC(sizeof(Base));thiz->base->rect.x_pos = rect.x_pos;thiz->base->rect.y_pos = rect.y_pos;thiz->base->rect.height = rect.height;thiz->base->rect.width = rect.width;thiz->base->visible = TRUE;thiz->base->layer = layer;thiz->base->type = type;thiz->base->back_color.vm_color_565 = VM_COLOR_WHITE;thiz->base->fore_color.vm_color_565 = VM_COLOR_BLACK;
}void widget_deinit(Widget* thiz)
{if(NULL != thiz && NULL != thiz->base)WBH_FREE(thiz->base);
}Widget* widget_get_parent(Widget* thiz)
{if(NULL != thiz)return thiz->parent;
}void widget_set_back_color(Widget* thiz, vm_graphic_color color)
{if(NULL != thiz && NULL != thiz->base)thiz->base->back_color = color;
}vm_graphic_color widget_get_back_color(Widget* thiz)
{if(NULL != thiz && NULL != thiz->base)return thiz->base->back_color;
}void widget_set_fore_color(Widget* thiz, vm_graphic_color color)
{if(NULL != thiz && NULL != thiz->base)thiz->base->fore_color = color;
}vm_graphic_color widget_get_fore_color(Widget* thiz)
{if(NULL != thiz && NULL != thiz->base)return thiz->base->fore_color;
}void widget_set_visible(Widget* thiz,int visible)
{if(NULL != thiz && NULL != thiz->base)thiz->base->visible = visible;
}int widget_is_visible(Widget* thiz)
{int ret = FALSE;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->visible;return ret;
}void widget_set_focus(Widget* thiz, int focus)
{if(NULL != thiz && NULL != thiz->base)thiz->base->focus = focus;
}int widget_is_focus(Widget* thiz)
{int ret = FALSE;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->focus;return ret;
}ControlType widget_get_type(Widget* thiz)
{ControlType ret = CONTROL_TYPE_NR;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->type;return ret;
}int widget_is_point_in_area(Widget* thiz, int x_pos, int y_pos)
{int ret = FALSE;if(NULL != thiz && NULL != thiz->base){Rect rect = thiz->base->rect;if(x_pos >= rect.x_pos && x_pos <= rect.x_pos + rect.width && y_pos >= rect.y_pos && y_pos <= rect.y_pos + rect.height)ret = TRUE;}return ret;
}void widget_set_layer_index(Widget* thiz, int layer_index)
{if(NULL != thiz && NULL != thiz->base)thiz->base->layer_index = layer_index;
}int widget_get_layer_index(Widget* thiz)
{if(NULL != thiz && NULL != thiz->base)return thiz->base->layer_index;
}int* widget_get_layer(Widget* thiz)
{int* ret = NULL;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->layer;return ret;
}int widget_get_x_pos(Widget* thiz)
{int ret = 0;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->rect.x_pos;return ret;
}int widget_get_x_pos_abs(Widget* thiz)
{int ret = 0;Widget* widget = widget_get_parent(thiz);ret = widget_get_x_pos(thiz);while(NULL != widget){ret += widget_get_x_pos(widget);widget = widget_get_parent(widget);}return ret;
}int widget_get_y_pos(Widget* thiz)
{int ret = 0;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->rect.y_pos;return ret;
}int widget_get_y_pos_abs(Widget* thiz)
{int ret = 0;Widget* widget = widget_get_parent(thiz);ret = widget_get_y_pos(thiz);while(NULL != widget){ret += widget_get_y_pos(widget);widget = widget_get_parent(widget);}return ret;
}int widget_get_width(Widget* thiz)
{int ret = 0;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->rect.width;return ret;
}int widget_get_height(Widget* thiz)
{int ret = 0;if(NULL != thiz && NULL != thiz->base)ret = thiz->base->rect.height;return ret;
}int widget_add_child(Widget* thiz, Widget* child)
{int i = -1;if(NULL != thiz){for(i = 0; i < MAX_WIDGET_CHILD; ++i){if(NULL == thiz->child[i] && NULL != child){thiz->child[i] = child;child->parent = thiz;break;}}}return i;
}
转载于:https://www.cnblogs.com/WIT-Evan/archive/2012/08/12/7291481.html
mre下的控件实现(二、Widget基础类)相关推荐
- mre下的控件实现(四、Button使用)
这里有一个实例使用(一.实现)中的按钮控件,达到的效果如下图所示, 用mre sdk(这里使用的是mre sdk 2.5版本)创建一个工程,工程名为mtid(实际上这个是我要在做一个工具). //生成 ...
- mre下的控件实现(三、Button实现)
实现button控件,其他控件类此写便是了. //button.h 按钮控件#ifndef __BUTTON_H__ #define __BUTTON_H__#include "widget ...
- mre下的控件实现(一、公共的宏定义)
//typedef.h一些公共的宏定义#ifndef __TYPEDEF_H__ #define __TYPEDEF_H__#include "vmlog.h" #include ...
- Material Design控件使用(二)
本篇接着之前的Material Design控件总结(一)往下学习support design包下其余控件,如果对Material Design不太熟悉的同学最好把第一篇看完再来看第二篇效果更好 本篇 ...
- 【pyqt5学习】——containers相关控件(tab widget、scroll area、stack widget、tool box、MDI area、dock widget)
目录 1.tab widget 2.scroll area 2.1 使用方法 Step1.拖入QScrollArea Step2.改变widget控件布局 Step3.设置scrollAreaWi ...
- 自定义可扩展叠加头部的下拉控件
最近写了个下拉控件,和几个下拉的头部样式,下拉控件可以连续添加叠加几个头部视图 下面是没有添加任何头部尾部的视图下拉效果 一步一步来介绍,先介绍这个下拉效果,在介绍自定义的头部 首先在使用上,和普通的 ...
- 【GIS开发】VB6.0下MO控件的安装:安装教程及MO破解教程(MapObjects2.x)
[GIS开发]VB6.0下MO控件的安装:安装教程及MO破解教程(MapObjects2.x) 基于MO和VB的GIS开发过程中,普遍使用的还是2.0及以上版本,ESRI公司早已不再对MO组件进行更新 ...
- Android 原生控件之二 ImageView
Android 原生控件之二 ImageView 相关 来源 开始 XML属性 1.android:adjustViewBounds 2.android:baseline 3.android:base ...
- Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
Xamarin XAML语言教程构建ControlTemplate控件模板 (二) (2)打开MainPage.xaml文件,编写代码,将构建的控件模板应用于ContentView中.代码如下: &l ...
最新文章
- python坐标点怎么输入_python导入坐标点的具体操作
- DearGUI编写贪吃蛇之让蛇跑的方向受控制_最新
- EJB的分类及其各自的功能和应用
- python3精要(49)-生成器
- Nis服务器主从安装配置
- YII CDbCriteria 的一些常用方法记录
- 工作286:v-model没有值会报错
- 自动驾驶 | 清华车辆与运载学院最新科研成果公布!
- 上线随想之2011-03-26
- node.js webpack html-webpack-plugin
- 【转】关于浮点数的精度与取值范围的问题
- Atitit 理解Monad attilax总结Atiti
- 【游戏开发3D数学笔记】1.有话说在前面
- PyQT多线程串口 QtDesigner
- 迪文屏程序制作。通讯
- CentOS7.6的详细安装步骤
- 内存取证之Volatility ——合天网安实验室学习笔记
- 听说,某团队今天开了4小时评审会……
- 宝塔linux面板命令大全
- RH Timer for Mac(定时器软件)
热门文章
- 鉴权,开放式授权,单点登陆
- REXROTH力士乐比例阀4WRZE25W8-220-7X/6EG24N9K31/A1D3M
- HTML关闭当前网页
- Vue中预览HIKVSION海康威视的NVR(网络硬盘录像机)中多个通道(摄像机)的视频
- 软件 黑苹果盒盖不休眠_如何设置mac盖上盖子不休眠
- php writevarint64_PHP浮点数的一个常见问题的解答
- 【测试】自动化测试01
- python函数助手_转jmeter(十五)函数助手
- Fire Workflow 1.0正式版终于发布了
- 实用的JS正则表达式 (正数正则、IP正则、邮编正则等)