/* 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 "testharness/TestPaletteView.h" #include "uitoolkit/UIToolkitAppearance.h" #include "uitoolkit/UIToolkitContext.h" #include "utilities/IOUtilities.h" #include #include #include #define stemobject_implementation TestPaletteView stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(getCellCount); stemobject_vtable_entry(getCellSize); stemobject_vtable_entry(getCellTooltipString); stemobject_vtable_entry(cellSelected); stemobject_vtable_entry(selectionChanged); stemobject_vtable_entry(cellDoubleClicked); stemobject_vtable_entry(cellsDraggedToIndex); stemobject_vtable_entry(drawCell); stemobject_vtable_end(); TestPaletteView * TestPaletteView_create(Vector2f position, Vector2f relativeOrigin, Vector2f sizeMax, UIAppearance appearance) { stemobject_create_implementation(init, position, relativeOrigin, sizeMax, appearance) } bool TestPaletteView_init(TestPaletteView * self, Vector2f position, Vector2f relativeOrigin, Vector2f sizeMax, UIAppearance appearance) { call_super(init, self, UIToolkit_currentContext()->defaultShaderConfiguration, position, relativeOrigin, sizeMax, SELECT_MODE_MULTIPLE, appearance); self->allowDrag = true; return true; } void TestPaletteView_dispose(TestPaletteView * self) { call_super_virtual(dispose, self); } unsigned int TestPaletteView_getCellCount(TestPaletteView * self) { return 128; } Vector2u TestPaletteView_getCellSize(TestPaletteView * self, unsigned int cellIndex, Vector2i * outCellOffset) { return VECTOR2u(16 * ((unsigned int) log10(cellIndex) + 1), 28); } String TestPaletteView_getCellTooltipString(TestPaletteView * self, unsigned int cellIndex) { if (cellIndex == 9) { return STRL("Nine"); } if (cellIndex == 23) { return STRL("Twenty-three"); } return STR_NULL; } void TestPaletteView_cellSelected(TestPaletteView * self, unsigned int cellIndex, unsigned int modifiers) { printf("Cell %u selected (modifiers = 0x%X)\n", cellIndex, modifiers); } void TestPaletteView_selectionChanged(TestPaletteView * self) { printf("Palette selection changed\n"); } void TestPaletteView_cellDoubleClicked(TestPaletteView * self, unsigned int cellIndex) { printf("Palette cell %u double clicked\n", cellIndex); } void TestPaletteView_cellsDraggedToIndex(TestPaletteView * self, unsigned int cellIndex, unsigned int modifiersAtDragStart, unsigned int modifiersAtDragEnd) { printf("Palette cells dragged to index %u (modifiers: 0x%X before, 0x%X after)\n", cellIndex, modifiersAtDragStart, modifiersAtDragEnd); } void TestPaletteView_drawCell(TestPaletteView * self, unsigned int cellIndex, Rect4f bounds, Vector2i offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO) { char string[8]; snprintf_safe(string, sizeof(string), "%u", cellIndex); call_virtual(drawString, drawingInterface, getAppearanceTypeface(self->appearance, UIToolkit_typeface), STR(string), Rect4f_getCenter(bounds), VECTOR2f(0.5f, 0.5f), 1.0f, COLOR4f(0.0f, 0.0f, 0.0f, 1.0f), vertexIO); }