Crafter.Graphics/examples/HelloUI/main.cpp

40 lines
1.5 KiB
C++
Raw Normal View History

2025-06-13 23:59:36 +02:00
import Crafter.Event;
import Crafter.Graphics;
2025-11-16 18:52:52 +01:00
import std;
2025-06-13 23:59:36 +02:00
using namespace Crafter;
int main() {
2026-03-09 20:10:19 +01:00
Device::Initialize();
Window window(1280, 720, "Hello Drawing!");
2025-06-13 23:59:36 +02:00
2026-03-09 20:10:19 +01:00
RenderingElement2D<true, true, false> element(
2025-12-28 00:05:03 +01:00
{
2026-03-09 20:10:19 +01:00
0.5, //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
0.5, //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
0.5, //relativeSizeX: the relative x size this element should be scaled to compared to its parent
0.5, //relativeSizeY: the relative y size this element should be scaled to compared to its parent
0.5, //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
0.5, //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle)
2025-12-28 00:05:03 +01:00
0 //z: this elements Z position
},
2025-11-27 00:17:06 +01:00
OpaqueType::FullyOpaque,
2025-11-26 02:56:38 +01:00
2,
2025-12-28 00:05:03 +01:00
1
2025-06-14 01:45:33 +02:00
);
2025-12-30 23:28:38 +01:00
MouseElement mouse(window);
2025-11-25 20:30:54 +01:00
element.children.push_back(&mouse);
2026-03-09 20:10:19 +01:00
window.renderer.elements.push_back(&element);
2025-11-25 20:30:54 +01:00
2025-12-28 00:05:03 +01:00
element.scalingBuffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
2026-03-09 20:10:19 +01:00
element.UpdatePosition(window.renderer);
2025-11-23 04:04:53 +01:00
2026-03-09 20:10:19 +01:00
EventListener<void> clickListener(&mouse.onMouseLeftClick, [&window]() {
std::println("Clicked on X:{} Y:{}!",
window.currentMousePos.x, window.currentMousePos.y
2025-12-30 23:28:38 +01:00
);
2025-11-23 04:04:53 +01:00
});
window.Render();
2025-06-13 23:59:36 +02:00
window.StartSync();
}