aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libui_sdl/libui/unix/menu.c46
-rw-r--r--src/libui_sdl/main.cpp24
2 files changed, 58 insertions, 12 deletions
diff --git a/src/libui_sdl/libui/unix/menu.c b/src/libui_sdl/libui/unix/menu.c
index 5ccb4a5..c4affd2 100644
--- a/src/libui_sdl/libui/unix/menu.c
+++ b/src/libui_sdl/libui/unix/menu.c
@@ -10,6 +10,7 @@ static gboolean hasAbout = FALSE;
struct uiMenu {
char *name;
GArray *items; // []*uiMenuItem
+ gboolean ischild;
};
struct uiMenuItem {
@@ -21,6 +22,7 @@ struct uiMenuItem {
gboolean disabled;
gboolean checked;
GHashTable *windows; // map[GtkMenuItem]*menuItemWindow
+ uiMenu *popupchild;
};
struct menuItemWindow {
@@ -35,6 +37,7 @@ enum {
typePreferences,
typeAbout,
typeSeparator,
+ typeSubmenu,
};
// we do NOT want programmatic updates to raise an ::activated signal
@@ -179,6 +182,33 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
}
item->windows = g_hash_table_new(g_direct_hash, g_direct_equal);
+ item->popupchild = NULL;
+
+ return item;
+}
+
+uiMenuItem *uiMenuAppendSubmenu(uiMenu *m, uiMenu* child)
+{
+ uiMenuItem *item;
+
+ if (menusFinalized)
+ userbug("You cannot create a new menu item after menus have been finalized.");
+
+ item = uiNew(uiMenuItem);
+
+ g_array_append_val(m->items, item);
+
+ item->type = typeSubmenu;
+ item->name = child->name;
+
+ uiMenuItemOnClicked(item, defaultOnClicked, NULL);
+
+ // checkme
+ item->gtype = GTK_TYPE_MENU_ITEM;
+
+ item->windows = g_hash_table_new(g_direct_hash, g_direct_equal);
+ item->popupchild = child;
+ child->ischild = TRUE;
return item;
}
@@ -240,6 +270,7 @@ uiMenu *uiNewMenu(const char *name)
m->name = g_strdup(name);
m->items = g_array_new(FALSE, TRUE, sizeof (uiMenuItem *));
+ m->ischild = FALSE;
return m;
}
@@ -260,10 +291,24 @@ static void appendMenuItem(GtkMenuShell *submenu, uiMenuItem *item, uiWindow *w)
singleSetChecked(GTK_CHECK_MENU_ITEM(menuitem), item->checked, signal);
}
gtk_menu_shell_append(submenu, menuitem);
+
ww = uiNew(struct menuItemWindow);
ww->w = w;
ww->signal = signal;
g_hash_table_insert(item->windows, menuitem, ww);
+
+ if (item->popupchild != NULL)
+ {
+ int j;
+ uiMenu* m;
+ GtkWidget *submenu;
+
+ m = item->popupchild;
+ submenu = gtk_menu_new();
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
+ for (j = 0; j < m->items->len; j++)
+ appendMenuItem(GTK_MENU_SHELL(submenu), g_array_index(m->items, uiMenuItem *, j), w);
+ }
}
GtkWidget *makeMenubar(uiWindow *w)
@@ -281,6 +326,7 @@ GtkWidget *makeMenubar(uiWindow *w)
if (menus != NULL)
for (i = 0; i < menus->len; i++) {
m = g_array_index(menus, uiMenu *, i);
+ if (m->ischild) continue;
menuitem = gtk_menu_item_new_with_label(m->name);
submenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index a644e2f..110dd25 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -594,7 +594,7 @@ void SetupScreenRects(int width, int height)
switch (ScreenRotation)
{
- case 1: // 90°
+ case 1: // 90\B0
{
uiDrawMatrixTranslate(&TopScreenTrans, -TopScreenRect.X, -TopScreenRect.Y);
uiDrawMatrixRotate(&TopScreenTrans, 0, 0, M_PI/2.0f);
@@ -612,7 +612,7 @@ void SetupScreenRects(int width, int height)
}
break;
- case 2: // 180°
+ case 2: // 180\B0
{
uiDrawMatrixTranslate(&TopScreenTrans, -TopScreenRect.X, -TopScreenRect.Y);
uiDrawMatrixRotate(&TopScreenTrans, 0, 0, M_PI);
@@ -624,7 +624,7 @@ void SetupScreenRects(int width, int height)
}
break;
- case 3: // 270°
+ case 3: // 270\B0
{
uiDrawMatrixTranslate(&TopScreenTrans, -TopScreenRect.X, -TopScreenRect.Y);
uiDrawMatrixRotate(&TopScreenTrans, 0, 0, -M_PI/2.0f);
@@ -1057,7 +1057,7 @@ int main(int argc, char** argv)
{
char name[32];
sprintf(name, "%d", kScreenRot[i]*90);
- MenuItem_ScreenRot[i] = uiMenuAppendItem(submenu, name);
+ MenuItem_ScreenRot[i] = uiMenuAppendCheckItem(submenu, name);
uiMenuItemOnClicked(MenuItem_ScreenRot[i], OnSetScreenRotation, (void*)&kScreenRot[i]);
}
@@ -1071,7 +1071,7 @@ int main(int argc, char** argv)
{
char name[32];
sprintf(name, "%d pixels", kScreenGap[i]);
- MenuItem_ScreenGap[i] = uiMenuAppendItem(submenu, name);
+ MenuItem_ScreenGap[i] = uiMenuAppendCheckItem(submenu, name);
uiMenuItemOnClicked(MenuItem_ScreenGap[i], OnSetScreenGap, (void*)&kScreenGap[i]);
}
@@ -1080,11 +1080,11 @@ int main(int argc, char** argv)
{
uiMenu* submenu = uiNewMenu("Screen layout");
- MenuItem_ScreenLayout[0] = uiMenuAppendItem(submenu, "Natural");
+ MenuItem_ScreenLayout[0] = uiMenuAppendCheckItem(submenu, "Natural");
uiMenuItemOnClicked(MenuItem_ScreenLayout[0], OnSetScreenLayout, (void*)&kScreenLayout[0]);
- MenuItem_ScreenLayout[1] = uiMenuAppendItem(submenu, "Vertical");
+ MenuItem_ScreenLayout[1] = uiMenuAppendCheckItem(submenu, "Vertical");
uiMenuItemOnClicked(MenuItem_ScreenLayout[1], OnSetScreenLayout, (void*)&kScreenLayout[1]);
- MenuItem_ScreenLayout[2] = uiMenuAppendItem(submenu, "Horizontal");
+ MenuItem_ScreenLayout[2] = uiMenuAppendCheckItem(submenu, "Horizontal");
uiMenuItemOnClicked(MenuItem_ScreenLayout[2], OnSetScreenLayout, (void*)&kScreenLayout[2]);
uiMenuAppendSubmenu(menu, submenu);
@@ -1092,13 +1092,13 @@ int main(int argc, char** argv)
{
uiMenu* submenu = uiNewMenu("Screen sizing");
- MenuItem_ScreenSizing[0] = uiMenuAppendItem(submenu, "Even");
+ MenuItem_ScreenSizing[0] = uiMenuAppendCheckItem(submenu, "Even");
uiMenuItemOnClicked(MenuItem_ScreenSizing[0], OnSetScreenSizing, (void*)&kScreenSizing[0]);
- MenuItem_ScreenSizing[1] = uiMenuAppendItem(submenu, "Emphasize top");
+ MenuItem_ScreenSizing[1] = uiMenuAppendCheckItem(submenu, "Emphasize top");
uiMenuItemOnClicked(MenuItem_ScreenSizing[1], OnSetScreenSizing, (void*)&kScreenSizing[1]);
- MenuItem_ScreenSizing[2] = uiMenuAppendItem(submenu, "Emphasize bottom");
+ MenuItem_ScreenSizing[2] = uiMenuAppendCheckItem(submenu, "Emphasize bottom");
uiMenuItemOnClicked(MenuItem_ScreenSizing[2], OnSetScreenSizing, (void*)&kScreenSizing[2]);
- MenuItem_ScreenSizing[3] = uiMenuAppendItem(submenu, "Auto");
+ MenuItem_ScreenSizing[3] = uiMenuAppendCheckItem(submenu, "Auto");
uiMenuItemOnClicked(MenuItem_ScreenSizing[3], OnSetScreenSizing, (void*)&kScreenSizing[3]);
uiMenuAppendSubmenu(menu, submenu);