From f3299aaf29636b8df86cab1bd994479574a55a2d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 21 Mar 2016 21:28:59 -0300 Subject: [PATCH] gui.c: add "Allow" menu to GUI --- gui.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/gui.c b/gui.c index 74792cc..667c981 100644 --- a/gui.c +++ b/gui.c @@ -1,8 +1,8 @@ /* * gui.c - Editor GUI core * - * Written 2009-2012, 2015 by Werner Almesberger - * Copyright 2009-2012, 2015 by Werner Almesberger + * Written 2009-2012, 2015-2016 by Werner Almesberger + * Copyright 2009-2012, 2015-2016 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,6 +49,8 @@ static GtkWidget *ev_stuff, *ev_meas, *ev_all, *ev_bright; static GtkWidget *stuff_image[2], *meas_image[2], *all_image[2]; static GtkWidget *bright_image[2]; +static GtkItemFactory *menu_factory; + static void do_build_frames(void); @@ -103,6 +105,41 @@ static void show_pkg(void) } +/* ----- allow callbacks --------------------------------------------------- */ + + +static void allow_touch(void) +{ + allow_overlap = ao_touch; + change_world(); +} + + +static void allow_any_overlap(void) +{ + allow_overlap = ao_any; + change_world(); +} + + +static void allow_neither(void) +{ + allow_overlap = ao_none; + change_world(); +} + + +static void allow_holes(void) +{ + GtkCheckMenuItem *item = + GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(menu_factory, + "/Allow/Holes")); + + holes_linked = !gtk_check_menu_item_get_active(item); + change_world(); +} + + /* ----- menu bar ---------------------------------------------------------- */ @@ -130,12 +167,15 @@ static GtkItemFactoryEntry menu_entries[] = { "/View/Show variables" }, { "/View/Show packages",NULL, show_pkg, 0, "/View/Show variables" }, + { "/Allow/Touch", NULL, allow_touch, 0, "" }, + { "/Allow/Overlap", NULL, allow_any_overlap, + 0, "/Allow/Touch" }, + { "/Allow/Neither", NULL, allow_neither, 0, "/Allow/Touch" }, + { "/Allow/sep1", NULL, NULL, 0, "" }, + { "/Allow/Holes", NULL, allow_holes, 0, "" } }; -static GtkItemFactory *menu_factory; - - static void make_menu_bar(GtkWidget *hbox) { GtkWidget *bar; @@ -176,6 +216,28 @@ void update_menu_bar(void) gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(menu_factory, s)), TRUE); + + switch (allow_overlap) { + case ao_none: + s = "/Allow/Neither"; + break; + case ao_touch: + s = "/Allow/Touch"; + break; + case ao_any: + s = "/Allow/Overlap"; + break; + default: + abort(); + } + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(menu_factory, s)), + TRUE); + + + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(menu_factory, + "/Allow/Holes")), !holes_linked); } @@ -461,6 +523,7 @@ int gui_main(void) edit_nothing(); select_frame(frames); make_popups(); + update_menu_bar(); gtk_main();