mre下的控件实现(二、Widget基础类)

本文详细介绍了Widget控件基类的实现,包括初始化、销毁、子控件管理、颜色设置、可见性控制等功能,并提供了关键接口和内部结构Base的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//widget.h 所有控件的基类
//mre本身只有简单的GDI函数,没有控件,在mre里写应用都
//要自己实现自己的control,这里把control的基类widget实现了。
#ifndef __WIDGET_H__
#define __WIDGET_H__

#include "typedef.h"

#define MAX_WIDGET_CHILD 0x20

struct _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

内容概要:该PPT详细介绍了企业架构设计的方法论,涵盖业务架构、数据架构、应用架构和技术架构四大核心模块。首先分析了企业架构现状,包括业务、数据、应用和技术四大架构的内容和关系,明确了企业架构设计的重要性。接着,阐述了新版企业架构总体框架(CSG-EAF 2.0)的形成过程,强调其融合了传统架构设计(TOGAF)和领域驱动设计(DDD)的优势,以适应数字化转型需求。业务架构部分通过梳理企业级和专业级价值流,细化业务能力、流程和对象,确保业务战略的有效落地。数据架构部分则遵循五大原则,确保数据的准确、一致和高效使用。应用架构方面,提出了分层解耦和服务化的设计原则,以提高灵活性和响应速度。最后,技术架构部分围绕技术框架、组件、平台和部署节点进行了详细设计,确保技术架构的稳定性和扩展性。 适合人群:适用于具有一定企业架构设计经验的IT架构师、项目经理和业务分析师,特别是那些希望深入了解如何将企业架构设计与数字化转型相结合的专业人士。 使用场景及目标:①帮助企业和组织梳理业务流程,优化业务能力,实现战略目标;②指导数据管理和应用开发,确保数据的一致性和应用的高效性;③为技术选型和系统部署提供科学依据,确保技术架构的稳定性和扩展性。 阅读建议:此资源内容详尽,涵盖企业架构设计的各个方面。建议读者在学习过程中,结合实际案例进行理解和实践,重点关注各架构模块之间的关联和协同,以便更好地应用于实际工作中。
资 源 简 介 独立分量分析(Independent Component Analysis,简称ICA)是近十年来逐渐发展起来的一种盲信号分离方法。它是一种统计方法,其目的是从由传感器收集到的混合信号中分离相互独立的源信号,使得这些分离出来的源信号之间尽可能独立。它在语音识别、电信和医学信号处理等信号处理方面有着广泛的应用,目前已成为盲信号处理,人工神经网络等研究领域中的一个研究热点。本文简要的阐述了ICA的发展、应用和现状,详细地论述了ICA的原理及实现过程,系统地介绍了目前几种主要ICA算法以及它们之间的内在联系, 详 情 说 明 独立分量分析(Independent Component Analysis,简称ICA)是近十年来逐渐发展起来的一种盲信号分离方法。它是一种统计方法,其目的是从由传感器收集到的混合信号中分离相互独立的源信号,使得这些分离出来的源信号之间尽可能独立。它在语音识别、电信和医学信号处理等信号处理方面有着广泛的应用,目前已成为盲信号处理,人工神经网络等研究领域中的一个研究热点。 本文简要的阐述了ICA的发展、应用和现状,详细地论述了ICA的原理及实现过程,系统地介绍了目前几种主要ICA算法以及它们之间的内在联系,在此基础上重点分析了一种快速ICA实现算法一FastICA。物质的非线性荧光谱信号可以看成是由多个相互独立的源信号组合成的混合信号,而这些独立的源信号可以看成是光谱的特征信号。为了更好的了解光谱信号的特征,本文利用独立分量分析的思想和方法,提出了利用FastICA算法提取光谱信号的特征的方案,并进行了详细的仿真实验。 此外,我们还进行了进一步的研究,探索了其他可能的ICA应用领域,如音乐信号处理、图像处理以及金融数据分析等。通过在这些领域中的实验和应用,我们发现ICA在提取信号特征、降噪和信号分离等方面具有广泛的潜力和应用前景。
标题Spring框架在大型超市前后台系统中的应用研究AI更换标题第1章引言介绍研究背景、意义,分析国内外在该领域的研究现状,并概述论文的研究方法和创新点。1.1研究背景与意义阐述Spring框架在大型超市前后台系统中的应用背景及其实际意义。1.2国内外研究现状分析国内外关于Spring框架在大型超市前后台系统中的应用研究现状。1.3研究方法与创新点介绍论文的研究方法,并突出论文的创新之处。第2章Spring框架及相关技术概述对Spring框架进行简要介绍,包括其核心特性和相关技术。2.1Spring框架简介概述Spring框架的基本概念、主要特点和优势。2.2Spring框架的核心组件详细介绍Spring框架的核心组件,如IoC容器、AOP等。2.3与Spring框架相关的技术阐述与Spring框架紧密相关的技术,如Spring MVC、Spring Data等。第3章大型超市前后台系统需求分析对大型超市前后台系统的需求进行详细分析,为后续系统设计奠定基础。3.1前台系统需求分析分析前台系统的功能需求,如商品展示、购物车管理等。3.2后台系统需求分析分析后台系统的功能需求,如商品管理、订单处理等。3.3非功能性需求分析讨论系统的性能、安全性等非功能性需求。第4章基于Spring框架的大型超市前后台系统设计根据需求分析结果,设计基于Spring框架的大型超市前后台系统。4.1系统架构设计设计系统的整体架构,包括前后台系统的交互方式、数据流向等。4.2数据库设计设计系统的数据库结构,包括表结构、数据关系等。4.3界面设计设计前后台系统的用户界面,确保用户友好性和交互性。第5章系统实现与测试详细阐述系统的实现过程,并对系统进行测试以验证其功能和性能。5.1系统实现按照系统设计,实现前后台系统的各个功能模块。5.2系统测试对系统进行功能测试、性能测试等,确保系统满足需求并具有稳定性
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值