mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-03 04:48:03 +00:00
Updated rectangle border rendering
This commit is contained in:
parent
a92ec772e1
commit
6567f85eb3
@ -151,11 +151,7 @@ int APIENTRY WinMain(
|
||||
uint64_t clayRequiredMemory = Clay_MinMemorySize();
|
||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(clayRequiredMemory, malloc(clayRequiredMemory));
|
||||
Clay_Initialize(clayMemory, (Clay_Dimensions){.width = 800, .height = 600}, (Clay_ErrorHandler){HandleClayErrors}); // This final argument is new since the video was published
|
||||
|
||||
// Font fonts[1];
|
||||
// fonts[FONT_ID_BODY_16] = LoadFontEx("resources/Roboto-Regular.ttf", 48, 0, 400);
|
||||
|
||||
Clay_SetMeasureTextFunction(Clay_Win32_MeasureText, NULL); // was gettings fonts[] passed in
|
||||
Clay_SetMeasureTextFunction(Clay_Win32_MeasureText, NULL);
|
||||
|
||||
ZeroMemory(&wc, sizeof wc);
|
||||
wc.hInstance = hInstance;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <Windows.h>
|
||||
#include "../../clay.h"
|
||||
|
||||
|
||||
HDC renderer_hdcMem = {0};
|
||||
HBITMAP renderer_hbmMem = {0};
|
||||
HANDLE renderer_hOld = {0};
|
||||
@ -115,18 +114,75 @@ void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands)
|
||||
break;
|
||||
}
|
||||
|
||||
// // The renderer should draw a colored border inset into the bounding box.
|
||||
// case CLAY_RENDER_COMMAND_TYPE_BORDER:
|
||||
// {
|
||||
// // TODO:
|
||||
// break;
|
||||
// }
|
||||
// The renderer should draw a colored border inset into the bounding box.
|
||||
case CLAY_RENDER_COMMAND_TYPE_BORDER:
|
||||
{
|
||||
Clay_BorderRenderData brd = renderCommand->renderData.border;
|
||||
RECT r = rc;
|
||||
|
||||
// case CLAY_RENDER_COMMAND_TYPE_IMAGE:
|
||||
// {
|
||||
// // TODO:
|
||||
// break;
|
||||
// }
|
||||
r.left = boundingBox.x;
|
||||
r.top = boundingBox.y;
|
||||
r.right = boundingBox.x + boundingBox.width;
|
||||
r.bottom = boundingBox.y + boundingBox.height;
|
||||
|
||||
HPEN topPen = CreatePen(PS_SOLID, brd.width.top, RGB(brd.color.r, brd.color.g, brd.color.b));
|
||||
HPEN leftPen = CreatePen(PS_SOLID, brd.width.left, RGB(brd.color.r, brd.color.g, brd.color.b));
|
||||
HPEN bottomPen = CreatePen(PS_SOLID, brd.width.bottom, RGB(brd.color.r, brd.color.g, brd.color.b));
|
||||
HPEN rightPen = CreatePen(PS_SOLID, brd.width.right, RGB(brd.color.r, brd.color.g, brd.color.b));
|
||||
|
||||
HPEN oldPen = SelectObject(renderer_hdcMem, topPen);
|
||||
|
||||
if (brd.cornerRadius.topLeft == 0)
|
||||
{
|
||||
MoveToEx(renderer_hdcMem, r.left, r.top, NULL);
|
||||
LineTo(renderer_hdcMem, r.right, r.top);
|
||||
|
||||
SelectObject(renderer_hdcMem, leftPen);
|
||||
MoveToEx(renderer_hdcMem, r.left, r.top, NULL);
|
||||
LineTo(renderer_hdcMem, r.left, r.bottom);
|
||||
|
||||
SelectObject(renderer_hdcMem, bottomPen);
|
||||
MoveToEx(renderer_hdcMem, r.left, r.bottom, NULL);
|
||||
LineTo(renderer_hdcMem, r.right, r.bottom);
|
||||
|
||||
SelectObject(renderer_hdcMem, rightPen);
|
||||
MoveToEx(renderer_hdcMem, r.right, r.top, NULL);
|
||||
LineTo(renderer_hdcMem, r.right, r.bottom);
|
||||
}
|
||||
else
|
||||
{
|
||||
// todo: i should be rounded
|
||||
MoveToEx(renderer_hdcMem, r.left, r.top, NULL);
|
||||
LineTo(renderer_hdcMem, r.right, r.top);
|
||||
|
||||
SelectObject(renderer_hdcMem, leftPen);
|
||||
MoveToEx(renderer_hdcMem, r.left, r.top, NULL);
|
||||
LineTo(renderer_hdcMem, r.left, r.bottom);
|
||||
|
||||
SelectObject(renderer_hdcMem, bottomPen);
|
||||
MoveToEx(renderer_hdcMem, r.left, r.bottom, NULL);
|
||||
LineTo(renderer_hdcMem, r.right, r.bottom);
|
||||
|
||||
SelectObject(renderer_hdcMem, rightPen);
|
||||
MoveToEx(renderer_hdcMem, r.right, r.top, NULL);
|
||||
LineTo(renderer_hdcMem, r.right, r.bottom);
|
||||
|
||||
}
|
||||
|
||||
SelectObject(renderer_hdcMem, oldPen);
|
||||
DeleteObject(topPen);
|
||||
DeleteObject(leftPen);
|
||||
DeleteObject(bottomPen);
|
||||
DeleteObject(rightPen);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// case CLAY_RENDER_COMMAND_TYPE_IMAGE:
|
||||
// {
|
||||
// // TODO: i couldnt get the win 32 api to load a bitmap.... So im punting on this one :(
|
||||
// break;
|
||||
// }
|
||||
|
||||
default:
|
||||
printf("Unhandled render command %d\r\n", renderCommand->commandType);
|
||||
@ -144,7 +200,6 @@ void Clay_Win32_Render(HWND hwnd, Clay_RenderCommandArray renderCommands)
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Hacks due to the windows api not making sence to use.... may measure too large, but never too small
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user