actually sensible classes
This commit is contained in:
parent
9bbefbc021
commit
c3b8761102
13 changed files with 128 additions and 152 deletions
|
|
@ -6,9 +6,7 @@ using namespace Crafter;
|
|||
int main() {
|
||||
WindowWayland window(1280, 720, "Hello Input!");
|
||||
|
||||
RenderingMouseElement element(
|
||||
2, //bufferWidth: the width of this elements pixel buffer
|
||||
1, //bufferHeight: the height of this elements pixel buffer
|
||||
Transform element(
|
||||
FractionalToMapped(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
|
||||
FractionalToMapped(0.5), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
|
||||
FractionalToMapped(0.5), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
|
||||
|
|
@ -19,13 +17,17 @@ int main() {
|
|||
false //ignoreScaling: wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale
|
||||
);
|
||||
|
||||
window.elements.push_back(&element.rendering);
|
||||
window.mouseElements.push_back(&element.mouse);
|
||||
RenderingElement rendering(2, 1);
|
||||
MouseElement mouse(window);
|
||||
|
||||
element.rendering.buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
element.children.push_back(&rendering);
|
||||
element.children.push_back(&mouse);
|
||||
window.elements.push_back(&element);
|
||||
|
||||
rendering.buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
element.UpdatePosition(window);
|
||||
|
||||
EventListener<MousePoint> clickListener(&element.mouse.onMouseLeftClick, [&element, &window](MousePoint point){
|
||||
EventListener<MousePoint> clickListener(&mouse.onMouseLeftClick, [&mouse, &window](MousePoint point){
|
||||
// Print the coordinates where the user clicked relative to the element's top left corner.
|
||||
|
||||
//Mapped space
|
||||
|
|
@ -35,7 +37,7 @@ int main() {
|
|||
std::cout << std::format("Clicked on Fraction X:{} Y:{}!", MappedToFractionalBoundless(point.x), MappedToFractionalBoundless(point.y)) << std::endl;
|
||||
|
||||
// Screen space
|
||||
std::cout << std::format("Clicked on Screen X:{} Y:{}!\n", MappedToPixelBoundless(point.x, MappedToPixelBoundless(element.mouse.transform.scaled.width, window.width)), MappedToPixelBoundless(point.y, MappedToPixelBoundless(element.mouse.transform.scaled.width, window.height))) << std::endl;
|
||||
std::cout << std::format("Clicked on Screen X:{} Y:{}!\n", MappedToPixelBoundless(point.x, MappedToPixelBoundless(mouse.scaled.width, window.width)), MappedToPixelBoundless(point.y, MappedToPixelBoundless(mouse.scaled.width, window.height))) << std::endl;
|
||||
});
|
||||
|
||||
window.Render();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue