litchie / exult-ios

Exult ( http://exult.sourceforge.net/ )
GNU General Public License v2.0
42 stars 8 forks source link

Shortcut bar - change owner to gamewin (gamewin.cc) #37

Closed DominusExult closed 8 years ago

DominusExult commented 8 years ago

I think a big source of some shortcut bar problems is that it is created in exult.cc while it should just be in gamewin.cc. The example of the previous keyboardgump was maybe misleading because that gump was supposed to be visible all the time, including the Exult menu etc.

This opens another set of problems, though:

My patch for this is at http://pastebin.com/WaMUQMBK (and pasted here as well - I have no idea how to make a pullrequest from a project I'm a member of).

diff --git a/exult.cc b/exult.cc
index 4422fdf..d4beb7c 100644
--- a/exult.cc
+++ b/exult.cc
@@ -743,7 +743,6 @@ int exult_main(const char *runpath) {
 #endif

 #ifdef __IPHONEOS__
-   g_shortcutBar = new ShortcutBar_gump(0,0);

    touchui->showGameControls();
 #endif
@@ -1462,8 +1461,8 @@ static void Handle_event(
        Touchscreen->handle_event(&event);
 #endif
 #ifdef __IPHONEOS__
-       if (g_shortcutBar->handle_event(&event))
-           break;
+       //if (g_shortcutBar->handle_event(&event))
+       //  break;
 #endif
        int x, y;
        gwin->get_win()->screen_to_game(event.button.x, event.button.y, gwin->get_fastmouse(), x, y);
@@ -1597,8 +1596,8 @@ static void Handle_event(
                Mouse::mouse->set_speed_cursor();
            }
 #ifdef __IPHONEOS__
-           if (g_shortcutBar->handle_event(&event))
-               break;
+           //if (g_shortcutBar->handle_event(&event))
+           //  break;
 #endif
            // Last click within .5 secs?
            if (curtime - last_b1_click < 500 &&
@@ -1856,8 +1855,8 @@ static int Get_click(
                Touchscreen->handle_event(&event);
 #endif
 #ifdef __IPHONEOS__
-           if (g_shortcutBar->handle_event(&event))
-               break;
+           //if (g_shortcutBar->handle_event(&event))
+           //  break;
 #endif
                if (event.button.button == 3)
                    rightclick = true;
@@ -1874,8 +1873,8 @@ static int Get_click(
                Touchscreen->handle_event(&event);
 #endif
 #ifdef __IPHONEOS__
-               if (g_shortcutBar->handle_event(&event))
-                   break;
+               //if (g_shortcutBar->handle_event(&event))
+               //  break;
 #endif
                if (event.button.button == 1) {
                    gwin->get_win()->screen_to_game(event.button.x, event.button.y, gwin->get_fastmouse(), x, y);
diff --git a/gamerend.cc b/gamerend.cc
index b36a94c..be751b6 100644
--- a/gamerend.cc
+++ b/gamerend.cc
@@ -539,10 +539,6 @@ void Game_window::paint_dirty() {
 #ifdef UNDER_CE
    gkeyboard->paint();
 #endif
-#ifdef __IPHONEOS__
-   if (g_shortcutBar)
-       g_shortcutBar->paint();
-#endif
 }

 /*
diff --git a/gamewin.cc b/gamewin.cc
index ab3d553..50c39b4 100644
--- a/gamewin.cc
+++ b/gamewin.cc
@@ -88,6 +88,9 @@
 #include "monstinf.h"
 #include "usefuns.h"
 #include "audio/midi_drivers/XMidiFile.h"
+#ifdef __IPHONEOS__
+#  include "iphone_gumps.h"
+#endif

 #ifdef USE_EXULTSTUDIO
 #include "server.h"
@@ -2890,7 +2893,8 @@ void Game_window::setup_game(
    painted = true;         // Main loop uses this.
    gump_man->close_all_gumps(true);        // Kill gumps.
    Face_stats::load_config(config);
-
+   ShortcutBar_gump *g_shortcutBar;
+   g_shortcutBar = new ShortcutBar_gump(0,0);
    // Set palette for time-of-day.
    clock->reset();
    clock->set_palette();
diff --git a/gumps/Gump_manager.cc b/gumps/Gump_manager.cc
index 88a1400..4fc98e8 100644
--- a/gumps/Gump_manager.cc
+++ b/gumps/Gump_manager.cc
@@ -431,11 +431,6 @@ void Gump_manager::paint(bool modal) {
 #ifdef UNDER_CE
    gkeyboard->paint();
 #endif
-#ifdef __IPHONEOS__
-   if (g_shortcutBar) {
-       g_shortcutBar->paint();
-   }
-#endif
 }

@@ -462,7 +457,7 @@ int Gump_manager::handle_modal_gump_event(

    int gx, gy;
    Uint16 keysym_unicode = 0;
-
+   ShortcutBar_gump *g_shortcutBar;
    switch (event.type) {
 #ifdef UNDER_CE
    case SDL_ACTIVEEVENT:
diff --git a/gumps/iphone_gumps.cc b/gumps/iphone_gumps.cc
index 179bca5..f54ba84 100644
--- a/gumps/iphone_gumps.cc
+++ b/gumps/iphone_gumps.cc
@@ -293,11 +293,13 @@ ShortcutBar_gump::ShortcutBar_gump(int placex, int placey)
    locy = placey;

    createButtons();
+   gumpman->add_gump(this);
 }

 ShortcutBar_gump::~ShortcutBar_gump()
 {
    deleteButtons();
+   gumpman->close_gump(this);
 }

 void ShortcutBar_gump::paint()
DominusExult commented 8 years ago

done with 6df4497