-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add menus This commit adds menus to maxGUI
- Loading branch information
1 parent
c0bb810
commit abe0cc4
Showing
12 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024, The maxGUI Contributors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <maxGUI/Menu.hpp> | ||
|
||
#include <utility> | ||
|
||
namespace maxGUI | ||
{ | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
Menu::Menu(HMENU menu_handle) noexcept | ||
: menu_handle_(std::move(menu_handle)) | ||
{} | ||
#endif | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
ParentMenu::ParentMenu(HMENU menu_handle) noexcept | ||
: Menu(std::move(menu_handle)) | ||
, next_submenu_id_(0) | ||
{} | ||
#endif | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
HMENU ParentMenu::Create(HMENU parent_menu, std::string text) noexcept { | ||
HMENU menu_handle = CreateMenu(); | ||
|
||
auto win32_text = Utf8ToWin32String(std::move(text)); | ||
BOOL result = ::AppendMenu(parent_menu, MF_POPUP | MF_STRING, reinterpret_cast<UINT_PTR>(menu_handle), win32_text.text_); | ||
if (result == 0) { | ||
// error | ||
} | ||
|
||
return menu_handle; | ||
} | ||
#endif | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2024, The maxGUI Contributors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef MAXGUI_MENU_HPP | ||
#define MAXGUI_MENU_HPP | ||
|
||
|
||
#include <max/Compiling/Configuration.hpp> | ||
#include <max/Containers/Rectangle.hpp> | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
#ifndef WIN32_LEAN_AND_MEAN | ||
#define WIN32_LEAN_AND_MEAN | ||
#endif | ||
|
||
#include <Windows.h> | ||
#endif | ||
|
||
|
||
namespace maxGUI | ||
{ | ||
|
||
class Menu { | ||
public: | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
explicit Menu(HMENU menu_handle) noexcept; | ||
#endif | ||
|
||
virtual ~Menu() noexcept = default; | ||
|
||
protected: | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
HMENU menu_handle_; | ||
#endif | ||
|
||
}; | ||
|
||
class ParentMenu : public Menu | ||
{ | ||
public: | ||
|
||
explicit ParentMenu(HMENU menu_handle) noexcept; | ||
|
||
~ParentMenu() noexcept override = default; | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
static HMENU Create(HMENU parent_menu, std::string text) noexcept; | ||
#endif | ||
|
||
template<typename T, typename... Params> | ||
T* AppendMenu(Params&&... params) noexcept; | ||
|
||
std::vector<std::unique_ptr<Menu>> submenus_; | ||
|
||
ULONG_PTR next_submenu_id_; | ||
|
||
}; | ||
|
||
class DefaultMenuBehavior { | ||
}; | ||
|
||
template< class Behavior = DefaultMenuBehavior > | ||
class PressableMenu : public Menu | ||
{ | ||
public: | ||
|
||
explicit PressableMenu(HMENU menu_handle) noexcept; | ||
|
||
~PressableMenu() noexcept override = default; | ||
|
||
static HMENU Create(HMENU parent_menu, ULONG_PTR id, std::string text) noexcept; | ||
|
||
}; | ||
|
||
} // namespace maxGUI | ||
|
||
#endif // #if defined(MAX_PLATFORM_WINDOWS) | ||
|
||
#include <maxGUI/Menu.inl> | ||
|
||
#endif // #ifndef MAXGUI_MENU_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024, The maxGUI Contributors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <utility> | ||
|
||
#if defined(MAX_PLATFORM_WINDOWS) | ||
|
||
#include <maxGUI/Win32String.hpp> | ||
|
||
namespace maxGUI | ||
{ | ||
|
||
template<typename T, typename... Params> | ||
T* ParentMenu::AppendMenu(Params&&... params) noexcept { | ||
#if defined(MAX_PLATFORM_WINDOWS) | ||
HMENU menu_handle = T::Create(menu_handle_, next_submenu_id_, std::forward<Params>(params)...); | ||
auto menu_ptr = std::make_unique<T>(menu_handle); | ||
|
||
next_submenu_id_++; | ||
|
||
T* raw_menu_ptr = menu_ptr.get(); | ||
submenus_.push_back(std::move(menu_ptr)); | ||
#endif | ||
return raw_menu_ptr; | ||
} | ||
|
||
template< class Behavior > | ||
PressableMenu< Behavior >::PressableMenu(HMENU menu_handle) noexcept | ||
: Menu(std::move(menu_handle)) | ||
{} | ||
|
||
template< class Behavior > | ||
HMENU PressableMenu< Behavior >::Create(HMENU parent_menu, ULONG_PTR id, std::string text) noexcept { | ||
HMENU submenu_handle = CreatePopupMenu(); | ||
|
||
auto win32_text = Utf8ToWin32String(std::move(text)); | ||
BOOL result = ::AppendMenu(parent_menu, MF_STRING, reinterpret_cast<UINT_PTR>(submenu_handle), win32_text.text_); | ||
if (result == 0) { | ||
// error | ||
} | ||
|
||
MENUITEMINFO menu_item_info = { 0 }; | ||
menu_item_info.cbSize = sizeof(menu_item_info); | ||
//menu_item_info.fMask = MIIM_DATA | MIIM_STRING | MIIM_ID;// | MIIM_TYPE; | ||
//menu_item_info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID; | ||
menu_item_info.fMask = MIIM_DATA | MIIM_TYPE;// | MIIM_ID; | ||
menu_item_info.fType = MFT_STRING; | ||
menu_item_info.dwTypeData = win32_text.text_; | ||
menu_item_info.cch = win32_text.char_count_; | ||
menu_item_info.dwItemData = reinterpret_cast<ULONG_PTR>(&Behavior::OnPressed); | ||
|
||
result = SetMenuItemInfo(parent_menu, id, TRUE, &menu_item_info); | ||
if (result == 0) { | ||
// error | ||
} | ||
|
||
return submenu_handle; | ||
} | ||
|
||
} // namespace maxGUI | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.