From 556eca046775a1e612006bff8ed5ca36c6216c93 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 31 Dec 2015 15:53:54 +1000 Subject: Fix menus, with an evil hack. ELM managed to break the main menu, it never showed, no matter what I did, but the woMan menus worked fine. Refactored both so they use generic functions for building the menu. Put the main menu in it's own window, which mostly works fine. I gotta rip the elm menu system a new one, or just drop it entirely and build my own. --- src/extantz/extantz.c | 152 +++++++++++++++++++----------------------------- src/extantz/woMan.c | 23 ++------ src/libraries/winFang.c | 57 ++++++++++++++++++ src/libraries/winFang.h | 4 ++ 4 files changed, 126 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 355a195..5a7d030 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -454,90 +454,61 @@ static void init_evas_gl(globals *ourGlobals) //-------------------------// -static void _on_menu_focus(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) -{ - evas_object_raise(obj); -} -static Evas_Object *_menuAdd(Evas_Object *win, Evas_Object *tb, char *label) +static winFang *_makeMainMenu(globals *ourGlobals) { - Evas_Object *menu= NULL; - Elm_Object_Item *tb_it; - - // Evas_Object * obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data - // The function is called when the item is clicked. - tb_it = elm_toolbar_item_append(tb, NULL, label, NULL, NULL); - // Mark it as a menu. - elm_toolbar_item_menu_set(tb_it, EINA_TRUE); - // This alledgedly marks it as a menu (not true), and gets an Evas_Object for us to play with. - menu = elm_toolbar_item_menu_get(tb_it); - // Alas this does not work. B-( - evas_object_smart_callback_add(menu, "focused", _on_menu_focus, NULL); - - // Priority is for when toolbar items are set to hide or menu when there are too many of them. They get hidden or put on the menu based on priority. - elm_toolbar_item_priority_set(tb_it, 9999); - - // The docs for this functien are meaningless, but it wont work right if you leave it out. - elm_toolbar_menu_parent_set(tb, win); - - // Add a seperator after, so that there's some visual distinction between menu items. - // Coz using all lower case and with no underline on the first letter, it's hard to tell. - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_toolbar_item_separator_set(tb_it, EINA_TRUE); - - return menu; -} + GLData *gld = &ourGlobals->gld; + winFang *me; + Evas_Object *menu, *tb; + Elm_Object_Item *it; -static void makeMainMenu(globals *ourGlobals) -{ - GLData *gld = &ourGlobals->gld; - Evas_Object *menu, *tb; - Elm_Object_Item *tb_it; - - // A toolbar thingy. - tb = eo_add(ELM_TOOLBAR_CLASS, ourGlobals->win, - evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0.0), - evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), - elm_obj_toolbar_shrink_mode_set(ELM_TOOLBAR_SHRINK_MENU), - efl_gfx_position_set(0, 0), - elm_obj_toolbar_align_set(0.0) - ); - ourGlobals->tb = tb; - - // Menus. - menu = _menuAdd(ourGlobals->win, tb, "file"); - // Evas_Object *obj, Elm_Object_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data - elm_menu_item_add(menu, NULL, NULL, "open", _on_open, ourGlobals); - elm_menu_item_add(menu, NULL, NULL, "quit", _on_done, gld); - - menu = _menuAdd(ourGlobals->win, tb, "edit"); - elm_menu_item_add(menu, NULL, NULL, "preferences", NULL, NULL); - - menu = _menuAdd(ourGlobals->win, tb, "view"); - menu = _menuAdd(ourGlobals->win, tb, "world"); - menu = _menuAdd(ourGlobals->win, tb, "tools"); - - menu = _menuAdd(ourGlobals->win, tb, "help"); - elm_menu_item_add(menu, NULL, NULL, "grid help", NULL, NULL); - elm_menu_item_separator_add(menu, NULL); - elm_menu_item_add(menu, NULL, NULL, "extantz blogs", NULL, NULL); - elm_menu_item_add(menu, NULL, NULL, "extantz forum", NULL, NULL); - elm_menu_item_separator_add(menu, NULL); - elm_menu_item_add(menu, NULL, NULL, "about extantz", NULL, NULL); - - menu = _menuAdd(ourGlobals->win, tb, "advanced"); - elm_menu_item_add(menu, NULL, NULL, "debug settings", NULL, NULL); - - menu = _menuAdd(ourGlobals->win, tb, "god"); - - // Other stuff in the toolbar. - tb_it = elm_toolbar_item_append(tb, NULL, "restriction icons", NULL, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_toolbar_item_separator_set(tb_it, EINA_TRUE); - tb_it = elm_toolbar_item_append(tb, NULL, "hop://localhost/Anarchadia 152, 155, 51 - Lost plot (Adult)", NULL, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_toolbar_item_separator_set(tb_it, EINA_TRUE); - tb_it = elm_toolbar_item_append(tb, NULL, "date time:o'clock", NULL, NULL); - - evas_object_show(tb); + // GL focus gets lost when any menu is used. sigh + + // Try to work around the borkedness of EFL menus by creating our own window. + // I can't figure it out, but the main menu wont appear otherwise. It worked before. + // TODO - rip out ELMs menu and create my own. It sucks. + me = winFangAdd(ourGlobals->mainWindow, 0, -4, ourGlobals->win_w, 0, "main menu hack", "mainMenu", ourGlobals->world); + + tb = makeMainMenu(me); + ourGlobals->tb = tb; + + menu = menuAdd(ourGlobals->mainWindow, tb, "file"); + // Evas_Object *obj, Elm_Object_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data + elm_menu_item_add(menu, NULL, NULL, "open", _on_open, ourGlobals); + elm_menu_item_add(menu, NULL, NULL, "quit", _on_done, gld); + + menu = menuAdd(ourGlobals->mainWindow, tb, "edit"); + elm_menu_item_add(menu, NULL, NULL, "preferences", NULL, NULL); + + menu = menuAdd(ourGlobals->mainWindow, tb, "view"); + menu = menuAdd(ourGlobals->mainWindow, tb, "world"); + menu = menuAdd(ourGlobals->mainWindow, tb, "tools"); + + menu = menuAdd(ourGlobals->mainWindow, tb, "help"); + elm_menu_item_add(menu, NULL, NULL, "grid help", NULL, NULL); + elm_menu_item_separator_add(menu, NULL); + elm_menu_item_add(menu, NULL, NULL, "extantz blogs", NULL, NULL); + elm_menu_item_add(menu, NULL, NULL, "extantz forum", NULL, NULL); + elm_menu_item_separator_add(menu, NULL); + elm_menu_item_add(menu, NULL, NULL, "about extantz", NULL, NULL); + + menu = menuAdd(ourGlobals->mainWindow, tb, "advanced"); + elm_menu_item_add(menu, NULL, NULL, "debug settings", NULL, NULL); + + menu = menuAdd(ourGlobals->mainWindow, tb, "god"); + + makeMainMenuFinish(me, tb); + + // Other stuff in the toolbar. + it = elm_toolbar_item_append(tb, NULL, "restriction icons", NULL, NULL); + it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_toolbar_item_separator_set(it, EINA_TRUE); + it = elm_toolbar_item_append(tb, NULL, "hop://localhost/Anarchadia 152, 155, 51 - Lost plot (Adult)", NULL, NULL); + it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_toolbar_item_separator_set(it, EINA_TRUE); + it = elm_toolbar_item_append(tb, NULL, "date time:o'clock", NULL, NULL); + + winFangCalcMinSize(me); + + return me; } // Elm inlined image windows needs this to change focus on mouse click. @@ -633,6 +604,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1); elm_config_preferred_engine_set("opengl_x11"); elm_config_accel_preference_set("3d"); + ourGlobals.mainWindow = winFangAdd(NULL, 0, 0, 50, 20, "extantz virtual world viewer", "extantz", NULL); ourGlobals.win = ourGlobals.mainWindow->win; @@ -648,6 +620,8 @@ EAPI_MAIN int elm_main(int argc, char **argv) // Get the screen size. elm_win_screen_size_get(ourGlobals.win, &ourGlobals.win_x, &ourGlobals.win_y, &ourGlobals.scr_w, &ourGlobals.scr_h); ourGlobals.win_x = ourGlobals.win_x + (ourGlobals.scr_w / 3); + // TODO - Now we have to take the frame height into consideration, didn't have to do that before. Faked for now. + ourGlobals.win_y += 28; ourGlobals.win_w = ourGlobals.scr_w / 2; ourGlobals.win_h = ourGlobals.scr_h - 30; evas_object_move(ourGlobals.win, ourGlobals.win_x, ourGlobals.win_y); @@ -655,6 +629,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) evas_object_event_callback_add(ourGlobals.win, EVAS_CALLBACK_RESIZE, _on_resize, &ourGlobals); + /* Our "layers". TODO - This is out of date, I should update it. Elm win - our real main window @@ -693,7 +668,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) #else snprintf(buf, sizeof(buf), "%s/sky_03.jpg", prefix_data_get()); eo_do(ourGlobals.mainWindow->bg, - elm_obj_image_file_set(buf, NULL), + efl_file_set(buf, NULL), efl_gfx_color_set(255, 255, 255, 255) ); #endif @@ -710,11 +685,6 @@ EAPI_MAIN int elm_main(int argc, char **argv) ourGlobals.scene->clickCb = _onWorldClick; #endif - // Gotta do this after adding the windows, otherwise the menu renders under the window. - // This sucks, gotta redefine this menu each time we create a new window? - // Also, GL focus gets lost when any menu is used. sigh - makeMainMenu(&ourGlobals); - ourGlobals.world = ephysicsAdd(&ourGlobals); // overlay_add(&ourGlobals); @@ -724,13 +694,14 @@ EAPI_MAIN int elm_main(int argc, char **argv) ourGlobals.LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals.mainWindow, ourGlobals.world); ourGlobals.files = filesAdd(&ourGlobals, (char *) prefix_data_get(), EINA_TRUE, EINA_FALSE); + // Gotta do this after adding the windows, otherwise the menu renders under the window. + // This sucks, gotta redefine this menu each time we create a new window? + _makeMainMenu(&ourGlobals); + // Try to connect to a local love server. serverStream = eina_strbuf_new(); reachOut("127.0.0.1", 8211 + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _add, (Ecore_Event_Handler_Cb) _data, (Ecore_Event_Handler_Cb) _del); - // Bump the top toolbar above the windows. - evas_object_raise(ourGlobals.tb); - _on_resize(&ourGlobals, NULL, NULL, NULL); elm_run(); @@ -747,7 +718,6 @@ EAPI_MAIN int elm_main(int argc, char **argv) #if USE_EVAS_3D scenriDel(ourGlobals.scene); #endif -// eo_unref(ourGlobals.tb); winFangDel(ourGlobals.mainWindow); } diff --git a/src/extantz/woMan.c b/src/extantz/woMan.c index 42b31fc..5436cc2 100644 --- a/src/extantz/woMan.c +++ b/src/extantz/woMan.c @@ -155,26 +155,14 @@ winFang *woMan_add(globals *ourGlobals) { winFang *me; Evas_Object *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; - Elm_Object_Item *tb_it, *menu_it, *tab_it; + Elm_Object_Item *menu_it, *tab_it; char buf[PATH_MAX]; int i; me = winFangAdd(ourGlobals->mainWindow, 600, 650, ourGlobals->win_w / 3, ourGlobals->win_h / 3, "virtual world manager", "woMan", ourGlobals->world); - // A tab thingy. - tb = elm_toolbar_add(me->win); - evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL); - - // Menu. - tb_it = elm_toolbar_item_append(tb, NULL, "Menu", NULL, NULL); - elm_toolbar_item_menu_set(tb_it, EINA_TRUE); - // Priority is for when toolbar items are set to hide or menu when there are too many of them. They get hidden or put on the menu based on priority. - elm_toolbar_item_priority_set(tb_it, 9999); - elm_toolbar_menu_parent_set(tb, me->win); - menu = elm_toolbar_item_menu_get(tb_it); - + tb = makeMainMenu(me); + menu = menuAdd(me, tb, "Menu"); menu_it = elm_menu_item_add(menu, NULL, NULL, "edit", NULL, NULL); elm_menu_item_add(menu, menu_it, NULL, "preferences", NULL, NULL); menu_it = elm_menu_item_add(menu, NULL, NULL, "help", NULL, NULL); @@ -183,9 +171,7 @@ winFang *woMan_add(globals *ourGlobals) menu_it = elm_menu_item_add(menu, NULL, NULL, "advanced", NULL, NULL); elm_menu_item_add(menu, menu_it, NULL, "debug settings", NULL, NULL); - // The toolbar needs to be packed into the box AFTER the menus are added. - elm_layout_box_append(me->win, WF_BOX, tb); - evas_object_show(tb); + makeMainMenuFinish(me, tb); gridList = elm_genlist_add(me->win); grids = eina_hash_stringshared_new(free); @@ -280,7 +266,6 @@ winFang *woMan_add(globals *ourGlobals) elm_object_text_set(bt, "Login"); // No eo interface for this that I can find. // evas_object_smart_callback_add(bt, "clicked", NULL, NULL); elm_layout_box_append(me->win, WF_BOX, bt); -// eo_unref(bt); winFangCalcMinSize(me); diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index eac3c37..b99cfdb 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -513,3 +513,60 @@ On the other hand, image is all I really need to fake it. elm_cnp.h seems to be the only docs, not actually linked to the rest of Elm docs. */ + + +Evas_Object *makeMainMenu(winFang *win) +{ + // A toolbar thingy. + return eo_add(ELM_TOOLBAR_CLASS, win->win, + evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0.0), + evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), + elm_obj_toolbar_shrink_mode_set(ELM_TOOLBAR_SHRINK_MENU), + efl_gfx_position_set(0, 0), + elm_obj_toolbar_align_set(0.0) + ); +} + +static void _on_menu_focus(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) +{ + evas_object_raise(obj); +} + +Evas_Object *menuAdd(winFang *win, Evas_Object *tb, char *label) +{ + Evas_Object *menu= NULL; + Elm_Object_Item *tb_it; + + // Evas_Object * obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data + // The function is called when the item is clicked. + tb_it = elm_toolbar_item_append(tb, NULL, label, NULL, NULL); + // Mark it as a menu. + elm_toolbar_item_menu_set(tb_it, EINA_TRUE); + // This alledgedly marks it as a menu (not true), and gets an Evas_Object for us to play with. + menu = elm_toolbar_item_menu_get(tb_it); + // Alas this does not work. B-( + evas_object_smart_callback_add(menu, "focused", _on_menu_focus, NULL); + + // Priority is for when toolbar items are set to hide or menu when there are too many of them. They get hidden or put on the menu based on priority. + elm_toolbar_item_priority_set(tb_it, 9999); + + // The docs for this functien are meaningless, but it wont work right if you leave it out. + elm_toolbar_menu_parent_set(tb, win->win); + + // Add a seperator after, so that there's some visual distinction between menu items. + // Coz using all lower case and with no underline on the first letter, it's hard to tell. + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_toolbar_item_separator_set(tb_it, EINA_TRUE); + + return menu; +} + +void makeMainMenuFinish(winFang *win, Evas_Object *tb) +{ + // The toolbar needs to be packed into the box AFTER the menus are added. + elm_layout_box_append(win->win, WF_BOX, tb); + evas_object_show(tb); + + // Bump the menu above the windows. + evas_object_raise(tb); +} diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index f2aebfd..91ceb0c 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h @@ -88,4 +88,8 @@ void winFangDel(winFang *win); Widget *widgetAdd(winFang *win, char *type, char *title, int x, int y, int w, int h); void widgetDel(Widget *wid); +Evas_Object *makeMainMenu(winFang *win); +Evas_Object *menuAdd(winFang *win, Evas_Object *tb, char *label); +void makeMainMenuFinish(winFang *win, Evas_Object *tb); + #endif -- cgit v1.1