/* Copyright (c) 2021 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __UIPopUpMenu_H__ #define __UIPopUpMenu_H__ typedef struct UIPopUpMenu UIPopUpMenu; #define UIPopUpMenu_superclass UIElement #include "shell/Shell.h" #include "uitoolkit/UIElement.h" #include "uitoolkit/UIMenuBar.h" #include "uitoolkit/UITextListView.h" #include typedef void (* UIPopUpMenuActionCallback)(UIPopUpMenu * popUpMenu, unsigned int itemIndex, int itemIdentifier, unsigned int modifiers, double referenceTime, void * context); #define POP_UP_MENU_OPEN_HIT_TEST_PRIORITY 1000 #define UIPopUpMenu_ivars \ UIElement_ivars \ \ UIPopUpMenuActionCallback callback; \ void * callbackContext; \ unsigned int itemCount; \ struct UIPopUpMenu_itemPrivate * items; \ float width; \ float itemMaxWidth; \ float rowHeight; \ float closedHeight; \ bool enabled; \ UIOverflowMode overflowMode; \ unsigned int selectedItemIndex; \ unsigned int highlightedItemIndex; \ unsigned int keyboardItemIndex; \ UIElement * lastFocusedElement; \ bool rollover; \ bool open; \ bool showKeyboardHighlight; \ double openTime; \ unsigned int openCenterIndex; \ unsigned int openItemCountMaxAbove; \ unsigned int openItemCountMaxBelow; \ ShellTimer scrollTimer; \ bool scrollingFast; \ bool useLocalizedKeyShortcuts; #define UIPopUpMenu_vtable(self_type) \ UIElement_vtable(self_type) \ \ void (* setItems)(self_type * self, unsigned int itemCount, UITextListView_item * items); \ bool (* setSelectedItemIdentifier)(self_type * self, int identifier); \ int (* getSelectedItemIdentifier)(self_type * self); \ Rect4f (* getItemBounds)(self_type * self, unsigned int itemIndex); \ void (* open)(self_type * self, double referenceTime); \ void (* close)(self_type * self); stemobject_declare(UIPopUpMenu) // Does not take ownership of items UIPopUpMenu * UIPopUpMenu_create(unsigned int itemCount, UITextListView_item * items, Vector2f position, Vector2f relativeOrigin, float width, UIOverflowMode overflowMode, UIPopUpMenuActionCallback callback, void * callbackContext, UIAppearance appearance); UIPopUpMenu * UIPopUpMenu_createWithMenuItems(unsigned int itemCount, UIMenuItem * items, Vector2f position, Vector2f relativeOrigin, float width, UIOverflowMode overflowMode, UIPopUpMenuActionCallback callback, void * callbackContext, UIAppearance appearance); bool UIPopUpMenu_init(UIPopUpMenu * self, unsigned int itemCount, UITextListView_item * items, Vector2f position, Vector2f relativeOrigin, float width, UIOverflowMode overflowMode, UIPopUpMenuActionCallback callback, void * callbackContext, UIAppearance appearance); bool UIPopUpMenu_initWithMenuItems(UIPopUpMenu * self, unsigned int itemCount, UIMenuItem * items, Vector2f position, Vector2f relativeOrigin, float width, UIOverflowMode overflowMode, UIPopUpMenuActionCallback callback, void * callbackContext, UIAppearance appearance); void UIPopUpMenu_dispose(UIPopUpMenu * self); bool UIPopUpMenu_hitTest(UIPopUpMenu * self, float x, float y, UIHitTestType type, int * outPriority, bool * outForwardNext); UIEventResponse UIPopUpMenu_mouseDown(UIPopUpMenu * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, bool isFinalTarget, double referenceTime); bool UIPopUpMenu_mouseUp(UIPopUpMenu * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, double referenceTime); bool UIPopUpMenu_mouseMoved(UIPopUpMenu * self, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); bool UIPopUpMenu_mouseDragged(UIPopUpMenu * self, unsigned int buttonMask, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); bool UIPopUpMenu_mouseLeave(UIPopUpMenu * self, unsigned int modifiers, double referenceTime); UIEventResponse UIPopUpMenu_scrollWheel(UIPopUpMenu * self, float x, float y, int scrollDeltaX, int scrollDeltaY, unsigned int buttonMask, unsigned int modifiers, bool isFinalTarget, double referenceTime); UIEventResponse UIPopUpMenu_keyDown(UIPopUpMenu * self, unsigned int charCode, unsigned int keyCode, unsigned int modifiers, bool isRepeat, bool isFinalTarget, double referenceTime); bool UIPopUpMenu_menuActionDown(UIPopUpMenu * self, unsigned int actionNumber, bool isRepeat, double referenceTime); bool UIPopUpMenu_menuActionUp(UIPopUpMenu * self, unsigned int actionNumber, double referenceTime); bool UIPopUpMenu_menuDirectionDown(UIPopUpMenu * self, UINavigationDirection direction, bool isRepeat, double referenceTime); bool UIPopUpMenu_acceptsFocus(UIPopUpMenu * self, bool finalTargetOnly); bool UIPopUpMenu_ignoreClipForHitTest(UIPopUpMenu * self, UIHitTestType type); Rect4f UIPopUpMenu_getBounds(UIPopUpMenu * self); void UIPopUpMenu_draw(UIPopUpMenu * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIPopUpMenu_listRenderables(UIPopUpMenu * self, RenderableIO * renderableIO, int drawOrderOffset, Rect4i clipBounds); void UIPopUpMenu_setItems(UIPopUpMenu * self, unsigned int itemCount, UITextListView_item * items); void UIPopUpMenu_setMenuItems(UIPopUpMenu * self, unsigned int itemCount, UIMenuItem * items); bool UIPopUpMenu_setSelectedItemIdentifier(UIPopUpMenu * self, int identifier); int UIPopUpMenu_getSelectedItemIdentifier(UIPopUpMenu * self); void UIPopUpMenu_open(UIPopUpMenu * self, double referenceTime); void UIPopUpMenu_close(UIPopUpMenu * self); void UIPopUpMenu_refreshAllShortcutStrings(UIPopUpMenu * self); // Only valid while menu is open Rect4f UIPopUpMenu_getItemBounds(UIPopUpMenu * self, unsigned int itemIndex); #endif