From 30d9c79be0002281d6c968a9b4a8e25b6d215edf Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Wed, 2 Jan 2013 21:43:27 +0100 Subject: [PATCH] Big WIP on keyboard handling and Menu support --- ogl_editor/data/macosx/appnib.xib | 861 +++++++++++++++++++++++++++++++++- ogl_editor/src/Editor.c | 154 +++++- ogl_editor/src/Editor.h | 10 +- ogl_editor/src/Menu.c | 88 ++++ ogl_editor/src/Menu.h | 95 ++++ ogl_editor/src/macosx/RocketView.m | 288 +++++++++++- ogl_editor/src/macosx/delegate.h | 2 +- ogl_editor/src/macosx/delegate.m | 13 +- ogl_editor/src/windows/RocketWindow.c | 11 +- tundra.lua | 2 +- units.lua | 2 +- 11 files changed, 1496 insertions(+), 30 deletions(-) create mode 100644 ogl_editor/src/Menu.c create mode 100644 ogl_editor/src/Menu.h diff --git a/ogl_editor/data/macosx/appnib.xib b/ogl_editor/data/macosx/appnib.xib index 068f3ba..a06b934 100644 --- a/ogl_editor/data/macosx/appnib.xib +++ b/ogl_editor/data/macosx/appnib.xib @@ -194,6 +194,443 @@ + + + Edit + + 2147483647 + + + submenuAction: + + Edit + + YES + + + Undo + z + 1048576 + 2147483647 + + + 5 + + + + Redo + Z + 1048576 + 2147483647 + + + 6 + + + + Cancel Edit + Gw + 2147483647 + + + 7 + + + + Clear + CA + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Cut + x + 1048576 + 2147483647 + + + + + + Copy + c + 1048576 + 2147483647 + + + + + + Paste + v + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Select Track + t + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Bias +0.01 + q + 2147483647 + + + + + + Bias +0.1 + w + 2147483647 + + + + + + Bias +1.0 + e + 2147483647 + + + + + + Bias +10.0 + r + 2147483647 + + + + + + Bias +100.0 + t + 2147483647 + + + + + + Bias +1000.0 + y + 2147483647 + + + + + + Bias -0.01 + a + 2147483647 + + + + + + Bias -0.1 + s + 2147483647 + + + + + + Bias -1.0 + d + 2147483647 + + + + + + Bias -10.0 + f + 2147483647 + + + + + + Bias -100.0 + g + 2147483647 + + + + + + Bias -1000.0 + h + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Interpolation mode + i + 2147483647 + + + + + + Insert current interpolate value + DQ + 2147483647 + + + + + + + + + View + + 2147483647 + + + submenuAction: + + View + + YES + + + Start/Stop Playback + IA + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Jump 8 rows up + + 524288 + 2147483647 + + + + + + Jump 8 rows down + + 524288 + 2147483647 + + + + + + Jump to previous bookmark + + 1048576 + 2147483647 + + + + + + Jump to next bookmark + + 1048576 + 2147483647 + + + + + + Jump to first track + + 1048576 + 2147483647 + + + + + + Jump to last track + + 1048576 + 2147483647 + + + + + + Jump to previous key + + 262144 + 2147483647 + + + + + + Jump to next key + + 262144 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Fold track + + 524288 + 2147483647 + + + + + + Unfold track + + 524288 + 2147483647 + + + + + + Fold group + + 786432 + 2147483647 + + + + + + Unfold group + + 786432 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Toogle bookmark + b + 2147483647 + + + + + + Clear bookmarks + b + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Jump row,start/endrow & edit + GQ + 131072 + 2147483647 + + + + + + Window @@ -314,7 +751,7 @@ YES - MinimalAppAppDelegate + RocketAppDelegate NSFontManager @@ -411,6 +848,14 @@ 546 + + + buttonClicked: + + + + 547 + @@ -450,6 +895,8 @@ + + @@ -662,6 +1109,316 @@ + + 568 + + + YES + + + + + + 569 + + + YES + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 570 + + + + + 571 + + + + + 573 + + + + + 574 + + + + + 575 + + + + + 576 + + + + + 577 + + + + + 578 + + + + + 579 + + + + + 580 + + + + + 581 + + + + + 582 + + + + + 583 + + + + + 584 + + + + + 585 + + + + + 586 + + + + + 589 + + + + + 590 + + + + + 591 + + + + + 592 + + + + + 593 + + + + + 594 + + + + + 595 + + + + + 596 + + + + + 597 + + + + + 598 + + + + + 677 + + + YES + + + + + + 678 + + + YES + + + + + + + + + + + + + + + + + + + + + + + + + 689 + + + + + 687 + + + + + 695 + + + + + 686 + + + + + 704 + + + + + 694 + + + + + 709 + + + + + 700 + + + + + 705 + + + + + 691 + + + + + 690 + + + + + 710 + + + + + 711 + + + + + 713 + + + + + 714 + + + + + 715 + + + + + 716 + + + + + 717 + + + + + 718 + + + + + 719 + + + @@ -693,8 +1450,58 @@ 562.IBPluginDependency 563.IBPluginDependency 564.IBPluginDependency + 568.IBPluginDependency + 569.IBPluginDependency 57.IBPluginDependency + 570.IBPluginDependency + 571.IBPluginDependency + 573.IBPluginDependency + 574.IBPluginDependency + 575.IBPluginDependency + 576.IBPluginDependency + 577.IBPluginDependency + 578.IBPluginDependency + 579.IBPluginDependency 58.IBPluginDependency + 580.IBPluginDependency + 581.IBPluginDependency + 582.IBPluginDependency + 583.IBPluginDependency + 584.IBPluginDependency + 585.IBPluginDependency + 586.IBPluginDependency + 589.IBPluginDependency + 590.IBPluginDependency + 591.IBPluginDependency + 592.IBPluginDependency + 593.IBPluginDependency + 594.IBPluginDependency + 595.IBPluginDependency + 596.IBPluginDependency + 597.IBPluginDependency + 598.IBPluginDependency + 677.IBPluginDependency + 678.IBPluginDependency + 686.IBPluginDependency + 687.IBPluginDependency + 689.IBPluginDependency + 690.IBPluginDependency + 691.IBPluginDependency + 694.IBPluginDependency + 695.IBPluginDependency + 700.IBPluginDependency + 704.IBPluginDependency + 705.IBPluginDependency + 709.IBPluginDependency + 710.IBPluginDependency + 711.IBPluginDependency + 713.IBPluginDependency + 714.IBPluginDependency + 715.IBPluginDependency + 716.IBPluginDependency + 717.IBPluginDependency + 718.IBPluginDependency + 719.IBPluginDependency 72.IBPluginDependency 74.IBPluginDependency 75.IBPluginDependency @@ -743,6 +1550,56 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -757,7 +1614,7 @@ - 567 + 721 0 diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index 676f878..97a4a65 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -3,6 +3,7 @@ #include #include #include +#include "Menu.h" #include "Dialog.h" #include "Editor.h" #include "LoadSave.h" @@ -1322,6 +1323,13 @@ void updateNeedsSaving() /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +bool Editor_needsSave() +{ + return s_undoLevel != Commands_undoCount(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static void onFinishedLoad(const text_t* path) { Editor_update(); @@ -1343,6 +1351,72 @@ void Editor_loadRecentFile(int id) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +const char* s_type[] = +{ + "EDITOR_MENU_NEW", + "EDITOR_MENU_SUB_MENU", + "EDITOR_MENU_SEPARATOR", + "EDITOR_MENU_RECENT_FILE_0", + "EDITOR_MENU_RECENT_FILE_1", + "EDITOR_MENU_RECENT_FILE_2", + "EDITOR_MENU_RECENT_FILE_3", + "EDITOR_MENU_OPEN", + "EDITOR_MENU_SAVE", + "EDITOR_MENU_SAVE_AS", + "EDITOR_MENU_REMOTE_EXPORT", + "EDITOR_MENU_UNDO", + "EDITOR_MENU_REDO", + "EDITOR_MENU_CANCEL_EDIT", + "EDITOR_MENU_CLEAR", + "EDITOR_MENU_CUT", + "EDITOR_MENU_COPY", + "EDITOR_MENU_PASTE", + "EDITOR_MENU_SELECT_TRACK", + "EDITOR_MENU_BIAS_P_001", + "EDITOR_MENU_BIAS_P_01", + "EDITOR_MENU_BIAS_P_1", + "EDITOR_MENU_BIAS_P_10", + "EDITOR_MENU_BIAS_P_100", + "EDITOR_MENU_BIAS_P_1000", + "EDITOR_MENU_BIAS_N_001", + "EDITOR_MENU_BIAS_N_01", + "EDITOR_MENU_BIAS_N_1", + "EDITOR_MENU_BIAS_N_10", + "EDITOR_MENU_BIAS_N_100", + "EDITOR_MENU_BIAS_N_1000", + "EDITOR_MENU_INTERPOLATION", + "EDITOR_MENU_ENTER_CURRENT_V", + "EDITOR_MENU_PLAY", + "EDITOR_MENU_ROW_UP", + "EDITOR_MENU_ROW_DOWN", + "EDITOR_MENU_TRACK_LEFT", + "EDITOR_MENU_TRACK_RIGHT", + "EDITOR_MENU_ROWS_DOWN", + "EDITOR_MENU_ROWS_UP", + "EDITOR_MENU_PREV_BOOKMARK", + "EDITOR_MENU_NEXT_BOOKMARK", + "EDITOR_MENU_FIRST_TRACK", + "EDITOR_MENU_LAST_TRACK", + "EDITOR_MENU_PREV_KEY", + "EDITOR_MENU_NEXT_KEY", + "EDITOR_MENU_FOLD_TRACK", + "EDITOR_MENU_UNFOLD_TRACK", + "EDITOR_MENU_FOLD_GROUP", + "EDITOR_MENU_UNFOLD_GROUP", + "EDITOR_MENU_TOGGLE_BOOKMARK", + "EDITOR_MENU_CLEAR_BOOKMARKS", + "EDITOR_MENU_TAB", +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Editor_onMenuEvent(int id) +{ + printf("%s\n", s_type[id - 0x1000]); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static void onOpen() { text_t currentFile[2048]; @@ -1353,7 +1427,7 @@ static void onOpen() /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static bool onSaveDialog() +static bool onSaveAs() { text_t path[2048]; int ret; @@ -1373,7 +1447,7 @@ static bool onSaveDialog() static void onSave() { if (!s_loadedFilename) - onSaveDialog(); + onSaveAs(); else LoadSave_saveRocketXML(getMostRecentFile(), getTrackData()); @@ -1391,19 +1465,87 @@ bool Editor_saveBeforeExit() return true; } - return onSaveDialog(); + return onSaveAs(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Editor_menuEvent(int menuItem) { + printf("%s\n", s_type[menuItem - 0x1000]); + switch (menuItem) { - case EDITOR_MENU_OPEN : onOpen(); break; - case EDITOR_MENU_SAVE : onSave(); break; - case EDITOR_MENU_SAVE_AS : onSaveDialog(); break; + case EDITOR_MENU_OPEN: onOpen(); break; + case EDITOR_MENU_SAVE: onSave(); break; + case EDITOR_MENU_SAVE_AS: onSaveAs(); break; case EDITOR_MENU_REMOTE_EXPORT : RemoteConnection_sendSaveCommand(); break; + + case EDITOR_MENU_RECENT_FILE_0: + case EDITOR_MENU_RECENT_FILE_1: + case EDITOR_MENU_RECENT_FILE_2: + case EDITOR_MENU_RECENT_FILE_3: + { + + Editor_loadRecentFile(menuItem - EDITOR_MENU_RECENT_FILE_0); + break; + } + + + /* + EDITOR_MENU_OPEN, + EDITOR_MENU_SAVE, + EDITOR_MENU_SAVE_AS, + EDITOR_MENU_REMOTE_EXPORT, + + // Edit + + EDITOR_MENU_UNDO, + EDITOR_MENU_REDO, + EDITOR_MENU_CANCEL_EDIT, + EDITOR_MENU_CLEAR, + EDITOR_MENU_CUT, + EDITOR_MENU_COPY, + EDITOR_MENU_PASTE, + EDITOR_MENU_SELECT_TRACK, + EDITOR_MENU_BIAS_P_001, + EDITOR_MENU_BIAS_P_01, + EDITOR_MENU_BIAS_P_1, + EDITOR_MENU_BIAS_P_10, + EDITOR_MENU_BIAS_P_100, + EDITOR_MENU_BIAS_P_1000, + EDITOR_MENU_BIAS_N_001, + EDITOR_MENU_BIAS_N_01, + EDITOR_MENU_BIAS_N_1, + EDITOR_MENU_BIAS_N_10, + EDITOR_MENU_BIAS_N_100, + EDITOR_MENU_BIAS_N_1000, + EDITOR_MENU_INTERPOLATION, + EDITOR_MENU_ENTER_CURRENT_V, + + // View + + EDITOR_MENU_PLAY, + EDITOR_MENU_ROW_UP, + EDITOR_MENU_ROW_DOWN, + EDITOR_MENU_TRACK_LEFT, + EDITOR_MENU_TRACK_RIGHT, + EDITOR_MENU_ROWS_DOWN, + EDITOR_MENU_ROWS_UP, + EDITOR_MENU_PREV_BOOKMARK, + EDITOR_MENU_NEXT_BOOKMARK, + EDITOR_MENU_FIRST_TRACK, + EDITOR_MENU_LAST_TRACK, + EDITOR_MENU_PREV_KEY, + EDITOR_MENU_NEXT_KEY, + EDITOR_MENU_FOLD_TRACK, + EDITOR_MENU_UNFOLD_TRACK, + EDITOR_MENU_FOLD_GROUP, + EDITOR_MENU_UNFOLD_GROUP, + EDITOR_MENU_TOGGLE_BOOKMARK, + EDITOR_MENU_CLEAR_BOOKMARKS, + EDITOR_MENU_TAB, + */ } } diff --git a/ogl_editor/src/Editor.h b/ogl_editor/src/Editor.h index 3aec7f7..2532e2b 100644 --- a/ogl_editor/src/Editor.h +++ b/ogl_editor/src/Editor.h @@ -15,20 +15,12 @@ void Editor_scroll(float deltaX, float deltaY, int flags); void Editor_updateTrackScroll(); void Editor_loadRecentFile(int file); bool Editor_saveBeforeExit(); +bool Editor_needsSave(); text_t** Editor_getRecentFiles(); enum { - EDITOR_MENU_NEW, - EDITOR_MENU_OPEN, - EDITOR_MENU_SAVE, - EDITOR_MENU_SAVE_AS, - EDITOR_MENU_REMOTE_EXPORT, -}; - -enum -{ EDITOR_KEY_SHIFT = 1, EDITOR_KEY_ALT = 2, EDITOR_KEY_CTRL = 4, diff --git a/ogl_editor/src/Menu.c b/ogl_editor/src/Menu.c new file mode 100644 index 0000000..f104931 --- /dev/null +++ b/ogl_editor/src/Menu.c @@ -0,0 +1,88 @@ +#include "Menu.h" +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// On win32 (where we use unicode for text-strings) this is defined already + +#ifndef _WIN32 +#define _T(v) v +#endif + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +MenuDescriptor g_fileMenu[] = +{ + { _T("Open..."), EDITOR_MENU_OPEN, 'o', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T("Recent Files"), EDITOR_MENU_SUB_MENU, 0, 0, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Save"), EDITOR_MENU_SAVE, 's', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T("Save as..."), EDITOR_MENU_SAVE_AS, 's', EMGUI_KEY_COMMAND | EMGUI_KEY_SHIFT, EMGUI_KEY_CTRL | EMGUI_KEY_SHIFT }, + { _T("Remote export"), EDITOR_MENU_REMOTE_EXPORT, 'e', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { 0 }, +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +MenuDescriptor g_editMenu[] = +{ + { _T("Undo"), EDITOR_MENU_UNDO, 'z', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T("Redo"), EDITOR_MENU_REDO, 'z', EMGUI_KEY_COMMAND | EMGUI_KEY_SHIFT, EMGUI_KEY_CTRL | EMGUI_KEY_SHIFT }, + { _T("Cancel Edit"), EDITOR_MENU_CANCEL_EDIT, EMGUI_KEY_ESC, 0, 0 }, + { _T("Clear"), EDITOR_MENU_CLEAR, EMGUI_KEY_BACKSPACE, 0, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Cut"), EDITOR_MENU_CUT, 'x', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T("Copy"), EDITOR_MENU_COPY, 'c', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T("Paste"), EDITOR_MENU_PASTE, 'v', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Select Track"), EDITOR_MENU_SELECT_TRACK, 't', EMGUI_KEY_COMMAND, EMGUI_KEY_CTRL }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Bias +0.01"), EDITOR_MENU_BIAS_P_001, 'q', 0, 0 }, + { _T("Bias +0.1"), EDITOR_MENU_BIAS_P_01, 'w', 0, 0 }, + { _T("Bias +1.0"), EDITOR_MENU_BIAS_P_1, 'e', 0, 0 }, + { _T("Bias +10.0"), EDITOR_MENU_BIAS_P_10, 'r', 0, 0 }, + { _T("Bias +10.01"), EDITOR_MENU_BIAS_P_100, 't', 0, 0 }, + { _T("Bias +100.01"), EDITOR_MENU_BIAS_P_1000, 'y', 0, 0 }, + { _T("Bias -0.01"), EDITOR_MENU_BIAS_N_001, 'a', 0, 0 }, + { _T("Bias -0.1"), EDITOR_MENU_BIAS_N_01, 's', 0, 0 }, + { _T("Bias -1.0"), EDITOR_MENU_BIAS_N_1, 'd', 0, 0 }, + { _T("Bias -10.0"), EDITOR_MENU_BIAS_N_10, 'f', 0, 0 }, + { _T("Bias -10.01"), EDITOR_MENU_BIAS_N_100, 'g', 0, 0 }, + { _T("Bias -100.01"), EDITOR_MENU_BIAS_N_1000, 'h', 0, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Interpolation"), EDITOR_MENU_INTERPOLATION, 'i', 0, 0 }, + { _T("Insert current value"), EDITOR_MENU_ENTER_CURRENT_V,EMGUI_KEY_ENTER,0, 0 }, + { 0 }, +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +MenuDescriptor g_viewMenu[] = +{ + { _T("Start/Stop Playback"), EDITOR_MENU_PLAY, EMGUI_KEY_SPACE, 0, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Jump one row up"), EDITOR_MENU_ROW_UP, EMGUI_KEY_ARROW_UP, 0, 0 }, + { _T("Jump one row down"), EDITOR_MENU_ROW_DOWN, EMGUI_KEY_ARROW_DOWN, 0, 0 }, + { _T("Jump one track left"), EDITOR_MENU_TRACK_LEFT, EMGUI_KEY_ARROW_LEFT, 0, 0 }, + { _T("Jump one track right"), EDITOR_MENU_TRACK_RIGHT, EMGUI_KEY_ARROW_RIGHT, 0, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Jump 8 rows up"), EDITOR_MENU_ROWS_UP, EMGUI_KEY_ARROW_UP, EMGUI_KEY_ALT, 0 }, + { _T("Jump 8 rows down"), EDITOR_MENU_ROWS_DOWN, EMGUI_KEY_ARROW_DOWN, EMGUI_KEY_ALT, 0 }, + { _T("Jump to previous bookmark"), EDITOR_MENU_PREV_BOOKMARK, EMGUI_KEY_ARROW_UP, EMGUI_KEY_COMMAND, 0 }, + { _T("Jump to next bookmark"), EDITOR_MENU_NEXT_BOOKMARK, EMGUI_KEY_ARROW_DOWN, EMGUI_KEY_COMMAND, 0 }, + { _T("Jump to first track"), EDITOR_MENU_FIRST_TRACK, EMGUI_KEY_ARROW_LEFT, EMGUI_KEY_COMMAND, 0 }, + { _T("Jump to last track"), EDITOR_MENU_LAST_TRACK, EMGUI_KEY_ARROW_RIGHT, EMGUI_KEY_COMMAND, 0 }, + { _T("Jump to previous key"), EDITOR_MENU_PREV_KEY, EMGUI_KEY_ARROW_UP, EMGUI_KEY_CTRL, 0 }, + { _T("Jump to next key"), EDITOR_MENU_NEXT_KEY, EMGUI_KEY_ARROW_DOWN, EMGUI_KEY_CTRL, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Fold track"), EDITOR_MENU_FOLD_TRACK, EMGUI_KEY_ARROW_LEFT, EMGUI_KEY_ALT, 0 }, + { _T("Unfold track"), EDITOR_MENU_UNFOLD_TRACK, EMGUI_KEY_ARROW_RIGHT, EMGUI_KEY_ALT, 0 }, + { _T("Fold group"), EDITOR_MENU_FOLD_GROUP, EMGUI_KEY_ARROW_LEFT, EMGUI_KEY_ALT | EMGUI_KEY_CTRL, 0 }, + { _T("Unfold group"), EDITOR_MENU_UNFOLD_GROUP, EMGUI_KEY_ARROW_RIGHT, EMGUI_KEY_ALT | EMGUI_KEY_CTRL, 0 }, + { _T(""), EDITOR_MENU_SEPARATOR, 0, 0, 0 }, + { _T("Toogle bookmark"), EDITOR_MENU_TOGGLE_BOOKMARK, 'b', 0, 0 }, + { _T("Clear bookmarks"), EDITOR_MENU_CLEAR_BOOKMARKS, 'b', EMGUI_KEY_SHIFT, EMGUI_KEY_SHIFT }, + { _T("Unfold track"), EDITOR_MENU_UNFOLD_TRACK, EMGUI_KEY_ARROW_RIGHT, EMGUI_KEY_ALT, 0 }, + { _T("Jump row,start/end & edit"), EDITOR_MENU_TAB, EMGUI_KEY_TAB, 0, 0 }, + { 0 }, +}; + diff --git a/ogl_editor/src/Menu.h b/ogl_editor/src/Menu.h new file mode 100644 index 0000000..ac6ecf7 --- /dev/null +++ b/ogl_editor/src/Menu.h @@ -0,0 +1,95 @@ +#pragma once + +#ifndef _WIN32 +#define _T(v) v +#endif + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +enum +{ + // File + + EDITOR_MENU_NEW = 0x1000, + EDITOR_MENU_SUB_MENU, + EDITOR_MENU_SEPARATOR, + EDITOR_MENU_RECENT_FILE_0, + EDITOR_MENU_RECENT_FILE_1, + EDITOR_MENU_RECENT_FILE_2, + EDITOR_MENU_RECENT_FILE_3, + + EDITOR_MENU_OPEN, + EDITOR_MENU_SAVE, + EDITOR_MENU_SAVE_AS, + EDITOR_MENU_REMOTE_EXPORT, + + // Edit + + EDITOR_MENU_UNDO, + EDITOR_MENU_REDO, + EDITOR_MENU_CANCEL_EDIT, + EDITOR_MENU_CLEAR, + EDITOR_MENU_CUT, + EDITOR_MENU_COPY, + EDITOR_MENU_PASTE, + EDITOR_MENU_SELECT_TRACK, + EDITOR_MENU_BIAS_P_001, + EDITOR_MENU_BIAS_P_01, + EDITOR_MENU_BIAS_P_1, + EDITOR_MENU_BIAS_P_10, + EDITOR_MENU_BIAS_P_100, + EDITOR_MENU_BIAS_P_1000, + EDITOR_MENU_BIAS_N_001, + EDITOR_MENU_BIAS_N_01, + EDITOR_MENU_BIAS_N_1, + EDITOR_MENU_BIAS_N_10, + EDITOR_MENU_BIAS_N_100, + EDITOR_MENU_BIAS_N_1000, + EDITOR_MENU_INTERPOLATION, + EDITOR_MENU_ENTER_CURRENT_V, + + // View + + EDITOR_MENU_PLAY, + EDITOR_MENU_ROW_UP, + EDITOR_MENU_ROW_DOWN, + EDITOR_MENU_TRACK_LEFT, + EDITOR_MENU_TRACK_RIGHT, + EDITOR_MENU_ROWS_DOWN, + EDITOR_MENU_ROWS_UP, + EDITOR_MENU_PREV_BOOKMARK, + EDITOR_MENU_NEXT_BOOKMARK, + EDITOR_MENU_FIRST_TRACK, + EDITOR_MENU_LAST_TRACK, + EDITOR_MENU_PREV_KEY, + EDITOR_MENU_NEXT_KEY, + EDITOR_MENU_FOLD_TRACK, + EDITOR_MENU_UNFOLD_TRACK, + EDITOR_MENU_FOLD_GROUP, + EDITOR_MENU_UNFOLD_GROUP, + EDITOR_MENU_TOGGLE_BOOKMARK, + EDITOR_MENU_CLEAR_BOOKMARKS, + EDITOR_MENU_TAB, +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +typedef struct MenuDescriptor +{ +#if defined(_WIN32) + const wchar_t* name; +#else + const char* name; +#endif + int id; + int key; + int macMod; + int winMid; +} MenuDescriptor; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +extern MenuDescriptor g_fileMenu[]; +extern MenuDescriptor g_editMenu[]; +extern MenuDescriptor g_viewMenu[]; + diff --git a/ogl_editor/src/macosx/RocketView.m b/ogl_editor/src/macosx/RocketView.m index 6649cf9..8f7bddf 100644 --- a/ogl_editor/src/macosx/RocketView.m +++ b/ogl_editor/src/macosx/RocketView.m @@ -1,12 +1,85 @@ #import "RocketView.h" #include "../Editor.h" #include "../rlog.h" +#include "../Menu.h" #include #include +#include +#include NSOpenGLContext* g_context = 0; NSWindow* g_window = 0; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Scan codes on Mac taken from http://boredzo.org/blog/archives/2007-05-22/virtual-key-codes + +#define KEY_A 0 +#define KEY_S 1 +#define KEY_D 2 +#define KEY_F 3 +#define KEY_H 4 +#define KEY_G 5 +#define KEY_Z 6 +#define KEY_X 7 +#define KEY_C 8 +#define KEY_V 9 + +#define KEY_B 11 +#define KEY_Q 12 +#define KEY_W 13 +#define KEY_E 14 +#define KEY_R 15 +#define KEY_Y 16 +#define KEY_T 17 +#define KEY_1 18 +#define KEY_2 19 +#define KEY_3 20 +#define KEY_4 21 +#define KEY_6 22 +#define KEY_5 23 +#define KEY_EQUALS 24 +#define KEY_9 25 +#define KEY_7 26 +#define KEY_MINUS 27 +#define KEY_8 28 +#define KEY_0 29 +#define KEY_RIGHTBRACKET 30 +#define KEY_O 31 +#define KEY_U 32 +#define KEY_LEFTBRACKET 33 +#define KEY_I 34 +#define KEY_P 35 +#define KEY_RETURN 36 +#define KEY_L 37 +#define KEY_J 38 +#define KEY_APOSTROPHE 39 +#define KEY_K 40 +#define KEY_SEMICOLON 41 +#define KEY_FRONTSLASH 42 +#define KEY_COMMA 43 +#define KEY_BACKSLASH 44 +#define KEY_N 45 +#define KEY_M 46 +#define KEY_PERIOD 47 +#define KEY_TAB 48 +#define KEY_SPACE 49 + +#define KEY_BACKAPOSTROPHE 50 +#define KEY_DELETE 51 + +#define KEY_ESCAPE 53 + +#define KEY_COMMAND 55 +#define KEY_SHIFT 56 +#define KEY_CAPSLOCK 57 +#define KEY_OPTION 58 +#define KEY_CONTROL 59 + +#define KEY_UP 126 +#define KEY_DOWN 125 +#define KEY_LEFT 123 +#define KEY_RIGHT 124 + @implementation RocketView /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -98,6 +171,7 @@ static int getModifierFlags(int flags) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/* - (void)keyDown:(NSEvent *)theEvent { NSString* key = [theEvent charactersIgnoringModifiers]; @@ -128,7 +202,8 @@ static int getModifierFlags(int flags) Editor_update(); } - +*/ + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (BOOL)acceptsFirstResponder @@ -215,16 +290,218 @@ static int getModifierFlags(int flags) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- (void)onRecentFile:(id)sender +CFStringRef createStringForKey(CGKeyCode keyCode) { - NSString* string = [sender representedObject]; - Editor_loadRecentFile([string intValue]); + TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); + CFDataRef layoutData = + TISGetInputSourceProperty(currentKeyboard, + kTISPropertyUnicodeKeyLayoutData); + + if (!layoutData) + return 0; + + const UCKeyboardLayout *keyboardLayout = + (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData); + + UInt32 keysDown = 0; + UniChar chars[4]; + UniCharCount realLength; + + UCKeyTranslate(keyboardLayout, + keyCode, + kUCKeyActionDisplay, + 0, + LMGetKbdType(), + kUCKeyTranslateNoDeadKeysBit, + &keysDown, + sizeof(chars) / sizeof(chars[0]), + &realLength, + chars); + CFRelease(currentKeyboard); + + return CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +- (void)onMenuPress:(id)sender +{ + int id = (int)((NSButton*)sender).tag; + Editor_menuEvent(id); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static int s_characterToKeyCode[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0x27, // ''' + 0, 0, 0, 0, + 0x2b, // ',' + 0x1b, // '-' + 0x2f, // '.' + 0x2c, // '/' + 0x1d, // '0' + 0x12, // '1' + 0x13, // '2' + 0x14, // '3' + 0x15, // '4' + 0x17, // '5' + 0x16, // '6' + 0x1a, // '7' + 0x1c, // '8' + 0x19, // '9' + 0, + 0x29, // ';' + 0, + 0x18, // '=' + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0x21, // '[' + 0x2a, // '\' + 0x1e, // ']' + 0, + 0, + 0x32, // '`' + 0, + 0x0b, // 'b' + 0x08, // 'c' + 0x02, // 'd' + 0x0e, // 'e' + 0x03, // 'f' + 0x05, // 'g' + 0x04, // 'h' + 0x22, // 'i' + 0x26, // 'j' + 0x28, // 'k' + 0x25, // 'l' + 0x2e, // 'm' + 0x2d, // 'n' + 0x1f, // 'o' + 0x23, // 'p' + 0x0c, // 'q' + 0x0f, // 'r' + 0x01, // 's' + 0x11, // 't' + 0x20, // 'u' + 0x09, // 'v' + 0x0d, // 'w' + 0x07, // 'x' + 0x10, // 'y' + 0x06, // 'z' + 0, 0, 0, 0, 0, +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +NSString* convertKeyCodeToString(int key) +{ + if (key < 128) + { + // first try to translate it and if that doesn't work use it as is + NSString* charName = (NSString*)createStringForKey(s_characterToKeyCode[key]); + + if (charName) + return charName; + + return [NSString stringWithFormat:@"%c", (char)key]; + } + else + { + switch (key) + { + case EMGUI_KEY_ARROW_UP: return [NSString stringWithFormat:@"%C", (uint16_t)0x2191]; + case EMGUI_KEY_ARROW_DOWN: return [NSString stringWithFormat:@"%C", (uint16_t)0x2193]; + case EMGUI_KEY_ARROW_LEFT: return [NSString stringWithFormat:@"%C", (uint16_t)0x2190]; + case EMGUI_KEY_ARROW_RIGHT: return [NSString stringWithFormat:@"%C", (uint16_t)0x2192]; + case EMGUI_KEY_ESC : return [NSString stringWithFormat:@"%C", (uint16_t)0x238b]; + case EMGUI_KEY_ENTER : return [NSString stringWithFormat:@"%C", (uint16_t)NSCarriageReturnCharacter]; + case EMGUI_KEY_SPACE : return @" "; + case EMGUI_KEY_BACKSPACE : return [NSString stringWithFormat:@"%C",(uint16_t)0x232b]; + case EMGUI_KEY_TAB : return [NSString stringWithFormat:@"%C",(uint16_t)0x21e4]; + } + } + + return 0; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void buildSubMenu(NSMenu* menu, MenuDescriptor menuDesc[]) +{ + MenuDescriptor* desc = &menuDesc[0]; + [menu removeAllItems]; + + while (desc->name) + { + NSString* name = [NSString stringWithUTF8String: desc->name]; + + if (desc->id == EDITOR_MENU_SEPARATOR) + { + [menu addItem:[NSMenuItem separatorItem]]; + } + else if (desc->id == EDITOR_MENU_SUB_MENU) + { + NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:name action:NULL keyEquivalent:@""]; + NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:name]; + [newItem setSubmenu:newMenu]; + [newMenu release]; + [menu addItem:newItem]; + [newItem release]; + } + else + { + int mask = 0; + NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(onMenuPress:) keyEquivalent:@""]; + [newItem setTag:desc->id]; + + if (desc->macMod & EMGUI_KEY_COMMAND) + mask |= NSCommandKeyMask; + if (desc->macMod & EMGUI_KEY_SHIFT) + mask |= NSShiftKeyMask; + if (desc->macMod & EMGUI_KEY_CTRL) + mask |= NSControlKeyMask; + if (desc->macMod & EMGUI_KEY_ALT) + mask |= NSAlternateKeyMask; + + NSString* key = convertKeyCodeToString(desc->key); + + if (key) + { + [newItem setKeyEquivalentModifierMask: mask]; + [newItem setKeyEquivalent:key]; + } + else + { + fprintf(stderr, "Unable to map keyboard shortcut for %s\n", desc->name); + } + + [menu addItem:newItem]; + [newItem release]; + } + + desc++; + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void buildMenu() +{ + NSMenu* fileMenu = [[[NSApp mainMenu] itemWithTitle:@"File"] submenu]; + NSMenu* editMenu = [[[NSApp mainMenu] itemWithTitle:@"Edit"] submenu]; + NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu]; + + buildSubMenu(fileMenu, g_fileMenu); + buildSubMenu(editMenu, g_editMenu); + buildSubMenu(viewMenu, g_viewMenu); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Window_populateRecentList(const char** files) { + buildMenu(); + NSMenu* fileMenu = [[[NSApp mainMenu] itemWithTitle:@"File"] submenu]; NSMenu* recentItems = [[fileMenu itemWithTitle:@"Recent Files"] submenu]; @@ -239,7 +516,8 @@ void Window_populateRecentList(const char** files) NSString* name = [NSString stringWithUTF8String: filename]; - NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(onRecentFile:) keyEquivalent:@""]; + NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(onMenuPress:) keyEquivalent:@""]; + [newItem setTag:EDITOR_MENU_RECENT_FILE_0 + i]; [newItem setRepresentedObject:[NSString stringWithFormat:@"%d",i]]; [newItem setKeyEquivalentModifierMask: NSCommandKeyMask]; [newItem setKeyEquivalent:[NSString stringWithFormat:@"%d",i + 1]]; diff --git a/ogl_editor/src/macosx/delegate.h b/ogl_editor/src/macosx/delegate.h index deacfa4..b7f6ec1 100644 --- a/ogl_editor/src/macosx/delegate.h +++ b/ogl_editor/src/macosx/delegate.h @@ -1,7 +1,7 @@ #import -@interface MinimalAppAppDelegate : NSObject { +@interface RocketAppDelegate : NSObject { NSWindow *window; NSButton *button; } diff --git a/ogl_editor/src/macosx/delegate.m b/ogl_editor/src/macosx/delegate.m index ab44b8e..c1edb24 100644 --- a/ogl_editor/src/macosx/delegate.m +++ b/ogl_editor/src/macosx/delegate.m @@ -5,7 +5,7 @@ void Window_populateRecentList(char** files); -@implementation MinimalAppAppDelegate +@implementation RocketAppDelegate @synthesize window; @synthesize button; @@ -14,6 +14,9 @@ void Window_populateRecentList(char** files); - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { + if (!Editor_needsSave()) + return NSTerminateNow; + int ret = NSRunAlertPanel(@"Save before exit?", @"Do you want save the work?", @"Yes", @"Cancel", @"No"); if (ret == NSAlertDefaultReturn) @@ -38,16 +41,20 @@ void Window_populateRecentList(char** files); NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults]; + for (int i = 0; i < 4; ++i) + recent_list[i][0] = 0; + if (prefs) { NSArray* stringArray = [prefs objectForKey:@"recentFiles"]; + int recentIndex = 0; for (int i = 0; i < 4; ++i) { NSString* name = [stringArray objectAtIndex:i]; const char* filename = [name cStringUsingEncoding:NSUTF8StringEncoding]; - if (filename) - strcpy(recent_list[i], filename); + if (filename && filename[0] != 0) + strcpy(recent_list[recentIndex++], filename); } } diff --git a/ogl_editor/src/windows/RocketWindow.c b/ogl_editor/src/windows/RocketWindow.c index 992de48..8936519 100644 --- a/ogl_editor/src/windows/RocketWindow.c +++ b/ogl_editor/src/windows/RocketWindow.c @@ -175,6 +175,9 @@ static int onKeyDown(WPARAM wParam, LPARAM lParam) { int key = -1; + int foo = (int)(lParam >> 16); + (void)foo; + switch (wParam) { case VK_LEFT : key = EMGUI_ARROW_LEFT; break; @@ -185,7 +188,11 @@ static int onKeyDown(WPARAM wParam, LPARAM lParam) default: { + int p, t = (int)wParam; + (void)t; wParam = MapVirtualKey((UINT)wParam, 2) & 0x0000ffff; + p = wParam; + (void)p; wParam = (WPARAM) CharUpperA((LPSTR)wParam); if((wParam >= 32 && wParam <= 126) || @@ -267,7 +274,7 @@ LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam } case WM_KEYDOWN: - case WM_SYSKEYDOWN: + //case WM_SYSKEYDOWN: { int key = onKeyDown(wParam, lParam); @@ -288,7 +295,7 @@ LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam { case ID_FILE_OPEN: { - Editor_menuEvent(EDITOR_MENU_OPEN); + //Editor_menuEvent(EDITOR_MENU_OPEN); Editor_update(); break; } diff --git a/tundra.lua b/tundra.lua index 55e46f1..b1140f0 100644 --- a/tundra.lua +++ b/tundra.lua @@ -6,7 +6,7 @@ local macosx = { "-Wno-deprecated-declarations", -- TickCount issue no Mountain Lion (needs to be fixed) "-I.", "-DMACOSX", "-Wall", { "-O0", "-g"; Config = "*-*-debug" }, - { "-O4"; Config = "*-*-release" }, + { "-O3"; Config = "*-*-release" }, }, }, diff --git a/units.lua b/units.lua index 0d4d5f4..7d89bf6 100644 --- a/units.lua +++ b/units.lua @@ -108,7 +108,7 @@ Program { Libs = { { "wsock32.lib", "opengl32.lib", "glu32.lib", "kernel32.lib", "user32.lib", "gdi32.lib", "Comdlg32.lib" ; Config = "win32-*-*" } }, - Frameworks = { "Cocoa", "OpenGL" }, + Frameworks = { "Cocoa", "OpenGL", "Carbon" }, }