/* Copyright (c) 2020 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 __UISlider_H__ #define __UISlider_H__ #ifdef __cplusplus extern "C" { #endif typedef struct UISlider UISlider; #define UISlider_superclass UIElement #include "gamemath/MoveInput.h" #include "uitoolkit/UIElement.h" typedef void (* UISliderCallback)(UISlider * slider, float value, unsigned int modifiers, double referenceTime, void * context); typedef unsigned int UISlider_options; #define SLIDER_OPTION_HORIZONTAL 0x0 #define SLIDER_OPTION_VERTICAL 0x1 #define SLIDER_OPTION_SNAP_TO_INTEGER 0x2 #define SLIDER_OPTION_ALLOW_UNCLAMPED_DRAG 0x4 #define SLIDER_OPTION_ALLOW_PRECISE_DRAG 0x8 #define SLIDER_OPTION_RESET_ON_CONTROL_CLICK 0x10 #define UISlider_ivars \ UIElement_ivars \ \ float minValue; \ float maxValue; \ float defaultValue; \ float value; \ UISlider_options options; \ float secondsToSlideFromMinToMaxAtFullSpeed; \ float secondsToAccelerateToFullSpeed; \ float preciseDragMultiplier; \ unsigned int pixelLength; \ unsigned int lastModifiers; \ UISliderCallback changeCallback; \ UISliderCallback changeCompleteCallback; \ void * callbackContext; \ \ bool protected_ivar(rollover); \ bool protected_ivar(dragInProgress); \ bool protected_ivar(menuActionDown); \ bool protected_ivar(focusLocked); \ bool protected_ivar(changesMadeByMenuDirection); \ bool protected_ivar(menuDirectionRangeClamped); \ Vector2f protected_ivar(dragOffset); \ Vector2f protected_ivar(lastDragPosition); \ MoveInputState protected_ivar(moveInput); \ float protected_ivar(moveVelocity); #define UISlider_vtable(self_type) \ UIElement_vtable(self_type) \ \ void (* setValue)(self_type * self, float value); \ float (* getRelativeValue)(self_type * self); \ void (* setRelativeValue)(self_type * self, float relativeValue); \ void (* setRange)(self_type * self, float minValue, float maxValue); \ Vector2f (* getTrackSize)(self_type * self); \ Vector2f (* getHandleSize)(self_type * self); \ Rect4f (* getTrackBounds)(self_type * self); \ Rect4f (* getHandleBounds)(self_type * self, bool rounded, bool clamped); \ void (* drawTrack)(self_type * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); \ void (* drawHandle)(self_type * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); stemobject_declare(UISlider) UISlider * UISlider_create(float minValue, float maxValue, float initialValue, Vector2f position, Vector2f relativeOrigin, UISlider_options options, unsigned int pixelLength, UISliderCallback changeCallback, UISliderCallback changeCompleteCallback, void * callbackContext, UIAppearance appearance); bool UISlider_init(UISlider * self, float minValue, float maxValue, float initialValue, Vector2f position, Vector2f relativeOrigin, UISlider_options options, unsigned int pixelLength, UISliderCallback changeCallback, UISliderCallback changeCompleteCallback, void * callbackContext, UIAppearance appearance); void UISlider_dispose(UISlider * self); void UISlider_setValue(UISlider * self, float value); // Range: 0.0f for min, 1.0f for max float UISlider_getRelativeValue(UISlider * self); void UISlider_setRelativeValue(UISlider * self, float relativeValue); void UISlider_setRange(UISlider * self, float minValue, float maxValue); bool UISlider_hitTest(UISlider * self, float x, float y, UIHitTestType type, int * outPriority, bool * outForwardNext); UIEventResponse UISlider_mouseDown(UISlider * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, bool isFinalTarget, double referenceTime); bool UISlider_mouseUp(UISlider * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, double referenceTime); bool UISlider_mouseMoved(UISlider * self, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); bool UISlider_mouseDragged(UISlider * self, unsigned int buttonMask, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime); UIEventResponse UISlider_scrollWheel(UISlider * self, float x, float y, int deltaX, int deltaY, unsigned int modifiers, bool isFinalTarget, double referenceTime); bool UISlider_keyModifiersChanged(UISlider * self, unsigned int modifiers, unsigned int lastModifiers, double referenceTime); bool UISlider_menuActionDown(UISlider * self, unsigned int actionNumber, bool isRepeat, double referenceTime); bool UISlider_menuActionUp(UISlider * self, unsigned int actionNumber, double referenceTime); bool UISlider_menuDirectionDown(UISlider * self, UINavigationDirection direction, bool isRepeat, double referenceTime); bool UISlider_menuDirectionUp(UISlider * self, UINavigationDirection direction, double referenceTime); bool UISlider_setFocusedElement(UISlider * self, compat_type(UIElement *) element, compat_type(UIElement *) fromElement, UINavigationDirection directionFromElement); bool UISlider_acceptsFocus(UISlider * self); Rect4f UISlider_getBounds(UISlider * self); Rect4f UISlider_getFocusBounds(UISlider * self); Vector2f UISlider_getTrackSize(UISlider * self); Vector2f UISlider_getHandleSize(UISlider * self); Rect4f UISlider_getTrackBounds(UISlider * self); Rect4f UISlider_getHandleBounds(UISlider * self, bool rounded, bool clamped); void UISlider_draw(UISlider * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); bool UISlider_needsRedraw(UISlider * self); void UISlider_drawTrack(UISlider * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UISlider_drawHandle(UISlider * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); #ifdef __cplusplus } #endif #endif