From 69be9dbb91c0efa9a6e7faa5aac9e38c38d24952 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sat, 6 Mar 2021 01:20:30 -0800 Subject: [PATCH] Sort of got menus working (not great design though) --- src/include/Globals.h | 2 ++ src/source/DataModel/GuiRootInstance.cpp | 2 ++ src/source/Globals.cpp | 1 + src/source/Listener/MenuButtonListener.cpp | 12 ++++++++++++ src/source/main.cpp | 2 +- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/include/Globals.h b/src/include/Globals.h index 9b6c960..d8280c5 100644 --- a/src/include/Globals.h +++ b/src/include/Globals.h @@ -21,6 +21,7 @@ public: static int surfaceId; static const std::string g_PlaceholderName; static COLORREF g_acrCustClr[16]; //Will be dynamic later + static HWND mainHwnd; }; extern std::vector postRenderStack; @@ -36,4 +37,5 @@ extern COLORREF g_acrCustClr[16]; //Will be dynamic later extern std::string cameraSound; extern std::string clickSound; extern std::string dingSound; +extern HWND mainHwnd; const std::string g_PlaceholderName = "Dygysphere"; \ No newline at end of file diff --git a/src/source/DataModel/GuiRootInstance.cpp b/src/source/DataModel/GuiRootInstance.cpp index bec5a1f..b1aa15e 100644 --- a/src/source/DataModel/GuiRootInstance.cpp +++ b/src/source/DataModel/GuiRootInstance.cpp @@ -136,6 +136,8 @@ GuiRootInstance::GuiRootInstance() : _message(""), _messageTime(0) button->fontLocationRelativeTo = Vector2(10, 0); button->setAllColorsSame(); button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F); + button->name = "file"; + button->setButtonListener(new MenuButtonListener()); button = makeTextButton(); button->boxBegin = Vector2(125, 0); diff --git a/src/source/Globals.cpp b/src/source/Globals.cpp index a1aec05..7243f05 100644 --- a/src/source/Globals.cpp +++ b/src/source/Globals.cpp @@ -19,6 +19,7 @@ POINT Globals::mousepoint; GFontRef g_fntdominant = NULL; GFontRef g_fntlighttrek = NULL; +HWND Globals::mainHwnd = NULL; Globals::Globals(void){} diff --git a/src/source/Listener/MenuButtonListener.cpp b/src/source/Listener/MenuButtonListener.cpp index fe585d3..c2298ee 100644 --- a/src/source/Listener/MenuButtonListener.cpp +++ b/src/source/Listener/MenuButtonListener.cpp @@ -1,5 +1,6 @@ #include "Listener/MenuButtonListener.h" #include "DataModel/ToggleImageButtonInstance.h" +#include "Application.h" #include "Globals.h" void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button) { @@ -8,4 +9,15 @@ void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button) g_dataModel->toggleRun(); ((ToggleImageButtonInstance*)button)->checked = g_dataModel->isRunning(); } + else if(button->name == "file") + { + HMENU mainmenu = CreatePopupMenu(); + AppendMenu(mainmenu, MF_STRING, 100, "New"); + AppendMenu(mainmenu, MF_STRING, 101, "Open..."); + AppendMenu(mainmenu, MF_STRING, 101, "Close"); + AppendMenu(mainmenu, MF_SEPARATOR, 0, NULL); + POINT p; + GetCursorPos(&p); + TrackPopupMenu(mainmenu, TPM_LEFTBUTTON, p.x, p.y, 0, Globals::mainHwnd, 0); + } } \ No newline at end of file diff --git a/src/source/main.cpp b/src/source/main.cpp index 35cb162..834a516 100644 --- a/src/source/main.cpp +++ b/src/source/main.cpp @@ -209,7 +209,7 @@ int main(int argc, char** argv) { } SendMessage(hwndMain, WM_SETICON, ICON_BIG,(LPARAM)LoadImage(GetModuleHandle(NULL), (LPCSTR)MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE)); - + Globals::mainHwnd = hwndMain; Application app = Application(hwndMain); app.run(); }