Esempio n. 1
0
static void _rtgui_filelist_view_destructor(struct rtgui_filelist_view *view)
{
    /* delete all file items */
    rtgui_filelist_view_clear(view);
    /* delete current directory and pattern */
    if (view->current_directory != RT_NULL)
    {
        rt_free(view->current_directory);
        view->current_directory = RT_NULL;
    }
    if (view->pattern != RT_NULL)
    {
        rt_free(view->pattern);
        view->pattern = RT_NULL;
    }

    _instance_count--;
    RT_ASSERT(_instance_count >= 0);
    if (_instance_count == 0)
    {
        /* delete image */
        rtgui_image_destroy(file_image);
        file_image = RT_NULL;
        rtgui_image_destroy(folder_image);
        folder_image = RT_NULL;
    }
}
Esempio n. 2
0
static void _rtgui_button_destructor(rtgui_button_t *button)
{
	if (button->pressed_image != RT_NULL)
	{
		rtgui_image_destroy(button->pressed_image);
		button->pressed_image = RT_NULL;
	}

	if (button->unpressed_image != RT_NULL)
	{
		rtgui_image_destroy(button->unpressed_image);
		button->unpressed_image = RT_NULL;
	}
}
Esempio n. 3
0
void demo_bitmap_open(struct rtgui_object* object, struct rtgui_event* event)
{
	char *str;
	rtgui_button_t *button = RTGUI_BUTTON(object);
	/* 从textbox控件中取得文件名 */
	str = (char*)rtgui_textbox_get_value(bmpdt.box);
	if(str == RT_NULL) return;
	if(*str == '/' && (rt_strstr(str, ".bmp")!=RT_NULL || rt_strstr(str, ".BMP")!=RT_NULL))
	{	/* 如果是bmp文件, 且文件名有效, 则读入图像数据 */
		if(bmpdt.filename != RT_NULL) 
			rt_free(bmpdt.filename);
		bmpdt.filename = rt_strdup(str);

		if(bmpdt.image != RT_NULL)
			rtgui_image_destroy(bmpdt.image);

		bmpdt.image = rtgui_image_create_from_file("bmp", bmpdt.filename, RT_TRUE);
		
		if(bmpdt.image != RT_NULL)
		{
			bmpdt.showimg = bmpdt.image;
			bmpdt.scale = 1.0;
			bmpdt.angle = 0.0;
			rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
		}
	}
	else
		rt_kprintf("Bad filename!");
}
Esempio n. 4
0
static void app_mainmenu_init(void)
{
    struct rtgui_image *bg_image;
    rtgui_rect_t rect;

    /* create main window of Application Manager */
    win = rtgui_mainwin_create(RT_NULL, "mainmenu", RTGUI_WIN_STYLE_MAINWIN);
    if (win != RT_NULL)
    {
        rtgui_object_set_event_handler(RTGUI_OBJECT(win), mainmenu_event_handler);
        rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect);

#ifdef RT_USING_MODULE 
        mainmenu_scan_apps();
#endif
        /* create background image */
        bg_image = rtgui_image_create("/resource/bg_image.jpg", RT_TRUE);
        if (bg_image == RT_NULL)
        {
            rt_kprintf("open \"/resource/bg_image.jpg\" failed\n");
        }
        ycircle_image = rtgui_image_create("/resource/ycircle.png", RT_TRUE);
        gcircle_image = rtgui_image_create("/resource/gcircle.png", RT_TRUE);
        app_list = app_list_create(&rect, items, ITEM_MAX, 2, 5, bg_image);
        rtgui_image_destroy(bg_image);
        app_list_draw(app_list);
        app_list_draw_pagemark(app_list);
        app_list->on_select = exec_internal_app;
        rtgui_win_show(win, RT_FALSE);
        /* set as main window */
        rtgui_app_set_main_win(rtgui_app_self(), win);
    }
}
Esempio n. 5
0
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;
		rtgui_image_t *image;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		rtgui_dc_fill_rect(dc, &rect);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1);

		/* draw RT-Thread logo */
		image = rtgui_image_create_from_file("hdc",
			"/resource/RTT.hdc", RT_FALSE);
		if (image != RT_NULL)
		{
			rtgui_image_blit(image, dc, &rect);
			rtgui_image_destroy(image);
			
			image = RT_NULL;
		}

        if (network_image != RT_NULL)
        {
            rect.x1 = rect.x2 - (network_image->w + 2);
            rtgui_image_blit(network_image, dc, &rect);
        }

		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_rect rect;
		struct rtgui_event_mouse* emouse; 

		emouse = (struct rtgui_event_mouse*) event;
		rtgui_widget_get_rect(widget, &rect);

		rect.y2 = rect.y1 + 100;
		if (emouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP) &&
			(rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK))
		{
			/* enter function view */
			player_notfiy_functionview();
		}
	}

	return rtgui_view_event_handler(widget, event);
}
/* 打开按钮的回调函数 */
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	rtgui_filelist_view_t *view;
	rtgui_workbench_t *workbench;
	rtgui_rect_t rect;

	/* 获得顶层的workbench */
	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

	/* WIN32平台上和真实设备上的初始路径处理 */
