/* Copyright (c) 2023 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 */ #include "uitoolkit/UIToolkitAppearance.h" #include "uitoolkit/UIToolkitDrawing.h" #include "uitoolkit/UITooltipRoot.h" #define stemobject_implementation UITooltipRoot stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(hitTestList); stemobject_vtable_entry(mouseMoved); stemobject_vtable_entry(listRenderables); stemobject_vtable_end(); UITooltipRoot * UITooltipRoot_create(UIAppearance appearance) { stemobject_create_implementation(init, appearance) } bool UITooltipRoot_init(UITooltipRoot * self, UIAppearance appearance) { call_super(init, self, VECTOR2f_ZERO, UICONTAINER_NO_CENTER, UICONTAINER_SIZE_AUTO, false, appearance); call_virtual(addElement, self, self->tooltipView = UITooltipView_create(STR_NULL, VECTOR2f_ZERO, VECTOR2f(getAppearanceFloat(appearance, UIToolkit_tooltipWidthMax), 0.0f), VECTOR2f(0.0f, 0.5f), ALIGN_LEFT, WRAP_DEFAULT, OVERFLOW_RESIZE, OVERFLOW_RESIZE, UIAppearance_init(&self->appearance)), true); self->tooltipView->visible = false; self->activeTooltip = UITooltip_none; self->timerID = SHELL_TIMER_INVALID; return true; } void UITooltipRoot_dispose(UITooltipRoot * self) { UIAppearance_dispose(self->tooltipView->appearance); Shell_cancelTimer(self->timerID); call_super_virtual(dispose, self); } static void tooltipTimerCallback(ShellTimer timerID, void * context) { UITooltipRoot * self = context; call_virtual(setText, self->tooltipView, self->activeTooltip.text); UIToolkit_getBestInvokerAttachPoint(self->activeTooltip.invokerBounds, Rect4f_getSize(call_virtual(getBounds, self->tooltipView)), self->activeTooltip.sidePreference, 0.0f, getAppearanceFloat(self->appearance, UIToolkit_tooltipOffset) + getAppearanceFloat(self->appearance, UITooltipView_frameMargin), getAppearanceRect4f(self->appearance, UIToolkit_safeDisplayBounds), NULL, &self->tooltipView->position, &self->tooltipView->relativeOrigin); self->tooltipView->visible = true; self->timerID = SHELL_TIMER_INVALID; Shell_redisplay(); } void UITooltipRoot_hitTestList(UITooltipRoot * self, float x, float y, UIHitTestType type, int priorityOffset, UIHitTestResultIO * resultIO) { } bool UITooltipRoot_mouseMoved(UITooltipRoot * self, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime) { UIElement * mouseoverElement = UIElement_hitTestSingle(self->parent, x, y, HIT_TEST_MOUSE_OVER); UITooltip tooltip = UITooltip_none; if (mouseoverElement != NULL) { tooltip = call_virtual(getTooltipAtPosition, mouseoverElement, x, y); } if (tooltip.invoker != self->activeTooltip.invoker || tooltip.identifier != self->activeTooltip.identifier) { Shell_cancelTimer(self->timerID); self->timerID = SHELL_TIMER_INVALID; self->activeTooltip = tooltip; self->tooltipView->visible = false; if (tooltip.invoker != NULL && tooltip.text.length > 0) { self->timerID = Shell_setTimer(getAppearanceDouble(self->appearance, UIToolkit_tooltipDelay), false, tooltipTimerCallback, self); } return true; } return false; } void UITooltipRoot_listRenderables(UITooltipRoot * self, RenderableIO * renderableIO, int drawOrderOffset, Rect4i clipBounds) { call_super_virtual(listRenderables, self, renderableIO, drawOrderOffset + TOOLTIP_DRAW_PRIORITY, clipBounds); }