/* 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 */ #include "gamemath/Scalar.h" #include "shell/ShellKeyCodes.h" #include "uitoolkit/UIWindowView.h" #include "uitoolkit/UIToolkitAppearance.h" #include "uitoolkit/UIToolkitContext.h" #include "uitoolkit/UIToolkitCursor.h" #include "uitoolkit/UIToolkitDrawing.h" #define stemobject_implementation UIWindowView stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(hitTest); stemobject_vtable_entry(hitTestList); stemobject_vtable_entry(mouseDown); stemobject_vtable_entry(mouseUp); stemobject_vtable_entry(mouseDragged); stemobject_vtable_entry(scrollWheel); stemobject_vtable_entry(keyDown); stemobject_vtable_entry(getFocusedElement); stemobject_vtable_entry(acceptsFocus); stemobject_vtable_entry(getBounds); stemobject_vtable_entry(getClipBounds); stemobject_vtable_entry(draw); stemobject_vtable_entry(listRenderables); stemobject_vtable_entry(getCursorAtPosition); stemobject_vtable_entry(showWindow); stemobject_vtable_entry(hideWindow); stemobject_vtable_entry(bringToFront); stemobject_vtable_entry(isModal); stemobject_vtable_entry(clampPositionToMaxDragBounds); stemobject_vtable_entry(setTitle); stemobject_vtable_entry(adjustUIBounds); stemobject_vtable_entry(getContentAreaBounds); stemobject_vtable_end(); UIWindowView * UIWindowView_create(Vector2f position, Vector2f relativeOrigin, Vector2f size, String title, UIWindowView_callback closeCallback, UIWindowView_resizeCallback resizeCallback, void * callbackContext, UIWindowRoot * windowRoot, UIAppearance appearance) { stemobject_create_implementation(init, position, relativeOrigin, size, title, closeCallback, resizeCallback, callbackContext, windowRoot, appearance) } static void closeButtonCallback(UIButton * button, unsigned int modifiers, double referenceTime, void * context) { UIWindowView * self = context; self->closeCallback(self, self->callbackContext); } static void updateCloseButtonPosition(UIWindowView * self) { float dragAreaHeight = getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); self->closeButton->position.x = roundpositivef(self->size.x - (dragAreaHeight - self->closeButton->upAtlasEntry.size.y) / 2); self->closeButton->position.y = roundpositivef(self->size.y + (dragAreaHeight - self->closeButton->upAtlasEntry.size.y) / 2); } bool UIWindowView_init(UIWindowView * self, Vector2f position, Vector2f relativeOrigin, Vector2f size, String title, UIWindowView_callback closeCallback, UIWindowView_resizeCallback resizeCallback, void * callbackContext, UIWindowRoot * windowRoot, UIAppearance appearance) { call_super(init, self, position, relativeOrigin, size, false, appearance); self->title = String_copy(title); self->closeCallback = closeCallback; self->resizeCallback = resizeCallback; self->callbackContext = callbackContext; self->windowRoot = windowRoot; self->titleColorTop = getAppearanceColor4f(appearance, UIWindowView_titleColorTop); self->titleColorBottom = getAppearanceColor4f(appearance, UIWindowView_titleColorBottom); self->titleTextColor = getAppearanceColor4f(appearance, UIWindowView_titleTextColor); self->backgroundColor = getAppearanceColor4f(self->appearance, UIWindowView_backgroundColor); self->renderable = createUIElementRenderableWithDefaultSettings(self, PRIMITIVE_TRIANGLES); self->draggingView = false; self->resizingView = false; self->firstDraw = true; self->visible = false; self->closeButton = NULL; self->protected_ivar(hitTestPriority) = WINDOW_HIT_TEST_PRIORITY; self->lastUnadjustedPosition = position; self->lastUIBounds = getAppearanceRect4f(self->appearance, UIToolkit_safeDisplayBounds); if (closeCallback != NULL) { UIAtlasEntry closeUpAtlasEntry = getAppearanceAtlasEntry(self->appearance, UIWindowView_windowCloseUp); UIAtlasEntry closeDownAtlasEntry = getAppearanceAtlasEntry(self->appearance, UIWindowView_windowCloseDown); UIAtlasEntry closeRolloverAtlasEntry = getAppearanceAtlasEntry(self->appearance, UIWindowView_windowCloseRollover); call_super(addElement, self, self->closeButton = UIGraphicalButton_create(closeUpAtlasEntry, closeDownAtlasEntry, closeRolloverAtlasEntry, VECTOR2f_ZERO, VECTOR2f(1.0f, 0.0f), closeButtonCallback, self, UIAppearance_init(&self->appearance)), true); updateCloseButtonPosition(self); } return true; } void UIWindowView_dispose(UIWindowView * self) { String_free(self->title); if (self->closeButton != NULL) { UIAppearance_dispose(self->closeButton->appearance); } call_super_virtual(dispose, self); } static Vector2i getResizeDirection(UIWindowView * self, float x, float y, Rect4f bounds) { float resizeAreaOutset = getAppearanceFloat(self->appearance, UIWindowView_resizeAreaOutset); float resizeAreaInset = getAppearanceFloat(self->appearance, UIWindowView_resizeAreaInset); Rect4f outerBounds = Rect4f_inset(bounds, VECTOR2f(-resizeAreaOutset, -resizeAreaOutset)); Rect4f innerBounds = Rect4f_inset(bounds, VECTOR2f(resizeAreaInset, resizeAreaInset)); Vector2i result = VECTOR2i(0, 0); if (y >= outerBounds.yMin && y < outerBounds.yMax) { if (x < innerBounds.xMin && x >= outerBounds.xMin) { result.x = -1; } else if (x > innerBounds.xMax && x <= outerBounds.xMax) { result.x = 1; } } if (x >= outerBounds.xMin && x < outerBounds.xMax) { if (y < innerBounds.yMin && y >= outerBounds.yMin) { result.y = -1; } else if (y > innerBounds.yMax && y <= outerBounds.yMax) { result.y = 1; } } return result; } bool UIWindowView_hitTest(UIWindowView * self, float x, float y, UIHitTestType type, int * outPriority, bool * outForwardNext) { if (!self->visible) { return false; } Rect4f bounds = call_virtual(getBounds, self); unsigned int windowIndex = UIWindowRoot_getWindowIndex(self->windowRoot, self); if (windowIndex == self->windowRoot->windowCount - 1) { if (self->resizeCallback != NULL && (type == HIT_TEST_MOUSE_DOWN || type == HIT_TEST_MOUSE_OVER)) { float resizeAreaOutset = getAppearanceFloat(self->appearance, UIWindowView_resizeAreaOutset); Rect4f resizeBoundsMin = Rect4f_inset(bounds, VECTOR2f(resizeAreaOutset, resizeAreaOutset)); Rect4f resizeBoundsMax = Rect4f_inset(bounds, VECTOR2f(-resizeAreaOutset, -resizeAreaOutset)); if (Rect4f_containsVector2f(resizeBoundsMax, VECTOR2f(x, y)) && !Rect4f_containsVector2f(resizeBoundsMin, VECTOR2f(x, y))) { *outPriority = self->protected_ivar(hitTestPriority) + WINDOW_RESIZE_AREA_HIT_TEST_PRIORITY + windowIndex * WINDOW_HIT_TEST_PRIORITY_DELTA; return true; } } if (call_super_virtual(hitTest, self, x, y, type, outPriority, outForwardNext)) { *outPriority += self->protected_ivar(hitTestPriority) + windowIndex * WINDOW_HIT_TEST_PRIORITY_DELTA; // This looks somewhat suspect. Added to fix a big where UIElement_hitTestSingle() would ignore the front window if // forwardNext was set to true by the hit tested element (such as UIScrollContainer). Maybe this is correct for all cases? *outForwardNext = false; return true; } if (type == HIT_TEST_KEY_DOWN) { *outPriority = -1; return true; } } if (type != HIT_TEST_KEY_DOWN) { if (self->resizeCallback != NULL && (type == HIT_TEST_MOUSE_DOWN || type == HIT_TEST_MOUSE_OVER)) { float resizeAreaOutset = getAppearanceFloat(self->appearance, UIWindowView_resizeAreaOutset); bounds = Rect4f_inset(bounds, VECTOR2f(-resizeAreaOutset, -resizeAreaOutset)); } if (Rect4f_containsVector2f(bounds, VECTOR2f(x, y))) { *outPriority = self->protected_ivar(hitTestPriority) + windowIndex * WINDOW_HIT_TEST_PRIORITY_DELTA; return true; } if (UIElement_isInFocusChain(self)) { *outPriority = WINDOW_UNFOCUS_HIT_TEST_PRIORITY; *outForwardNext = true; return true; } } return false; } void UIWindowView_hitTestList(UIWindowView * self, float x, float y, UIHitTestType type, int priorityOffset, UIHitTestResultIO * resultIO) { unsigned int windowIndex = UIWindowRoot_getWindowIndex(self->windowRoot, self); call_super(hitTestList, self, x, y, type, priorityOffset + self->protected_ivar(hitTestPriority) + windowIndex * WINDOW_HIT_TEST_PRIORITY_DELTA, resultIO); int priority = 0; bool forwardNext = false; if (call_virtual(hitTest, self, x, y, type, &priority, &forwardNext)) { if (type == HIT_TEST_MOUSE_DOWN && (!UIWindowRoot_isFrontWindow(self->windowRoot, self) || !UIElement_isInFocusChain(self)) && UIWindowRoot_hitTestWindow(self->windowRoot, x, y) == self) { call_virtual(addResult, resultIO, self, priorityOffset + priority + 1, true); } call_virtual(addResult, resultIO, self, priorityOffset + priority - 1, forwardNext); } } UIEventResponse UIWindowView_mouseDown(UIWindowView * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, bool isFinalTarget, double referenceTime) { bool isFrontWindow = UIWindowRoot_isFrontWindow(self->windowRoot, self); if (!isFrontWindow || !UIElement_isInFocusChain(self)) { call_virtual(bringToFront, self); call_virtual(setFocusedElement, UIElement_getTopParent(self), self, NULL, UI_NONE); return RESPONSE_HANDLED_FORWARD_NEXT; } Rect4f bounds = call_virtual(getBounds, self); float dragAreaHeight = getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); if (buttonNumber == 0 && self->resizeCallback != NULL) { self->resizeDirection = getResizeDirection(self, x, y, bounds); if (self->resizeDirection.x != 0 || self->resizeDirection.y != 0) { if (!isFrontWindow) { call_virtual(bringToFront, self); call_virtual(setFocusedElement, UIElement_getTopParent(self), self, NULL, UI_NONE); } self->resizingView = true; self->dragOffset = VECTOR2f(x, y); self->initialResizeBounds = bounds; self->initialResizeBounds.yMax -= dragAreaHeight; return RESPONSE_HANDLED; } } if (isFrontWindow) { UIEventResponse response = call_super_virtual(mouseDown, self, buttonNumber, buttonMask, x, y, modifiers, isFinalTarget, referenceTime); if (response == RESPONSE_HANDLED) { return response; } } if (Rect4f_containsVector2f(bounds, VECTOR2f(x, y))) { call_virtual(bringToFront, self); call_virtual(setFocusedElement, UIElement_getTopParent(self), self, NULL, UI_NONE); Rect4f dragAreaBounds = bounds; dragAreaBounds.yMin = dragAreaBounds.yMax - dragAreaHeight; Rect4f closeButtonBounds = RECT4f_EMPTY; if (self->closeCallback != NULL) { closeButtonBounds = Rect4f_offset(call_virtual(getBounds, self->closeButton), VECTOR2f(bounds.xMin, bounds.yMin)); } if (buttonNumber == 0 && Rect4f_containsVector2f(dragAreaBounds, VECTOR2f(x, y))) { if (Rect4f_containsVector2f(closeButtonBounds, VECTOR2f(x, y))) { return RESPONSE_HANDLED_FORWARD_NEXT; } self->draggingView = true; self->dragOffset = Vector2f_subtract(VECTOR2f(x, y), self->position); } return RESPONSE_HANDLED; } if (UIElement_isFocused(self)) { UIElement_unfocus(self); return RESPONSE_HANDLED_FORWARD_NEXT; } return RESPONSE_UNHANDLED; } bool UIWindowView_mouseUp(UIWindowView * self, unsigned int buttonNumber, unsigned int buttonMask, float x, float y, unsigned int modifiers, double referenceTime) { if (buttonNumber == 0 && (self->draggingView || self->resizingView)) { self->draggingView = self->resizingView = false; return true; } return call_super_virtual(mouseUp, self, buttonNumber, buttonMask, x, y, modifiers, referenceTime); } void UIWindowView_setPosition(UIWindowView * self, Vector2f position) { self->position = self->lastUnadjustedPosition = position; } void UIWindowView_clampPositionToMaxDragBounds(UIWindowView * self) { Rect4f maxDragBounds = UIElement_rootToLocalRect(self, getAppearanceRect4f(self->appearance, UIToolkit_safeDisplayBounds)); if (self->position.x - self->size.x * self->relativeOrigin.x + self->size.x / 2 < maxDragBounds.xMin) { self->position.x = maxDragBounds.xMin - self->size.x / 2 + self->size.x * self->relativeOrigin.x; } else if (self->position.x + self->size.x * (1.0f - self->relativeOrigin.x) - self->size.x / 2 > maxDragBounds.xMax) { self->position.x = maxDragBounds.xMax + self->size.x / 2 - self->size.x * (1.0f - self->relativeOrigin.x); } float dragAreaHeight = getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); if (self->position.y - (self->size.y + dragAreaHeight) * self->relativeOrigin.y + self->size.y < maxDragBounds.yMin) { self->position.y = maxDragBounds.yMin - self->size.y + (self->size.y + dragAreaHeight) * self->relativeOrigin.y; } else if (self->position.y + (self->size.y + dragAreaHeight) * (1.0f - self->relativeOrigin.y) > maxDragBounds.yMax) { self->position.y = maxDragBounds.yMax - (self->size.y + dragAreaHeight) * (1.0f - self->relativeOrigin.y); } } void UIWindowView_setTitle(UIWindowView * self, String title) { String_free(self->title); self->title = String_copy(title); } void UIWindowView_adjustUIBounds(UIWindowView * self, Rect4f oldBounds, Rect4f newBounds) { self->lastUnadjustedPosition.x = newBounds.xMin + (self->lastUnadjustedPosition.x - oldBounds.xMin) * (newBounds.xMax - newBounds.xMin) / (oldBounds.xMax - oldBounds.xMin); self->lastUnadjustedPosition.y = newBounds.yMin + (self->lastUnadjustedPosition.y - oldBounds.yMin) * (newBounds.yMax - newBounds.yMin) / (oldBounds.yMax - oldBounds.yMin); self->position = self->lastUnadjustedPosition; call_virtual(clampPositionToMaxDragBounds, self); } bool UIWindowView_mouseDragged(UIWindowView * self, unsigned int buttonMask, float x, float y, float deltaX, float deltaY, unsigned int modifiers, double referenceTime) { if (self->draggingView) { self->position.x = x - self->dragOffset.x; self->position.y = y - self->dragOffset.y; self->lastUnadjustedPosition = self->position; UIWindowView_clampPositionToMaxDragBounds(self); return true; } if (self->resizingView) { Rect4f bounds = call_virtual(getBounds, self); float dragAreaHeight = getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); Vector2f minimumSize = getAppearanceVector2f(self->appearance, UIWindowView_minimumSize); bounds.yMax -= dragAreaHeight; Rect4f newBounds = bounds; Rect4f maxDragBounds = UIElement_rootToLocalRect(self, getAppearanceRect4f(self->appearance, UIToolkit_safeDisplayBounds)); if (self->resizeDirection.x == -1) { newBounds.xMin = roundpositivef(self->initialResizeBounds.xMin + x - self->dragOffset.x); if (newBounds.xMin < maxDragBounds.xMin) { newBounds.xMin = maxDragBounds.xMin; } if (newBounds.xMin > newBounds.xMax - minimumSize.x) { newBounds.xMin = newBounds.xMax - minimumSize.x; } } else if (self->resizeDirection.x == 1) { newBounds.xMax = roundpositivef(self->initialResizeBounds.xMax + x - self->dragOffset.x); if (newBounds.xMax > maxDragBounds.xMax) { newBounds.xMax = maxDragBounds.xMax; } if (newBounds.xMax < newBounds.xMin + minimumSize.x) { newBounds.xMax = newBounds.xMin + minimumSize.x; } } if (self->resizeDirection.y == -1) { newBounds.yMin = roundpositivef(self->initialResizeBounds.yMin + y - self->dragOffset.y); if (newBounds.yMin < maxDragBounds.yMin) { newBounds.yMin = maxDragBounds.yMin; } if (newBounds.yMin > newBounds.yMax - minimumSize.y) { newBounds.yMin = newBounds.yMax - minimumSize.y; } } else if (self->resizeDirection.y == 1) { newBounds.yMax = roundpositivef(self->initialResizeBounds.yMax + y - self->dragOffset.y); if (newBounds.yMax > maxDragBounds.yMax - dragAreaHeight) { newBounds.yMax = maxDragBounds.yMax - dragAreaHeight; } if (newBounds.yMax < newBounds.yMin + minimumSize.y) { newBounds.yMax = newBounds.yMin + minimumSize.y; } } if (newBounds.xMin != bounds.xMin || newBounds.xMax != bounds.xMax || newBounds.yMin != bounds.yMin || newBounds.yMax != bounds.yMax) { newBounds = self->resizeCallback(self, newBounds, self->resizeDirection, self->callbackContext); self->position.x += (newBounds.xMin + (newBounds.xMax - newBounds.xMin) * self->relativeOrigin.x) - (bounds.xMin + (bounds.xMax - bounds.xMin) * self->relativeOrigin.x); self->position.y += (newBounds.yMin + (newBounds.yMax - newBounds.yMin) * self->relativeOrigin.y) - (bounds.yMin + (bounds.yMax - bounds.yMin) * self->relativeOrigin.y); self->size.x = newBounds.xMax - newBounds.xMin; self->size.y = newBounds.yMax - newBounds.yMin; if (self->closeButton != NULL) { updateCloseButtonPosition(self); } } self->lastUnadjustedPosition = self->position; return true; } return call_super_virtual(mouseDragged, self, buttonMask, x, y, deltaX, deltaY, modifiers, referenceTime); } UIEventResponse UIWindowView_scrollWheel(UIWindowView * self, float x, float y, int deltaX, int deltaY, unsigned int modifiers, bool isFinalTarget, double referenceTime) { Rect4f bounds = call_virtual(getBounds, self); if (Rect4f_containsVector2f(bounds, VECTOR2f(x, y))) { return RESPONSE_HANDLED; } return call_super(scrollWheel, self, x, y, deltaX, deltaY, modifiers, isFinalTarget, referenceTime); } UIEventResponse UIWindowView_keyDown(UIWindowView * self, unsigned int charCode, unsigned int keyCode, unsigned int modifiers, bool isRepeat, bool isFinalTarget, double referenceTime) { if (isFinalTarget && keyCode == KEY_CODE_W && (modifiers & MODIFIER_CONTROL_BIT) && self->closeCallback != NULL) { self->closeCallback(self, self->callbackContext); return RESPONSE_HANDLED; } return call_super_virtual(keyDown, self, charCode, keyCode, modifiers, isRepeat, isFinalTarget, referenceTime); } UIElement * UIWindowView_getFocusedElement(UIWindowView * self) { UIElement * focusedElement = call_super_virtual(getFocusedElement, self); if (focusedElement == NULL) { focusedElement = (UIElement *) self; } return focusedElement; } bool UIWindowView_acceptsFocus(UIWindowView * self) { return true; } Rect4f UIWindowView_getBounds(UIWindowView * self) { Rect4f uiBounds = getAppearanceRect4f(self->appearance, UIToolkit_safeDisplayBounds); if (!Rect4f_isEqual(uiBounds, self->lastUIBounds)) { call_virtual(adjustUIBounds, self, self->lastUIBounds, uiBounds); self->lastUIBounds = uiBounds; } Vector2f size = self->size; size.y += getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); return UIElement_boundsRectWithOrigin(self->position, self->relativeOrigin, size); } Rect4f UIWindowView_getClipBounds(UIWindowView * self) { if (self->clipContents) { return call_virtual(getContentAreaBounds, self); } return RECT4f_EMPTY; } Rect4f UIWindowView_getContentAreaBounds(UIWindowView * self) { Rect4f bounds = call_virtual(getBounds, self); bounds.yMax -= getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); return bounds; } static void clampPositionToInitialBounds(UIWindowView * self) { Rect4f initialBounds = UIElement_rootToLocalRect(self, getAppearanceRect4f(self->appearance, UIToolkit_safeDisplayBounds)); if (self->position.x - self->size.x * self->relativeOrigin.x < initialBounds.xMin) { self->position.x = initialBounds.xMin + self->size.x * self->relativeOrigin.x; } else if (self->position.x + self->size.x * (1.0f - self->relativeOrigin.x) > initialBounds.xMax) { self->position.x = initialBounds.xMax - self->size.x * (1.0f - self->relativeOrigin.x); } float dragAreaHeight = getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); if (self->position.y - (self->size.y + dragAreaHeight) * self->relativeOrigin.y < initialBounds.yMin) { self->position.y = initialBounds.yMin + (self->size.y + dragAreaHeight) * self->relativeOrigin.y; } else if (self->position.y + (self->size.y + dragAreaHeight) * (1.0f - self->relativeOrigin.y) > initialBounds.yMax) { self->position.y = initialBounds.yMax - (self->size.y + dragAreaHeight) * (1.0f - self->relativeOrigin.y); } } void UIWindowView_draw(UIWindowView * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO) { if (!self->visible) { return; } if (self->firstDraw) { clampPositionToInitialBounds(self); self->firstDraw = false; } Color4f titleColorTop = self->titleColorTop; Color4f titleColorBottom = self->titleColorBottom; Color4f titleTextColor = self->titleTextColor; if (!call_virtual(isModal, self) && !UIElement_isInFocusChain(self)) { Color4f bottomColorGray = COLOR4f(0.5f, 0.5f, 0.5f, titleColorBottom.alpha); Color4f topColorGray = COLOR4f(0.5f, 0.5f, 0.5f, titleColorTop.alpha); if (drawingInterface->alphaPremultiplied) { bottomColorGray.red *= bottomColorGray.alpha; bottomColorGray.green *= bottomColorGray.alpha; bottomColorGray.blue *= bottomColorGray.alpha; topColorGray.red *= bottomColorGray.alpha; topColorGray.green *= bottomColorGray.alpha; topColorGray.blue *= bottomColorGray.alpha; } titleColorBottom = Color4f_interpolate(titleColorBottom, bottomColorGray, 0.25f); titleColorTop = Color4f_interpolate(titleColorTop, topColorGray, 0.25f); titleTextColor = Color4f_interpolate(titleTextColor, COLOR4f(0.0f, 0.0f, 0.0f, 0.0f), 0.375f); } Rect4f bounds = Rect4f_offset(call_virtual(getBounds, self), offset); float dragAreaHeight = getAppearanceFloat(self->appearance, UIWindowView_dragAreaHeight); float dropShadowOutset = getAppearanceFloat(self->appearance, UIWindowView_dropShadowOutset); Vector2f dropShadowOffset = getAppearanceVector2f(self->appearance, UIWindowView_dropShadowOffset); Rect4f whiteEntry = getAppearanceAtlasEntry(self->appearance, UIToolkit_white).bounds; call_virtual(drawSlicedQuad3x3, drawingInterface, Rect4f_offset(Rect4f_inset(bounds, VECTOR2f(-dropShadowOutset, -dropShadowOutset)), dropShadowOffset), UIAtlasEntry_boundsForScale(getAppearanceAtlasEntry(self->appearance, UIWindowView_windowDropShadow), drawingInterface->scaleFactor), getAppearanceSliceGrid3x3(self->appearance, UIWindowView_dropShadowSlices), getAppearanceColor4f(self->appearance, UIWindowView_dropShadowColor), vertexIO); call_virtual(drawQuad, drawingInterface, RECT4f(bounds.xMin, bounds.xMax, bounds.yMin, bounds.yMin + self->size.y), whiteEntry, self->backgroundColor, vertexIO); unsigned int vertexStartIndex = vertexIO->vertexCount; call_virtual(drawSlicedQuad3x3, drawingInterface, RECT4f(bounds.xMin, bounds.xMax, bounds.yMax - dragAreaHeight, bounds.yMax), UIAtlasEntry_boundsForScale(getAppearanceAtlasEntry(self->appearance, UIWindowView_windowDragArea), drawingInterface->scaleFactor), getAppearanceSliceGrid3x3(self->appearance, UIWindowView_dragAreaSlices), titleColorBottom, vertexIO); applyVertexColorGradient(vertexStartIndex, vertexIO->vertexCount - vertexStartIndex, titleColorBottom, titleColorTop, VECTOR2f(bounds.xMin, bounds.yMax - dragAreaHeight), VECTOR2f(bounds.xMin, bounds.yMax), vertexIO); unsigned int lastIndex = vertexIO->indexCount; UITypeface * typeface = UIToolkit_getUITypeface(self->appearance, drawingInterface); call_virtual(drawString, drawingInterface, typeface, self->title, VECTOR2f(bounds.xMin + getAppearanceFloat(self->appearance, UIWindowView_titleLeftPadding), bounds.yMax - dragAreaHeight / 2), VECTOR2f(0.0f, 0.5f), 1.0f, titleTextColor, vertexIO); clipVerticesInsideRect(lastIndex, vertexIO->indexCount - lastIndex, bounds, vertexIO); } void UIWindowView_listRenderables(UIWindowView * self, RenderableIO * renderableIO, int drawOrderOffset, Rect4i clipBounds) { self->dirty = false; if (!self->visible) { return; } unsigned int windowIndex = UIWindowRoot_getWindowIndex(self->windowRoot, self); RenderableIO_addRenderable(renderableIO, self->renderable, drawOrderOffset + 100 + windowIndex, clipBounds); if (self->closeButton != NULL) { if (UIElement_isInFocusChain(self) || self->closeButton->rollover) { setAppearanceColor4f(&self->closeButton->appearance, UIGraphicalButton_color, COLOR4f(1.0f, 1.0f, 1.0f, 1.0f)); } else { setAppearanceColor4f(&self->closeButton->appearance, UIGraphicalButton_color, COLOR4f_PREMULTIPLIED(1.0f, 1.0f, 1.0f, 0.5f)); } updateCloseButtonPosition(self); } unsigned int elementIndex = 0; if (self->closeButton != NULL) { call_virtual(listRenderables, self->closeButton, renderableIO, drawOrderOffset + 100 + windowIndex, clipBounds); elementIndex = 1; } clipBounds = UIElement_intersectClipBounds(clipBounds, call_virtual(getAbsoluteClipBounds, self)); for (; elementIndex < self->elementCount; elementIndex++) { call_virtual(listRenderables, self->elements[elementIndex].element, renderableIO, drawOrderOffset + 100 + windowIndex, clipBounds); } } ShellCursorID UIWindowView_getCursorAtPosition(UIWindowView * self, float x, float y) { if (self->resizeCallback == NULL) { return call_super_virtual(getCursorAtPosition, self, x, y); } Vector2f rootPosition = UIElement_localToRootVector(self, VECTOR2f(x, y)); if (self->resizingView || UIElement_hitTestSingle(UIElement_getTopParent(self), rootPosition.x, rootPosition.y, HIT_TEST_MOUSE_OVER) == (UIElement *) self) { Vector2i resizeDirection; if (self->resizingView) { resizeDirection = self->resizeDirection; } else { resizeDirection = getResizeDirection(self, x, y, call_virtual(getBounds, self)); } if (resizeDirection.x == -1) { if (resizeDirection.y == -1) { return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeBottomLeft); } if (resizeDirection.y == 1) { return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeTopLeft); } return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeLeft); } if (resizeDirection.x == 1) { if (resizeDirection.y == -1) { return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeBottomRight); } if (resizeDirection.y == 1) { return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeTopRight); } return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeRight); } if (resizeDirection.y == -1) { return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeBottom); } if (resizeDirection.y == 1) { return UIToolkit_getBuiltInCursor(UIToolkitCursor_resizeTop); } } return call_super_virtual(getCursorAtPosition, self, x, y); } void UIWindowView_showWindow(UIWindowView * self) { self->visible = true; } void UIWindowView_hideWindow(UIWindowView * self) { self->visible = false; } void UIWindowView_bringToFront(UIWindowView * self) { UIWindowRoot_bringWindowToFront(self->windowRoot, self); } bool UIWindowView_isModal(UIWindowView * self) { return false; } void UIWindowView_enforceMinimumWindowSize(Vector2f sizeMin, Rect4f * ioNewBounds, Vector2i resizeDirection) { if (ioNewBounds->xMax - ioNewBounds->xMin < sizeMin.x) { if (resizeDirection.x == -1) { ioNewBounds->xMin = ioNewBounds->xMax - sizeMin.x; } else { ioNewBounds->xMax = ioNewBounds->xMin + sizeMin.x; } } if (ioNewBounds->yMax - ioNewBounds->yMin < sizeMin.y) { if (resizeDirection.y == -1) { ioNewBounds->yMin = ioNewBounds->yMax - sizeMin.y; } else { ioNewBounds->yMax = ioNewBounds->yMin + sizeMin.y; } } } void UIWindowView_enforceMaximumWindowSize(Vector2f sizeMax, Rect4f * ioNewBounds, Vector2i resizeDirection) { if (ioNewBounds->xMax - ioNewBounds->xMin > sizeMax.x) { if (resizeDirection.x == -1) { ioNewBounds->xMin = ioNewBounds->xMax - sizeMax.x; } else { ioNewBounds->xMax = ioNewBounds->xMin + sizeMax.x; } } if (ioNewBounds->yMax - ioNewBounds->yMin > sizeMax.y) { if (resizeDirection.y == -1) { ioNewBounds->yMin = ioNewBounds->yMax - sizeMax.y; } else { ioNewBounds->yMax = ioNewBounds->yMin + sizeMax.y; } } }