#ifdef _WIN32
	view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
#else
	view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
#endif
	/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
	if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
	{
		char path[32], image_type[8];

		/* 设置文件路径的标签 */
		rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
		if (image != RT_NULL) 
		{
			rtgui_image_destroy(image);
			image = RT_NULL;
		}

		rt_memset(image_type, 0, sizeof(image_type));

		/* 获得图像的类型 */
		if (rt_strstr(path, ".bmp") != RT_NULL ||
			rt_strstr(path, ".BMP") != RT_NULL)
			strcat(image_type, "bmp");
		if (rt_strstr(path, ".png") != RT_NULL ||
			rt_strstr(path, ".PNG") != RT_NULL)
			strcat(image_type, "png");
		if (rt_strstr(path, ".jpg") != RT_NULL ||
			rt_strstr(path, ".JPG") != RT_NULL)
			strcat(image_type, "jpeg");
		if (rt_strstr(path, ".hdc") != RT_NULL ||
			rt_strstr(path, ".HDC") != RT_NULL)
			strcat(image_type, "hdc");

		/* 如果图像文件有效,创建相应的rtgui_image对象 */
		if (image_type[0] != '\0')
			image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
	}

	/* 删除 文件列表 视图 */
	rtgui_view_destroy(RTGUI_VIEW(view));
	rtgui_view_show(_view, RT_FALSE);
}
Esempio n. 7
0
static void _rtgui_filelist_view_destructor(struct rtgui_filelist_view *view)
{
    /* delete all file items */
    rtgui_filelist_view_clear(view);
	/* delete current directory and pattern */
	if (view->current_directory != RT_NULL)
	{
		rt_free(view->current_directory); 
		view->current_directory = RT_NULL;
	}
	if (view->pattern != RT_NULL) 
	{
		rt_free(view->pattern); 
		view->pattern = RT_NULL;
	}

	/* delete image */
	rtgui_image_destroy(file_image);
	rtgui_image_destroy(folder_image);
}
Esempio n. 8
0
void mainmenu_register_internal_app(char *name, char *text, rtgui_image_t *image,
                                    void (*app_starter)(void *), void *p)
{
    int i;

    for (i = 0; i < ITEM_MAX; i++)
    {
        if (!items[i].text)
            break;
        if (!items[i].name)
            continue;
        if (strcmp(items[i].name, name) == 0)
            return;
    }
    if (i == ITEM_MAX)
    {
        rt_kprintf("app list is full\n");
        return;
    }

    items[i].name = rt_strdup(name);
    if (!items[i].name)
        return;

    items[i].text = rt_strdup(name);
    if (!items[i].text)
        goto _err;

    items[i].icon = image;

    items[i].app_starter = app_starter;
    items[i].parameter = p;
    items[i].is_external = 1;

    return;

_err:
    items[i].app_starter = RT_NULL;
    if (items[i].name)
    {
        rt_free(items[i].name);
        items[i].name = RT_NULL;
    }
    if (items[i].text)
    {
        rt_free(items[i].text);
        items[i].text = RT_NULL;
    }
    if (items[i].icon)
    {
        rtgui_image_destroy(items[i].icon);
        items[i].icon = RT_NULL;
    }
}
static void _rtgui_iconbox_destructor(rtgui_iconbox_t *iconbox)
{
	if (iconbox->image != RT_NULL)
	{
		rtgui_image_destroy(iconbox->image);
		iconbox->image = RT_NULL;
	}

	rt_free(iconbox->text);
	iconbox->text = RT_NULL;
}
Esempio n. 10
0
static rt_bool_t picture_view_event_handler(rtgui_object_t *object, rtgui_event_t *event)
{
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        struct rtgui_image* image = RT_NULL;
        char fn[32];

        dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
        if (dc == RT_NULL) return RT_FALSE;
        rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);

        /* open image */
        rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn);
        rt_kprintf("pic fn: %s\n", fn);
        if (strstr(fn, ".hdc") != RT_NULL ||
            strstr(fn, ".HDC") != RT_NULL)
        {
            image = rtgui_image_create_from_file("hdc",
                fn, RT_FALSE);
        }
        else if (strstr(fn, ".bmp") != RT_NULL ||
            strstr(fn, ".BMP") != RT_NULL)
        {
            image = rtgui_image_create_from_file("bmp",
                fn, RT_FALSE);
        }

        if (image != RT_NULL)
        {
            /* blit image */
            rtgui_image_blit(image, dc, &rect);
            /* destroy image */
            rtgui_image_destroy(image);
        }
        else
        {
            rtgui_dc_fill_rect(dc, &rect);
            rtgui_dc_draw_text(dc, "没有文件被打开", &rect);
        }
        rtgui_dc_end_drawing(dc);

        return RT_FALSE;
    }

    return rtgui_container_event_handler(object, event);
}
Esempio n. 11
0
void mainmenu_unregister_app(char *name)
{
    int i;

    for (i = 0; i < ITEM_MAX; i++)
    {
        if (!items[i].is_external)
            continue;
        if (strcmp(items[i].name, name) == 0)
        {
            rt_free(items[i].name);
            items[i].name = RT_NULL;
            rt_free(items[i].text);
            items[i].text = RT_NULL;
            rtgui_image_destroy(items[i].icon);
            items[i].icon = RT_NULL;
            items[i].app_starter = RT_NULL;
            rtgui_free(items[i].parameter);
        }
    }
}
Esempio n. 12
0
void mainmenu_register_app(char *name)
{
    int i;
    char *path_buf;

    for (i = 0; i < ITEM_MAX; i++)
    {
        if (!items[i].text)
            break;
        if (!items[i].is_external)
            continue;
        if (!items[i].name)
            continue;
        if (strcmp(items[i].name, name) == 0)
            return;
    }
    if (i == ITEM_MAX)
    {
        rt_kprintf("app list is full\n");
        return;
    }

    items[i].name = rt_strdup(name);
    if (!items[i].name)
        return;

    path_buf = rtgui_malloc(DFS_PATH_MAX);
    if (!path_buf)
    {
        goto _err;
    }

    items[i].text = rt_strdup(name);
    if (!items[i].text)
        goto _err;

    rt_snprintf(path_buf, DFS_PATH_MAX, "/programs/%s/%s.png", name, name);
    path_buf[DFS_PATH_MAX - 1] = '\0';
    items[i].icon = rtgui_image_create(path_buf, RT_FALSE);
    if (!items[i].icon)
        goto _err;

    items[i].app_starter = launch_ext_mo;
    rt_snprintf(path_buf, DFS_PATH_MAX, "/programs/%s/%s.mo", name, name);
    items[i].parameter = path_buf;
    items[i].is_external = 1;

    rt_kprintf("mo %s registered\n", name);
    return;

_err:
    items[i].app_starter = RT_NULL;
    if (items[i].name)
    {
        rt_free(items[i].name);
        items[i].name = RT_NULL;
    }
    if (items[i].text)
    {
        rt_free(items[i].text);
        items[i].text = RT_NULL;
    }
    if (items[i].icon)
    {
        rtgui_image_destroy(items[i].icon);
        items[i].icon = RT_NULL;
    }
    if (path_buf)
        rtgui_free(path_buf);
}
Esempio n. 13
0
static rt_bool_t picture_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;
		struct rtgui_image* image;
		char fn[32];

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		/* open image */
		rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn);
		image = rtgui_image_create_from_file("hdc",
			fn, RT_FALSE);
		if (image != RT_NULL)
		{
			/* blit image */
			rtgui_image_blit(image, dc, &rect);
			/* destroy image */
			rtgui_image_destroy(image);
		}
		else
		{
			rtgui_dc_fill_rect(dc, &rect);
			rtgui_dc_draw_text(dc, "没有文件被打开", &rect);
		}
		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
	else if (event->type == RTGUI_EVENT_KBD)
	{
		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
		if (ekbd->type == RTGUI_KEYDOWN)
		{
			switch (ekbd->key)
			{
			case RTGUIK_RIGHT:
				if (view_mode == VIEW_DIR_MODE) picture_show_next();
				else if (view_mode == VIEW_FN_LIST_MODE)
				{
					picture_fn_list_current ++;
					if (picture_fn_list_current == picture_fn_list_size)
					{
						picture_fn_list_current = 0;
					}
					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
					rtgui_widget_update(RTGUI_WIDGET(picture_view));
				}
				break;
			case RTGUIK_LEFT:
				if (view_mode == VIEW_DIR_MODE) picture_show_prev();
				else if (view_mode == VIEW_FN_LIST_MODE)
				{
					if (picture_fn_list_current == 0)
					{
						picture_fn_list_current = picture_fn_list_size - 1;
					}
					else picture_fn_list_current --;

					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
					rtgui_widget_update(RTGUI_WIDGET(picture_view));
				}
				break;
			case RTGUIK_RETURN:
			{
				rtgui_view_t* view;

				view = RTGUI_VIEW(widget);

				/* close this view */
				current_fn[0] = '\0';

				/* end of modal */
			    rtgui_view_end_modal(view, RTGUI_MODAL_OK);
			    picture_view = RT_NULL;
			}
				break;
			}
		}
		return RT_FALSE;
	}

	return rtgui_view_event_handler(widget, event);
}
Esempio n. 14
0
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        rtgui_image_t *background;

		/* draw child */
		rtgui_view_event_handler(widget, event);

        dc = rtgui_dc_begin_drawing(widget);
        if (dc == RT_NULL) return RT_FALSE;
        rtgui_widget_get_rect(widget, &rect);

        /* draw background */
        background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
        if (background != RT_NULL)
        {
            rtgui_image_blit(background, dc, &rect);
            rtgui_image_destroy(background);
        }
        else
        {
            rtgui_dc_fill_rect(dc, &rect);
        }

        /* draw playing information */
		player_update_tag_info();

        rtgui_dc_end_drawing(dc);

        return RT_FALSE;
    }
    else if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
        	if ((ekbd->key == RTGUIK_LEFT) || (ekbd->key == RTGUIK_RIGHT))
        	{
        		if (player_mode == PLAYER_STOP)
        		{
                    rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
        		}
        		else
        		{
        			rt_device_t dev = rt_device_find("snd");
        			if (ekbd->key == RTGUIK_LEFT && radio_setup.default_volume > 0)
        			{
        				radio_setup.default_volume--;
        				rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume);
        			}
        			else if (ekbd->key == RTGUIK_RIGHT && radio_setup.default_volume < CODEC_VOLUME_MAX)
        			{
        				radio_setup.default_volume++;
        				rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume);
        			}
        		}
        	}
			else
			{
				return RTGUI_WIDGET(music_listbox)->event_handler(RTGUI_WIDGET(music_listbox), event);
			}
        }
        return RT_FALSE;
    }
	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_event_mouse* emouse;

		emouse = (struct rtgui_event_mouse*)event;
		if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
		{
			if (rtgui_rect_contains_point(&next_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(NEXT_BUTTON);
			else if (rtgui_rect_contains_point(&prev_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(PREV_BUTTON);
			else if (rtgui_rect_contains_point(&playing_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(PLAYING_BUTTON);
		}
	}
    else if (event->type == RTGUI_EVENT_COMMAND)
    {
        struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

        switch (ecmd->command_id)
        {
        case PLAYER_REQUEST_PLAY_SINGLE_FILE:
        case PLAYER_REQUEST_PLAY_LIST:
            rtgui_timer_start(info_timer);
			return RT_TRUE;

        case PLAYER_REQUEST_STOP:
        {
			struct play_item *item = RT_NULL;

			/* if it's radio mode, set next mode to stop */
			if (player_mode == PLAYER_PLAY_RADIO)
				next_step = PLAYER_STEP_STOP;

			/* set player mode */
			player_mode = PLAYER_STOP;

			switch (next_step)
			{
			case PLAYER_STEP_NEXT:
				/* play next */
				item = play_list_next(play_list_get_mode());
				break;
			case PLAYER_STEP_PREV:
				/* play prev */
				item = play_list_prev(play_list_get_mode());
				break;
			case PLAYER_STEP_SEEK:
				/* play current item */
				item = play_list_current();
			}

			if (item != RT_NULL)
				player_play_item(item);
			else
			{
				player_mode = PLAYER_STOP;
				rtgui_timer_stop(info_timer);
			}

			/* update tag information */
			player_update_tag_info();
        }
		return RT_TRUE;

        case PLAYER_REQUEST_FREEZE:
        {
            /* stop play */
            if (player_is_playing() == RT_TRUE)
            {
                player_stop();
            }

            /* delay some tick */
            rt_thread_delay(50);

            /* show a modal view */
            {
                rtgui_view_t *view;
                rtgui_label_t *label;
                rtgui_rect_t rect = {0, 0, 150, 150}, container_rect;

                rtgui_graphic_driver_get_default_rect(&container_rect);
                /* set centre */
                rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
                view = rtgui_view_create("USB");
                rtgui_workbench_add_view(workbench, view);

                /* set container to window rect */
                container_rect = rect;

                rect.x1 = 0;
                rect.y1 = 0;
                rect.x2 = 120;
                rect.y2 = 20;
                label = rtgui_label_create("USB 联机中...");
                rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
                rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
                rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));

                rtgui_view_show(view, RT_TRUE);
                /* never reach hear */
            }
        }

		case PLAYER_REQUEST_UPDATE_INFO:
			/* update status information */
			player_update_tag_info();
			return RT_TRUE;

        default:
            break;
        }

        return RT_FALSE;
    }

    return rtgui_view_event_handler(widget, event);
}