整理了Label部件和window部件的C++类

This commit is contained in:
Liu Chao
2012-09-12 21:21:08 +08:00
parent 83e5ed1ced
commit dc6ccbbdfa
9 changed files with 343 additions and 191 deletions
+5 -5
View File
@@ -69,12 +69,12 @@ int Show_Font_Bitmap(LCUI_Bitmap *in_fonts);
/* 功能:在屏幕打印以0和1表示字体位图 */
int Mix_Fonts_Bitmap(
LCUI_Graph *back_graph, /* 背景图形 */
int start_x,
int start_y,
LCUI_Graph *back_graph, /* 背景图形 */
int start_x,
int start_y,
LCUI_Bitmap *in_fonts, /* 传入的字体位图数据 */
LCUI_RGB color, /* 字体的配色 */
int flag
LCUI_RGB color, /* 字体的配色 */
int flag
);
/* 功能:将字体位图数据与背景图形混合 */
+6 -1
View File
@@ -40,7 +40,7 @@
* ****************************************************************************/
#ifndef __LCUI_LABEL_H__
#define __LCUI_LABEL_H__
typedef struct _LCUI_Label LCUI_Label;
typedef struct _LCUI_Label LCUI_Label;
/**************************** lable部件 ********************************/
struct _LCUI_Label
{
@@ -87,4 +87,9 @@ void Set_Label_Font_Default_Color(LCUI_Widget *widget, LCUI_RGB color);
LCUI_END_HEADER
#ifdef __cplusplus
#include LC_LABEL_HPP
#endif
#endif
+79
View File
@@ -0,0 +1,79 @@
/* ***************************************************************************
* LCUI_Label.hpp -- C++ class and function for Label widget
*
* Copyright (C) 2012 by
* Liu Chao
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* LCUI_Label.h -- 文本标签(label)部件的C++类和函数
*
* 版权所有 (C) 2012 归属于
* 刘超
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#ifndef __LCUI_LABEL_HPP__
#define __LCUI_LABEL_HPP__
LCUIWidget::_Label::_Label(LCUIWidget *object)
{
parent = object;
}
int LCUIWidget::_Label::setText(const char *fmt, ...)
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
char text[LABEL_TEXT_MAX_SIZE];
memset(text, 0, sizeof(text));
LCUI_Label *p_label;
p_label = (LCUI_Label*)Get_Widget_Private_Data(parent->getWidget());
va_list ap;
va_start(ap, fmt);
vsnprintf(text, LABEL_TEXT_MAX_SIZE, fmt, ap);
va_end(ap);
Strcpy( &p_label->text, text );/* 拷贝字符串 */
Draw_Widget( parent->getWidget() );/* 更新部件 */
return 0;
}
int LCUIWidget::_Label::setFont(int font_pixel_size, char *fontfile)
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
return Set_Label_Font(parent->getWidget(), font_pixel_size, fontfile);
}
#endif
+154 -181
View File
@@ -46,200 +46,173 @@
#define WIDGET_IS_NULL -5
#include LC_WINDOW_H
#include LC_LABEL_H
#include LC_GRAPHICS_H
class LCUIWidget
{
private:
int error;
LCUI_Widget **widget;
public:
LCUIWidget(const char* widget_type):Label(this),Window(this)
{
error = 0;
widget = new (LCUI_Widget *);
*widget = Create_Widget(widget_type);
if(*widget == NULL){
error = 1;
}
}
~LCUIWidget()
{
delete widget;
}
int isError()
{
return error;
}
LCUI_Widget *getWidget()
{
return *widget;
}
int resize(LCUI_Size new_size)
{
if( error ) return WIDGET_IS_NULL;
Resize_Widget( getWidget() , new_size);
return 0;
}
int move(LCUI_Pos new_pos)
{
if(error) return WIDGET_IS_NULL;
Move_Widget( getWidget() , new_pos);
return 0;
}
int show()
{
if(error) return WIDGET_IS_NULL;
Show_Widget( getWidget() );
return 0;
}
int hide()
{
if(error) return WIDGET_IS_NULL;
Hide_Widget( getWidget() );
return 0;
}
int refresh()
{
if(error) return WIDGET_IS_NULL;
Refresh_Widget( getWidget() );
return 0;
}
int draw()
{
if(error) return WIDGET_IS_NULL;
Draw_Widget( getWidget() );
return 0;
}
int enable()
{
if(error) return WIDGET_IS_NULL;
Enable_Widget( getWidget() );
return 0;
}
int disable()
{
if(error) return WIDGET_IS_NULL;
Disable_Widget( getWidget() );
return 0;
}
int setAlpha(unsigned char alpha)
{
if(error) return WIDGET_IS_NULL;
Set_Widget_Alpha( getWidget() , alpha);
return 0;
}
int setAlign(LCUI_Align align, LCUI_Pos offset_pos)
{
if(error) return WIDGET_IS_NULL;
Set_Widget_Align( getWidget() , align, offset_pos);
return 0;
}
int setBorder(LCUI_RGB color, LCUI_Border border)
{
if(error) return WIDGET_IS_NULL;
Set_Widget_Border( getWidget() , color, border);
return 0;
}
int setBackgroundImage(LCUI_Graph *img, int flag)
{
if(error) return WIDGET_IS_NULL;
return Set_Widget_Background_Image( getWidget() , img, flag);
}
/* label widget */
class _Label
{
public:
_Label(LCUIWidget *object)
{
parent = object;
}
int setText(const char *fmt, ...)
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
char text[LABEL_TEXT_MAX_SIZE];
memset(text, 0, sizeof(text));
LCUI_Label *p_label;
p_label = (LCUI_Label*)Get_Widget_Private_Data(parent->getWidget());
va_list ap;
va_start(ap, fmt);
vsnprintf(text, LABEL_TEXT_MAX_SIZE, fmt, ap);
va_end(ap);
Strcpy( &p_label->text, text );/* 拷贝字符串 */
Draw_Widget( parent->getWidget() );/* 更新部件 */
return 0;
}
int setFont(int font_pixel_size, char *fontfile)
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
return Set_Label_Font(parent->getWidget(), font_pixel_size, fontfile);
}
private:
LCUIWidget *parent;
};
_Label Label;
/* label widget end */
/* window widget */
LCUIWidget(const char* widget_type);
~LCUIWidget();
int isError();
LCUI_Widget *getWidget();
int resize(LCUI_Size new_size);
int move(LCUI_Pos new_pos);
int show();
int hide();
int refresh();
int draw();
int enable();
int disable();
int setAlpha(unsigned char alpha);
int setAlign(LCUI_Align align, LCUI_Pos offset_pos);
int setBorder(LCUI_RGB color, LCUI_Border border);
int setBackgroundImage(LCUI_Graph *img, int flag);
/* window widget class */
class _Window
{
{
public:
_Window( LCUIWidget *object )
{
parent = object;
}
int setTitle( const char *text )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Set_Window_Title_Text(parent->getWidget(), text);
return 0;
}
int setIcon( LCUIGraph &icon )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Set_Window_Title_Icon(parent->getWidget(), &icon.graph);
return 0;
}
int setIcon( LCUI_Graph *icon )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Set_Window_Title_Icon(parent->getWidget(), icon);
return 0;
}
int addToClientArea(LCUIWidget &object)
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Window_Client_Area_Add(parent->getWidget(), object.getWidget());
return 0;
}
_Window( LCUIWidget *object );
int setTitle( const char *text );
int setIcon( LCUIGraph &icon );
int setIcon( LCUI_Graph *icon );
int addToClientArea( LCUIWidget &object );
private:
LCUIWidget *parent;
};
_Window Window;
/* window widget end */
/* window widget class --end-- */
/* label widget class */
class _Label
{
public:
_Label(LCUIWidget *object);
int setText(const char *fmt, ...);
int setFont(int font_pixel_size, char *fontfile);
private:
LCUIWidget *parent;
};
/* label widget class --end-- */
_Label Label;
_Window Window;
private:
int error;
LCUI_Widget **widget;
};
#include LC_WINDOW_H
#include LC_LABEL_H
LCUIWidget::LCUIWidget(const char* widget_type):Label(this),Window(this)
{
error = 0;
widget = new (LCUI_Widget *);
*widget = Create_Widget(widget_type);
if(*widget == NULL){
error = 1;
}
}
LCUIWidget::~LCUIWidget()
{
delete this->widget;
}
int LCUIWidget::isError()
{
return error;
}
LCUI_Widget *LCUIWidget::getWidget()
{
return *widget;
}
int LCUIWidget::resize(LCUI_Size new_size)
{
if( isError() ) return WIDGET_IS_NULL;
Resize_Widget( getWidget() , new_size );
return 0;
}
int LCUIWidget::move(LCUI_Pos new_pos)
{
if( isError() ) return WIDGET_IS_NULL;
Move_Widget( getWidget() , new_pos );
return 0;
}
int LCUIWidget::show()
{
if( isError() ) return WIDGET_IS_NULL;
Show_Widget( getWidget() );
return 0;
}
int LCUIWidget::hide()
{
if( isError() ) return WIDGET_IS_NULL;
Hide_Widget( getWidget() );
return 0;
}
int LCUIWidget::refresh()
{
if( isError() ) return WIDGET_IS_NULL;
Refresh_Widget( getWidget() );
return 0;
}
int LCUIWidget::draw()
{
if( isError() ) return WIDGET_IS_NULL;
Draw_Widget( getWidget() );
return 0;
}
int LCUIWidget::enable()
{
if( isError() ) return WIDGET_IS_NULL;
Enable_Widget( getWidget() );
return 0;
}
int LCUIWidget::disable()
{
if( isError() ) return WIDGET_IS_NULL;
Disable_Widget( getWidget() );
return 0;
}
int LCUIWidget::setAlpha(unsigned char alpha)
{
if( isError() ) return WIDGET_IS_NULL;
Set_Widget_Alpha( getWidget() , alpha);
return 0;
}
int LCUIWidget::setAlign(LCUI_Align align, LCUI_Pos offset_pos)
{
if( isError() ) return WIDGET_IS_NULL;
Set_Widget_Align( getWidget() , align, offset_pos);
return 0;
}
int LCUIWidget::setBorder(LCUI_RGB color, LCUI_Border border)
{
if( isError() ) return WIDGET_IS_NULL;
Set_Widget_Border( getWidget() , color, border);
return 0;
}
int LCUIWidget::setBackgroundImage(LCUI_Graph *img, int flag)
{
if( isError() ) return WIDGET_IS_NULL;
return Set_Widget_Background_Image( getWidget() , img, flag);
}
#endif
#endif
+4
View File
@@ -101,4 +101,8 @@ void Window_TitleBar_Add(LCUI_Widget *window, LCUI_Widget *widget);
LCUI_END_HEADER
#ifdef __cplusplus
#include LC_WINDOW_HPP
#endif
#endif /* __LCUI_WINDOW_H__ */
+89
View File
@@ -0,0 +1,89 @@
/* ***************************************************************************
* LCUI_Window.h -- C++ class and function for window widget
*
* Copyright (C) 2012 by
* Liu Chao
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* LCUI_Window.h -- 窗口部件的C++类和函数
*
* 版权所有 (C) 2012 归属于
* 刘超
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#ifndef __LCUI_WINDOW_HPP_
#define __LCUI_WINDOW_HPP_
LCUIWidget::_Window::_Window( LCUIWidget *object )
{
parent = object;
}
int LCUIWidget::_Window::setTitle( const char *text )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Set_Window_Title_Text(parent->getWidget(), text);
return 0;
}
int LCUIWidget::_Window::setIcon( LCUIGraph &icon )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Set_Window_Title_Icon(parent->getWidget(), &icon.graph);
return 0;
}
int LCUIWidget::_Window::setIcon( LCUI_Graph *icon )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Set_Window_Title_Icon(parent->getWidget(), icon);
return 0;
}
int LCUIWidget::_Window::addToClientArea( LCUIWidget &object )
{
if( parent->isError() ) {
return WIDGET_IS_NULL;
}
Window_Client_Area_Add(parent->getWidget(), object.getWidget());
return 0;
}
#endif
+2 -2
View File
@@ -16,8 +16,8 @@ LCUI_PictureBox.h \
LCUI_ProgressBar.h \
LCUI_Cursor.h \
LCUI_Error.h \
LCUI_Label.h \
LCUI_Window.h \
LCUI_Label.h LCUI_Label.hpp\
LCUI_Window.h LCUI_Window.hpp\
LCUI_Memory.h \
LCUI_Menu.h \
LCUI_CheckBox.h \
+2 -2
View File
@@ -220,8 +220,8 @@ LCUI_PictureBox.h \
LCUI_ProgressBar.h \
LCUI_Cursor.h \
LCUI_Error.h \
LCUI_Label.h \
LCUI_Window.h \
LCUI_Label.h LCUI_Label.hpp\
LCUI_Window.h LCUI_Window.hpp\
LCUI_Memory.h \
LCUI_Menu.h \
LCUI_CheckBox.h \
+2
View File
@@ -74,7 +74,9 @@
/* 一些部件的头文件路径 */
#define LC_WINDOW_H <LCUI/LCUI_Window.h>
#define LC_WINDOW_HPP <LCUI/LCUI_Window.hpp>
#define LC_LABEL_H <LCUI/LCUI_Label.h>
#define LC_LABEL_HPP <LCUI/LCUI_Label.hpp>
#define LC_BUTTON_H <LCUI/LCUI_Button.h>
#define LC_PICBOX_H <LCUI/LCUI_PictureBox.h>
#define LC_PROGBAR_H <LCUI/LCUI_ProgressBar.h>