Marc Andre Tanner wrote:
 http://repo.or.cz/w/qi-bootmenu.git/blob/HEAD:/gui.c

Dave, you should be able to add your gui by patching this file.
Hi Marc,

This attached patch:
- uses the default evas engine (rather than guessing x11/fb)
- introduces a grid layout
- adds new command line options (-l or -g) for choosing between list or grid. - replaces the power-off logo with something different to the default logo. (git diff excludes the binary file, so i've attached it here.)

Your (list) layout remains the default.

Cheers,
Dave


diff --git a/config.h b/config.h
index 8f7de15..5ba4a6d 100644
--- a/config.h
+++ b/config.h
@@ -12,5 +12,7 @@
 #define FONT_SIZE 20 
 #define DEFAULT_LOGO "/usr/share/qi-bootmenu/defaultlogo.png"
 #define POWEROFF_LOGO "/usr/share/qi-bootmenu/poweroff.png"
-#define LOGO_WIDTH 100 
-#define LOGO_HEIGHT 80
+#define LIST_LOGO_WIDTH 100
+#define LIST_LOGO_HEIGHT 80
+#define GRID_LOGO_WIDTH 200
+#define GRID_LOGO_HEIGHT 180
diff --git a/data/poweroff.png b/data/poweroff.png
index b8d5ab7..cbdcbb7 100644
Binary files a/data/poweroff.png and b/data/poweroff.png differ
diff --git a/gui.c b/gui.c
index f3e93aa..dc2c475 100644
--- a/gui.c
+++ b/gui.c
@@ -11,10 +11,15 @@
 #define SCREEN_WIDTH 480
 #define SCREEN_HEIGHT 640
 
+#define LAYOUT_LIST 0
+#define LAYOUT_GRID 1
+
 /* drawing related stuff */
 static Ecore_Evas *ee;
 static Evas *evas;
 
+int layout = LAYOUT_LIST;
+
 void poweroff(void *data, Evas *evas, Evas_Object *obj, void *event);
 static void draw_item_border(Evas_Object *item);
 
@@ -44,10 +49,7 @@ static bool canvas_init(){
 		return false;
 
 	/* XXX: fixed dimensions */
-	if (getenv("DISPLAY"))
-		ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
-	else
-		ee = ecore_evas_fb_new(NULL, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+	ee = ecore_evas_new(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL);
 
 	if (!ee)
 		return false;
@@ -57,20 +59,37 @@ static bool canvas_init(){
 	ecore_evas_show(ee);
 
 	evas = ecore_evas_get(ee);
+	if (!evas)
+		return false;
+
 	evas_font_path_append(evas, FONT_PATH);
 
+	if( LAYOUT_GRID == layout ) {
+		/* Divide the screen into 6ths */
+		Evas_Object *eline;
+		eline = evas_object_line_add(evas);
+		evas_object_line_xy_set(eline, SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2, SCREEN_HEIGHT);
+		evas_object_show(eline);
+		eline = evas_object_line_add(evas);
+		evas_object_line_xy_set(eline, 0, SCREEN_HEIGHT/3, SCREEN_WIDTH, SCREEN_HEIGHT/3);
+		evas_object_show(eline);
+		eline = evas_object_line_add(evas);
+		evas_object_line_xy_set(eline, 0, 2*(SCREEN_HEIGHT/3), SCREEN_WIDTH, 2*(SCREEN_HEIGHT/3) );
+		evas_object_show(eline);
+	}
+
 	return true;
 }
 
-static void draw_item(const char *text, const char *logo, void(*callback)(void*, Evas*, Evas_Object*, void *),
+static void draw_list_item(const char *text, const char *logo, void(*callback)(void*, Evas*, Evas_Object*, void *),
                       void *data, int x, int y) {
 
 	Evas_Object *ebox, *elogo, *etext;
 
 	elogo = evas_object_image_add(evas);
 	evas_object_image_file_set(elogo, logo, NULL);
-	evas_object_image_fill_set(elogo, 0, 0, LOGO_WIDTH, LOGO_HEIGHT);
-	evas_object_resize(elogo, LOGO_WIDTH, LOGO_HEIGHT);
+	evas_object_image_fill_set(elogo, 0, 0, LIST_LOGO_WIDTH, LIST_LOGO_HEIGHT);
+	evas_object_resize(elogo, LIST_LOGO_WIDTH, LIST_LOGO_HEIGHT);
 	evas_object_show(elogo);
 
 	etext = evas_object_text_add(evas);
@@ -82,7 +101,7 @@ static void draw_item(const char *text, const char *logo, void(*callback)(void*,
 	evas_object_box_align_set(ebox, 0, 0.5);
 	evas_object_box_padding_set(ebox, 10, 10);
 	evas_object_move(ebox, x, y);
-	evas_object_resize(ebox, SCREEN_WIDTH, LOGO_HEIGHT);
+	evas_object_resize(ebox, SCREEN_WIDTH, LIST_LOGO_HEIGHT);
 	evas_object_box_append(ebox, elogo);
 	evas_object_box_append(ebox, etext);
 	evas_object_event_callback_add(ebox, EVAS_CALLBACK_MOUSE_UP, callback, data);
@@ -90,6 +109,23 @@ static void draw_item(const char *text, const char *logo, void(*callback)(void*,
 	evas_object_show(ebox);
 }
 
+static void draw_grid_item(const char *logo, void(*callback)(void*, Evas*, Evas_Object*, void *),
+						void *data, int x, int y) {
+
+	printf("%s @ %d, %d \n", logo, x, y);
+
+	Evas_Object *o_logo = NULL;
+	o_logo = evas_object_image_add(evas);
+	evas_object_image_file_set(o_logo, logo, NULL);
+	evas_object_image_fill_set(o_logo, 0, 0, GRID_LOGO_WIDTH, GRID_LOGO_HEIGHT);
+	evas_object_move(o_logo, x, y);
+	evas_object_resize(o_logo, GRID_LOGO_WIDTH, GRID_LOGO_HEIGHT);
+	evas_object_show(o_logo);
+
+	evas_object_event_callback_add(o_logo, EVAS_CALLBACK_MOUSE_UP, callback, data);
+}
+
+
 static void draw_item_border(Evas_Object *item) {
 	Evas_Object *eline; 
 	Evas_Coord x, y, w, h;
@@ -110,26 +146,52 @@ static void draw_item_border(Evas_Object *item) {
 
 int gui(int argc, char **argv) {
 
+	if (argc > 1 && argv[1][0] == '-') {
+		switch (argv[1][1]) {
+		case 'l':
+			layout = LAYOUT_LIST;
+			break;
+		case 'g':
+			puts("grid layout");
+			layout = LAYOUT_GRID;
+			break;
+		}
+	}
+
 	if (!canvas_init()) {
 		eprint("Couldn't init GUI\n");
 		return 1;
 	}
 
-	/* search for system images to boot and display them in a list */
+	/* search for system images to boot and display them */
 	Eina_List *l, *systems = scan_system();
-	int i, y = 0;
+	int i = 0, x = 0, y = 0;
 	BootItem *s;
 
-	EINA_LIST_FOREACH(systems, l, s) {
-		draw_item(s->dev, s->logo, bootitem_clicked, s,  0, y);
-		y += LOGO_HEIGHT;
+	if( LAYOUT_GRID == layout){
+		EINA_LIST_FOREACH(systems, l, s) {
+			int x = ( i%2 == 0) ? 20 : 260;
+			int y = 16 + ((SCREEN_HEIGHT/3) * (i/2));
+			draw_grid_item(s->logo, bootitem_clicked, s, x, y);
+			i++;
+		}
+		for (i = 0; i < countof(menu); i++) {
+			int x = ( (5-i)%2 == 0) ? 20 : 260;
+			int y = 16 + ((SCREEN_HEIGHT/3) * ((5-i)/2));
+			draw_grid_item(menu[i].logo, menu[i].callback, NULL,  x, y);
+		}
+	}else{
+		EINA_LIST_FOREACH(systems, l, s) {
+			draw_list_item(s->dev, s->logo, bootitem_clicked, s, 0, y);
+			y += LIST_LOGO_HEIGHT;
+		}
+		/* add pre defined menu entries */
+		for (i = 0; i < countof(menu); i++) {
+			draw_list_item(menu[i].text, menu[i].logo, menu[i].callback, NULL,  0, y);
+			y += LIST_LOGO_HEIGHT;
+		}
 	}
 
-	/* add pre defined menu entries */
-	for (i = 0; i < countof(menu); i++) {
-		draw_item(menu[i].text, menu[i].logo, menu[i].callback, NULL,  0, y);
-		y += LOGO_HEIGHT;
-	}
 
 	ecore_main_loop_begin();
 

<<inline: poweroff.png>>

_______________________________________________
devel mailing list
[email protected]
https://lists.openmoko.org/mailman/listinfo/devel

Reply via email to