/* Copyright (c) 2019 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 __UIToolkitDrawing_H__ #define __UIToolkitDrawing_H__ #ifdef __cplusplus extern "C" { #endif #include "gamemath/Rect4f.h" #include "renderer/VertexTypes.h" #include "uitoolkit/UIAppearance.h" #include "uitoolkit/UIDrawingInterface.h" #include "uitoolkit/UITypes.h" typedef struct UIToolkit_sliceVertex { Vector2f position; Vector2f texCoords; } UIToolkit_sliceVertex; typedef struct UIToolkit_sliceVertexWithRow { Vector2f position; Vector2f texCoords; unsigned int rowIndex; } UIToolkit_sliceVertexWithRow; #define UI_SLICE_VERTEX_COUNT_3x3 16 #define UI_SLICE_INDEX_COUNT_3x3 54 #define UI_SLICE_VERTEX_COUNT_3x1 8 #define UI_SLICE_INDEX_COUNT_3x1 18 #define UI_SLICE_VERTEX_COUNT_1x3 8 #define UI_SLICE_INDEX_COUNT_1x3 18 // Draws four nonoverlapping quads of a thickness specified by inset (extending inward) around the outer perimeter of rect void UIToolkit_drawRectOutline(Rect4f rect, float inset, Color4f color, Rect4f textureBounds, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); // outSliceVertices must be large enough to store UI_SLICE_VERTEX_COUNT_3x3 elements // outSliceIndexes must be large enough to store UI_SLICE_INDEX_COUNT_3x3 elements void UIToolkit_sliceQuad3x3(Rect4f vertexBounds, Rect4f textureBounds, UISliceGrid3x3 slices, UIToolkit_sliceVertex * outSliceVertices, uint32_t * outSliceIndexes); // outSliceVertices must be large enough to store UI_SLICE_VERTEX_COUNT_3x1 elements // outSliceIndexes must be large enough to store UI_SLICE_INDEX_COUNT_3x1 elements void UIToolkit_sliceQuad3x1(Rect4f vertexBounds, Rect4f textureBounds, UISliceGrid3x1 slices, UIToolkit_sliceVertex * outSliceVertices, uint32_t * outSliceIndexes); // outSliceVertices must be large enough to store UI_SLICE_VERTEX_COUNT_1x3 elements // outSliceIndexes must be large enough to store UI_SLICE_INDEX_COUNT_1x3 elements void UIToolkit_sliceQuad1x3(Rect4f vertexBounds, Rect4f textureBounds, UISliceGrid1x3 slices, UIToolkit_sliceVertex * outSliceVertices, uint32_t * outSliceIndexes); // Returns the number of elements that will be written by UIToolkit_sliceQuad3x3WithRows() for the same vertexBounds, slices, inset, and rowHeight in outVertexCount and outIndexCount. Both must be non-NULL. void UIToolkit_getCountsForSlicedQuad3x3WithRows(Rect4f vertexBounds, UISliceGrid3x3 slices, float inset, float rowHeight, unsigned int * outVertexCount, unsigned int * outIndexCount); // outSliceVertices must be large enough to store a number of elements equal to value returned in outVertexCount for a call to UIToolkit_getCountsForSlicedQuad3x3WithRows() with the same vertexBounds, slices, inset, and rowHeight // outSliceIndexes must be large enough to store a number of elements equal to value returned in outIndexCount for a call to UIToolkit_getCountsForSlicedQuad3x3WithRows() with the same vertexBounds, slices, inset, and rowHeight void UIToolkit_sliceQuad3x3WithRows(Rect4f vertexBounds, Rect4f textureBounds, UISliceGrid3x3 slices, float inset, float rowHeight, UIToolkit_sliceVertexWithRow * outSliceVertices, uint32_t * outSliceIndexes); void UIToolkit_drawVerticalScrollbar(Rect4f containerBounds, float scrollPosition, float heightTotal, float displayedHeight, bool rounded, bool mini, bool dragging, bool mouseover, UIAppearance appearance, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIToolkit_drawHorizontalScrollbar(Rect4f containerBounds, float scrollPosition, float widthTotal, float displayedWidth, bool rounded, bool mini, bool dragging, bool mouseover, UIAppearance appearance, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIToolkit_drawVerticalScrollbarExtended(Rect4f containerBounds, float scrollPosition, float heightTotal, float displayedHeight, bool rounded, Color4f color, float width, Rect4f atlasEntry, UISliceGrid1x3 slices, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIToolkit_drawHorizontalScrollbarExtended(Rect4f containerBounds, float scrollPosition, float widthTotal, float displayedWidth, bool rounded, Color4f color, float height, Rect4f atlasEntry, UISliceGrid3x1 slices, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); bool UIToolkit_hitTestVerticalScrollbar(float x, float y, Rect4f bounds, float scrollPosition, float heightTotal, float displayedHeight, UIAppearance appearance); bool UIToolkit_hitTestHorizontalScrollbar(float x, float y, Rect4f bounds, float scrollPosition, float widthTotal, float displayedWidth, UIAppearance appearance); void UIToolkit_drawPopUpFrameWithShadow(Rect4f bounds, Color4f color, float shadowStrength, UIAppearance appearance, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIToolkit_drawPopUpFrameShadowOnly(Rect4f bounds, float shadowStrength, UIAppearance appearance, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); void UIToolkit_drawPopUpTail(Rect4f popUpBounds, Vector2f tailPosition, Color4f tailColor, UIAppearance appearance, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); UITypeface * UIToolkit_getUITypeface(UIAppearance appearance, UIDrawingInterface * drawingInterface); // invokerBounds and safeUIBounds must be in the same coordinate system, either both relative or both absolute // perpendicularMin specifies the minimum distance that the attach point must be from the nearest boundary along // the axis perpendicular to the attach direction; for example, to keep a pop-up tail from getting too close to // a rounded corner and detaching from the pop-up frame void UIToolkit_getBestInvokerAttachPoint(Rect4f invokerBounds, Vector2f size, UISidePreference sidePreference, float perpendicularMin, float offset, Rect4f safeUIBounds, Vector2f * outRawPosition, Vector2f * outAdjustedPosition, Vector2f * outRelativeOrigin); #ifdef __cplusplus } #endif #endif