Пример #1
0
/*
    测试 struct window
*/
int main()
{
    si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER;
	si_t app_type = APPLICATION_TYPE_NORMAL;
    struct window * w = NULL;

    /* 初始化用户应用程序 */
    application_init(video_access_mode, app_type, "single_window");

    w = window_init("single_window");
    /* 申请失败 */
    if(w == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w, 300, 100, 450, 200);

    /* 添加顶层窗口 */
    application_add_window(NULL, w);
    /* 设置主窗口 */
    application_set_main_window(w);

    /* 运行 */
    application_exec();

    return 0;
}
Пример #2
0
si_t save_as_button_callback(void* btn, void* msg)
{
    union message* m = (union message*)msg;
	struct button* b = NULL;
	switch(m->base.type)
	{
	case MESSAGE_TYPE_MOUSE_SINGLE_CLICK:
		if(NULL == save_window)
		{
			save_window = window_init("save window");
            /* 申请失败 */
            if(NULL == main_window)
            {
				EGUI_PRINT_ERROR("failed to init save window");
				application_exit();
                return -1;
            }
			window_set_bounds(save_window, main_window->area.x + 30, main_window->area.y + 30, 300, 60);
			window_set_color(save_window, NULL, &barely_blue);

			save_text_line = text_line_init(FILE_MAX, 0);
			if(NULL == save_text_line)
			{
				EGUI_PRINT_ERROR("failed to init save_text_line on save window");
				application_exit();
				return -1;
			}
			text_line_set_bounds(save_text_line, 5, 5, 230, 50);
			text_line_set_placeholder(save_text_line, "input file name");
			text_line_set_color(save_text_line, &dark_blue, NULL, &light_green);

			b = button_init("ok");
			if(NULL == b)
			{
				EGUI_PRINT_ERROR("failed to init ok button on save window");
				application_exit();
				return -1;
			}
			button_set_bounds(b, 240, 10, 50, 40);
			button_set_color(b, &dark_blue, &light_green);
			button_set_font(b, FONT_MATRIX_12);
			b->callback = save_window_ok_button_callback;

			object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(b));
			object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(save_text_line));
			application_add_window(NULL, save_window);
			break;
		}
		else
		{
			EGUI_PRINT_ERROR("save window already open!");
		}
	default:
		button_default_callback(btn, msg);
	}
	return 0;
}
Пример #3
0
int main()
{
    si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER;
	si_t app_type = APPLICATION_TYPE_NORMAL;
    struct window * w;
    struct scroll_bar* s;
    struct label* l;
    char show[25];

    /* 初始化用户应用程序 */
    application_init(video_access_mode, app_type, "scroll_bar");

    /* 申请窗口 */
    w = window_init("window with scroll_bar");
    /* 申请失败 */
    if(w == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w, 300, 100, 448, 200);

    s = scroll_bar_init(1, 400, 20);
    /* 申请失败 */
    if(s == NULL)
    {
        application_exit();
        return -1;
    }
	scroll_bar_set_bounds(s, 428, 0, 20, 200);
 
    l = label_init(show);
    /* 申请失败 */
    if(l == NULL)
    {
        application_exit();
        return -1;
    }
	label_set_bounds(l, 10, 40, 400, 20);
    sprintf(show, "not started");

    scroll_bar_register_move_handler(s, WIDGET_POINTER(l), SCROLL_BAR_EVENT_ALL, label_handler);
   
    object_attach_child(OBJECT_POINTER(w), OBJECT_POINTER(s));
    object_attach_child(OBJECT_POINTER(w), OBJECT_POINTER(l));

    /* 添加顶层窗口 */
    application_add_window(NULL, w);
    /* 设置主窗口 */
    application_set_main_window(w);

    /* 运行 */
    application_exec();

    return 0;
}
Пример #4
0
si_t pop_window()
{
    switch(save_or_rename_flag)
    {
        case 0:
            save_window = window_init("save_directory_window");
            break;
        case 1:
            save_window = window_init("save_file_window");
            break;
        case 2:
            save_window = window_init("rename_window");
            break;
        default:
            break;
     }
    if(NULL == save_window)
    {
        //EGUI_PRINT_ERROR("failed to init save window");
		application_exit();
        return -1;
    }
    window_set_bounds(save_window,200, 200, 300, 60);
    window_set_color(save_window, NULL, &ground_purple);
    save_text_line = text_line_init(100, 0);
    if(NULL == save_text_line)
    {
        //EGUI_PRINT_ERROR("failed to init save_text_line on save window");
        application_exit();
        return -1;
    }
    text_line_set_bounds(save_text_line, 5, 5, 230, 50);
    text_line_set_placeholder(save_text_line, "input file name");
    text_line_set_color(save_text_line, &heavy_blue, NULL, &heavy_blue );
    save_button = button_init("OK");
    if(NULL == save_button)
	{
	    //EGUI_PRINT_ERROR("failed to init ok button on save window");
        application_exit();
        return -1;
	}
    button_set_bounds(save_button, 240, 10, 50, 40);
    button_set_color(save_button, &ground_purple, &heavy_blue );
    button_set_font(save_button, FONT_MATRIX_12);
	save_button->callback = rename_window_ok_button_callback;
    object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(save_button));
    object_attach_child(OBJECT_POINTER(save_window), OBJECT_POINTER(save_text_line));
    application_add_window(Desktop_w, save_window);
    return 0;

}
Пример #5
0
/*
    测试 eicon
*/
int main()
{
    si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER;
    ewindow * w;
    eicon * ic;

    /* 初始化用户应用程序 */
    application_init(video_access_mode, "eicon");

    /* 申请窗口 */
    w = window_init(1);
    /* 申请失败 */
    if(w == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w,300,100,500,200);
    w->title = "window with eicon";
    w->minimize_enable = 1;
    w->maximize_enable = 1;
    w->callback = window_default_callback;

    /* 申请按钮 */
    ic = icon_init(2);
    /* 申请失败 */
    if(ic == NULL)
    {
        application_exit();
        return -1;
    }
    icon_set_bounds(ic ,50,50,100,120);
	icon_set_text(ic,"ehello");
	icon_set_img_path(ic,"/home/orange/Egui2.0/img/2.bmp");
	icon_set_is_text_visiable(ic ,1);
    ic->callback = icon_default_callback;

    /* 将按钮添加到窗口 */
    object_attach_child(OBJECT_POINTER(w), OBJECT_POINTER(ic));

	/* 添加顶层窗口 */
    application_add_window(NULL, w);
    /* 设置主窗口 */
    application_set_main_window(w);

    /* 运行 */
    application_exec();

    return 0;
}
Пример #6
0
// This function prepares to draw in a window by setting up its boundary
// restrictions.
// THIS FUNCTION SHOULD ALWAYS BE CALLED WHEN MAKING A WINDOW
// OR MOVING A WINDOW
static inline void window_init_draw(struct window *w) {
    int x = w->x;
    int y = w->y;
    struct window *init = w;
    int width = w->width;
    int height = w->height;
    while (w->parent) {
        w = w->parent;
        x += w->x;
        y += w->y;
        if(w->width - x < width)
            width = w->width - x;
        if(w->height - y < height)
            height = w->height - y;
    }

    // Account for the offset of the top-level window
    height += w->y;
    width += w->x;

    init->x_offset = x;
    init->y_offset = y;
    window_set_bounds(init, x, y, width, height);
}
Пример #7
0
/*
    测试顶层窗口和子窗口

    程序一共申请了四个窗口 w1 w2 w3 w4
    其中 w1 和 w2 是顶层窗口
    w3 和 w4 是 w2 的同一层次子窗口

    w2 总在 w3 和 w4 的后面
    w3 和 w4 的前后关系则可以改变
*/
int main()
{
    si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER;
	si_t app_type = APPLICATION_TYPE_NORMAL;
    struct window * w1;
    struct window * w2;
    struct window * w3;
    struct window * w4;
    struct window * w5;
    struct radiobutton * r, *s;

    /* 初始化用户应用程序 */
    application_init(video_access_mode, app_type, "toplevel_child");

    w1 = window_init("uncle-1");
    /* 申请失败 */
    if(w1 == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w1, 300, 100, 448, 200);

    w2 = window_init("parent");
    /* 申请失败 */
    if(w2 == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w2, 350, 150, 448, 200);

    w3 = window_init("child-1");
    /* 申请失败 */
    if(w3 == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w3, 400, 200, 600, 600);

    w4 = window_init("child-2");
    /* 申请失败 */
    if(w4 == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w4, 450, 250, 448, 200);

    w5 = window_init("uncle-2");
    /* 申请失败 */
    if(w5 == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w5, 500, 300, 448, 200);

    {
        struct button *b = button_init("click me!");
        button_set_bounds(b, 50, 50, 150, 50);
        b->callback = button_callback;
        object_attach_child(OBJECT_POINTER(w4), OBJECT_POINTER(b));
    }

    /*
     * Window structure illustraion:
     *           app
     *          / | \
     *  (main)w1 w5 w2
     *              / \
     *             w3  w4
     */

    /* 添加顶层窗口 */
    application_add_window(NULL, w1);
    /* 添加顶层窗口 */
    application_add_window(NULL, w2);
    /* 添加非顶层窗口 */
    application_add_window(w2, w3);
    /* 添加非顶层窗口 */
    application_add_window(w2, w4);
    /* 添加顶层窗口 */
    application_add_window(NULL, w5);
    /* 设置主窗口 */
    application_set_main_window(w1);

    r = radiobutton_init("test_group", 0);
    s = radiobutton_init("test_group", 1);
    radiobutton_set_bounds(r, 20, 20, 13, 13);
    radiobutton_set_bounds(s, 20, 40, 13, 13);
    object_attach_child(OBJECT_POINTER(w4), OBJECT_POINTER(r));
    object_attach_child(OBJECT_POINTER(w4), OBJECT_POINTER(s));

    {
        struct panel *p = panel_init(0);
        struct button *pb = button_init("button in panel");
        struct checkbox *pcb = checkbox_init(0);
        panel_set_bounds(p, 5, 5, 500, 500);
        button_set_bounds(pb, 5, 5, 200, 50);
        checkbox_set_bounds(pcb, 210, 5, -1, -1);
        object_attach_child(OBJECT_POINTER(w3), OBJECT_POINTER(p));
        object_attach_child(OBJECT_POINTER(p), OBJECT_POINTER(pb));
        object_attach_child(OBJECT_POINTER(p), OBJECT_POINTER(pcb));
    }

    /* 运行 */
    application_exec();

    return 0;
}
Пример #8
0
int main()
{
    si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER;
	si_t app_type = APPLICATION_TYPE_NORMAL;
    struct window * w;
    struct text_line * ta;
    char lyrics[]= "The boy with the thorn in his side\n"
		"Behind the hatred there lies\n"
		"A murderous desire for love\n"
		"\n"
		"How can they look into my eyes\n"
		"And still they don't believe me\n"
		"How can they hear me say those words\n"
		"And still they don't believe me\n"
		"And if they don't believe me now\n"
		"Will they ever believe me?\n"
		"And if they don't believe me now\n"
		"Will they ever believe me?\n"
		"\n"
		"The boy with the thorn in his side\n"
		"Behind the hatred there lies\n"
		"A plundering desire for love\n";

    char* buf;

    /* 初始化用户应用程序 */
    application_init(video_access_mode, app_type, "text_line");

    /* 申请窗口 */
    w = window_init("window with text_line");
    /* 申请失败 */
    if(w == NULL)
    {
        application_exit();
        return -1;
    }
	window_set_bounds(w, 300, 100, 548, 300);

    ta = text_line_init(2 * sizeof(lyrics), 0);
    /* 申请失败 */
    if(ta == NULL)
    {
        application_exit();

        return -1;
    }
	text_line_set_bounds(ta, 5, 5, 538, 290);
    text_line_set_multilines(ta);
    buf = text_line_get_buf(ta);
    strncpy(buf, lyrics, sizeof(lyrics));

    object_attach_child(OBJECT_POINTER(w), OBJECT_POINTER(ta));

    /* 添加顶层窗口 */
    application_add_window(NULL, w);
    /* 设置主窗口 */
    application_set_main_window(w);

    /* 运行 */
    application_exec();

    return 0;
}
Пример #9
0
int main(int argc, char* argv[])
{
    struct scroll_bar* s;
    struct button* b1 = NULL, *b2 = NULL;
    char msg[LABEL_MAX];
	char file_msg[LABEL_MAX];
    si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER;
	si_t app_type = APPLICATION_TYPE_NORMAL;
	char* file_name = NULL;
	si_t fonty = 0;

    /**
     * open with file
     **/
    if(argc == 2)
	{
		struct stat st;
		if(stat(argv[1], &st) == -1)
		{
			EGUI_PRINT_ERROR("file %s does not exists", argv[1]);
			return -1;
		}

		if(!S_ISREG(st.st_mode) || access(argv[1], R_OK | W_OK) != 0)
		{
			EGUI_PRINT_ERROR("file %s cannot access!", argv[1]);
			return -1;
		}

		/**
		 * file too large
		 **/
		if(st.st_size > FILE_MAX)
		{
			EGUI_PRINT_ERROR("file %s does not exists\n", argv[1]);
			return -1;
		}
		file_name = argv[1];
    }
    else if(argc != 1)
    {
		EGUI_PRINT_ERROR("wrong parameter!\nusage: \nediterbasic\nor:\nediterbasic [filename]");
		return -1;
    }


    /* 初始化用户应用程序 */
    application_init(video_access_mode, app_type, "editerbasic");

    /**
     * window
     **/
    main_window = window_init("editer_basic");
    /* 申请失败 */
    if(main_window == NULL)
    {
        application_exit();
        return -1;
    }
    window_set_bounds(main_window, 300, 100, 550, 300);
	window_set_color(main_window, NULL, &light_green);

    /**
     * label that show process
     **/
	if(file_name)
	{
		sprintf(file_msg, "%s", file_name);
	}
	else
	{
		sprintf(file_msg, "new file");
	}
	file_label = label_init(file_msg);
    if(file_label == NULL)
    {
        application_exit();
        return -1;
    }
	label_set_bounds(file_label, 10, 10, 365, 20);
	label_set_color(file_label, &barely_blue, &light_blue);
	label_set_font(file_label, FONT_MATRIX_12);
 
    /**
     * save button
     **/
    b1 = button_init("save");
    if(b1 == NULL)
    {
        application_exit();
        return -1;
    }
	button_set_bounds(b1, 380, 5, 60, 30);
	button_set_color(b1, &dark_blue, &barely_blue);
	button_set_font(b1, FONT_MATRIX_12);
	b1->callback = save_button_callback;

	b2 = button_init("save as");
	if(b2 == NULL)
	{
		application_exit();
		return -1;
	}
	button_set_bounds(b2, 445, 5, 100, 30);
	button_set_color(b2, &dark_blue, &barely_blue);
	button_set_font(b2, FONT_MATRIX_12);
	b2->callback = save_as_button_callback;

    /**
     * text_line that shows file context
     **/
	file_context_text_line = text_line_init(FILE_MAX, 0);
    if(file_context_text_line == NULL)
    {
        application_exit();
        return -1;
    }
	text_line_set_bounds(file_context_text_line, 5, 40, 520, 230);
	text_line_set_color(file_context_text_line, &dark_blue, NULL, NULL);
	text_line_set_multilines(file_context_text_line);
	fonty = get_font_height(file_context_text_line->gd);

	if(file_name)
	{
		if(load_file(file_name, text_line_get_buf(file_context_text_line)) < 0)
		{
			EGUI_PRINT_ERROR("failed to load file %s", file_name);
			application_exit();
			return -1;
		}
		s = scroll_bar_init(1, fonty * text_line_get_max_line_shown(file_context_text_line), fonty);
	}
	else
	{
		s = scroll_bar_init(1, file_context_text_line->area.height, fonty);
	}
    if(s == NULL)
    {
        application_exit();
        return -1;
    }
	scroll_bar_set_bounds(s, 525, 40, 20, 230);

	text_line_register_move_handler(file_context_text_line, WIDGET_POINTER(s), TEXT_LINE_EVENT_ALL, scrollbar_subscribe_text_line);
	scroll_bar_register_move_handler(s, WIDGET_POINTER(file_context_text_line), SCROLL_BAR_EVENT_ALL, text_line_subscribe_scrollbar);

	log_label = label_init(msg);
    if(log_label == NULL)
    {
        application_exit();
        return -1;
    }
	label_set_bounds(log_label, 5, 275, 450, 20);
	label_set_color(log_label, NULL, &light_green);
	sprintf(msg, "open file successfully!");
 
    object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(file_label));
    object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(file_context_text_line));
    object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(log_label));
    object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(b1));
    object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(b2));
    object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(s));

    /* 添加顶层窗口 */
    application_add_window(NULL, main_window);
    /* 设置主窗口 */
    application_set_main_window(main_window);

    /* 运行 */
    application_exec();

    return 0;
}