//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基础类)相关推荐

  1. mre下的控件实现(四、Button使用)

    这里有一个实例使用(一.实现)中的按钮控件,达到的效果如下图所示, 用mre sdk(这里使用的是mre sdk 2.5版本)创建一个工程,工程名为mtid(实际上这个是我要在做一个工具). //生成 ...

  2. mre下的控件实现(三、Button实现)

    实现button控件,其他控件类此写便是了. //button.h 按钮控件#ifndef __BUTTON_H__ #define __BUTTON_H__#include "widget ...

  3. mre下的控件实现(一、公共的宏定义)

    //typedef.h一些公共的宏定义#ifndef __TYPEDEF_H__ #define __TYPEDEF_H__#include "vmlog.h" #include ...

  4. Material Design控件使用(二)

    本篇接着之前的Material Design控件总结(一)往下学习support design包下其余控件,如果对Material Design不太熟悉的同学最好把第一篇看完再来看第二篇效果更好 本篇 ...

  5. 【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 ...

  6. 自定义可扩展叠加头部的下拉控件

    最近写了个下拉控件,和几个下拉的头部样式,下拉控件可以连续添加叠加几个头部视图 下面是没有添加任何头部尾部的视图下拉效果 一步一步来介绍,先介绍这个下拉效果,在介绍自定义的头部 首先在使用上,和普通的 ...

  7. 【GIS开发】VB6.0下MO控件的安装:安装教程及MO破解教程(MapObjects2.x)

    [GIS开发]VB6.0下MO控件的安装:安装教程及MO破解教程(MapObjects2.x) 基于MO和VB的GIS开发过程中,普遍使用的还是2.0及以上版本,ESRI公司早已不再对MO组件进行更新 ...

  8. Android 原生控件之二 ImageView

    Android 原生控件之二 ImageView 相关 来源 开始 XML属性 1.android:adjustViewBounds 2.android:baseline 3.android:base ...

  9. Xamarin XAML语言教程构建ControlTemplate控件模板 (二)

    Xamarin XAML语言教程构建ControlTemplate控件模板 (二) (2)打开MainPage.xaml文件,编写代码,将构建的控件模板应用于ContentView中.代码如下: &l ...

最新文章

  1. Kotlin 中infix,inline,noinline,crossinline ,refied 等的理解
  2. Unity3D深入浅出 -组件与节点之间的调用关系
  3. 将长整形的数字分位显示
  4. 全球及中国潜水压力传感器行业运行态势及发展战略研究报告2022-2027年
  5. SQL--Chapter8--Working with Triggers and Transactions
  6. mapgis转arcgis数据后发现属性表内没有数据
  7. ansible 配置文件
  8. WorkManager从入门到实践,有这一篇就够了
  9. 首款搭载鸿蒙OS的智能手机,首款搭载鸿蒙OS 华为智选智能摄像头Pro零点全网开售:299元...
  10. 拓扑一致体参数化的复杂模型的等几何分析计算重用
  11. 【传】玩转Android---UI篇---ImageButton(带图标的按钮)
  12. 2019年7月9日星期二(C语言)
  13. 20200927:Java和Cpp中栈与队列的区别
  14. YYKit(Base模块)学习笔记
  15. 一、vmware的安装
  16. 初次Blender建模遇到的问题与解决方法(二)
  17. 美年旅游_套餐管理_分页PageHelper
  18. .net 初中级程序员招聘
  19. 计算机导航窗格里没有桌面,今天解决win10 导航窗格怎么添加桌面的解决环节
  20. 2019杭电多校第七场 Kejin Player HDU - 6656 (期望)

热门文章

  1. Word域代码:TOA,自动生成目录
  2. with(this)中with
  3. 汇编语言error A2044: invalid character in file
  4. oracle数据库培训
  5. 红象云腾童小军:建立开放联盟,加速大数据处理,完善大数据生态
  6. 网络创世纪服务器端源码
  7. VMWare之Windows硬盘扩容
  8. 解决Attempt to invoke virtual method '...ListAdapter'on a null object reference
  9. 类型多样的石膏PBR多通道贴图素材,速来收藏!
  10. 非常不错的表单设计器(源码)