|
发表于 2010-9-2 22:47:12
|
显示全部楼层
回复【楼主位】neilxiang
-----------------------------------------------------------------------
我用window实现简单的移动功能,楼主可以试用这种方式.
#include "demo_view.h"
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/checkbox.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/textbox.h>
static rtgui_win_t *win1;
void move_all_widget(int heigth,rt_bool_t isUp)
{
rtgui_rect_t current_rect;
rtgui_list_t *node;
rtgui_list_foreach(node, &(RTGUI_CONTAINER(win1)->children))
{
rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
current_rect.x1 =widget->extent.x1;
current_rect.x2 =widget->extent.x2;
if ( isUp == RT_TRUE )
{
current_rect.y1 =widget->extent.y1 - heigth;
current_rect.y2 =widget->extent.y2 - heigth;
}
else
{
current_rect.y1 =widget->extent.y1 + heigth;
current_rect.y2 =widget->extent.y2 + heigth;
}
rtgui_widget_set_rect(widget, ¤t_rect);
}
}
static void move_up(struct rtgui_widget* widget, rtgui_event_t* event)
{
move_all_widget(25,RT_TRUE);
rtgui_widget_update(RTGUI_WIDGET(win1));
}
static void move_down(struct rtgui_widget* widget, rtgui_event_t* event)
{
move_all_widget(25,RT_FALSE);
rtgui_widget_update(RTGUI_WIDGET(win1));
}
/*创建非模态window*/
void create_new_window1(rtgui_widget_t *widget)
{
int i;
char* arrayName[10];
rtgui_checkbox_t* checkbox;
rtgui_toplevel_t *parent;
rtgui_rect_t rect_label,rect_size = {0, 0, 240, 120};
arrayName[0]="test 1";
arrayName[1]="test 2";
arrayName[2]="test 3";
arrayName[3]="test 4";
arrayName[4]="test 5";
arrayName[5]="test 6";
arrayName[6]="test 7";
arrayName[7]="test 8";
arrayName[8]="test 9";
arrayName[9]="test 10";
parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
/* 创建一个窗口,风格为无标题及无边框 */
win1 = rtgui_win_create(parent,
"Table", &rect_size, RTGUI_WIN_STYLE_NO_TITLE);
rtgui_rect_moveto(&rect_size, 0, 45);
rtgui_win_set_rect(win1,&rect_size);
rect_label.x1=5;
rect_label.x2=100;
rect_label.y1=rect_size.y1;
rect_label.y2=rect_label.y1+20;
for (i=0; i < 10; i++ )
{
checkbox = rtgui_checkbox_create(arrayName,RT_FALSE);
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect_label);
rtgui_container_add_child(RTGUI_CONTAINER(win1), RTGUI_WIDGET(checkbox));
rect_label.y1=rect_label.y2+ 5;
rect_label.y2=rect_label.y1+20;
}
/* 非模态显示窗口 */
rtgui_win_show(win1, RT_FALSE);
}
rtgui_view_t *test_move(rtgui_workbench_t* workbench)
{
rtgui_view_t *view1;
rtgui_button_t *button;
rtgui_textbox_t* text;
rtgui_rect_t widget_rect;
view1 = demo_view(workbench, "test");
demo_view_get_rect(view1, &widget_rect);
widget_rect.x1 = 5;
widget_rect.x2 = widget_rect.x1 + 50;
widget_rect.y1 = 170;
widget_rect.y2 = widget_rect.y1 + 20;
button = rtgui_button_create("窗口");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, create_new_window1);
widget_rect.x1 = widget_rect.x2 + 10;
widget_rect.x2 += 50;
button = rtgui_button_create("上移");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, move_up);
widget_rect.x1 = widget_rect.x2 + 10;
widget_rect.x2 += 50;
button = rtgui_button_create("下移");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, move_down);
return view1;
} |
|