/* Copyright (c) 2018 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 __UIButton_H__ #define __UIButton_H__ #ifdef __cplusplus extern "C" { #endif typedef struct UIButton UIButton; #define UIButton_superclass UIElement #include "font/String.h" #include "shell/Shell.h" #include "uitoolkit/UIAppearance.h" #include "uitoolkit/UIElement.h" typedef void (* UIButtonActionCallback)(UIButton * button, unsigned int modifiers, double referenceTime, void * context); #define UIButton_ivars \ UIElement_ivars \ \ String text; \ float width; \ float minWidth; \ UIOverflowMode overflowMode; \ UIButtonActionCallback actionCallback; \ void * actionCallbackContext; \ bool enabled; \ \ bool rollover; \ bool clickInProgress; \ bool down; \ bool invokeActionAfterAnimation; \ unsigned int actionModifiers; \ ShellTimer animationTimer; #define UIButton_vtable(self_type) \ UIElement_vtable(self_type) \ \ void (* invokeAction)(self_type * self, unsigned int modifiers, double referenceTime); stemobject_declare(UIButton) // text is copied // If overflowMode is OVERFLOW_RESIZE, width is treated as a minimum UIButton * UIButton_create(String text, Vector2f position, Vector2f relativeOrigin, float width, UIOverflowMode overflowMode, UIButtonActionCallback actionCallback, void * actionCallbackContext, UIAppearance appearance); bool UIButton_init(UIButton * self, String text, Vector2f position, Vector2f relativeOrigin, float width, UIOverflowMode overflowMode, UIButtonActionCallback actionCallback, void * actionCallbackContext, UIAppearance appearance); void UIButton_dispose(UIButton * self); // text is copied void UIButton_setText(UIButton * self, String text); void UIButton_simulateClick(UIButton * self, unsigned int modifiers); UIEventResponse UIButton_mouseDown(UIButton * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, bool isFinalTarget, double referenceTime); bool UIButton_mouseUp(UIButton * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, double referenceTime); bool UIButton_mouseMoved(UIButton * self, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); bool UIButton_mouseDragged(UIButton * self, unsigned int buttonMask, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); bool UIButton_menuActionDown(UIButton * self, unsigned int actionNumber, bool isRepeat, double referenceTime); bool UIButton_acceptsFocus(UIButton * self); Rect4f UIButton_getBounds(UIButton * self); void UIButton_draw(UIButton * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); UITooltip UIButton_getTooltipAtPosition(UIButton * self, float x, float y); void UIButton_invokeAction(UIButton * self, unsigned int modifiers, double referenceTime); #ifdef __cplusplus } #endif #endif