integer math
This commit is contained in:
parent
4428cfe12c
commit
5ff43e240c
27 changed files with 922 additions and 1011 deletions
|
|
@ -6,7 +6,7 @@ int main() {
|
|||
constexpr std::uint_fast32_t width = 1280;
|
||||
constexpr std::uint_fast32_t height = 720;
|
||||
|
||||
Window<true, false, false, false> window(width, height);
|
||||
WindowWayland window(width, height, "Hello Drawing!");
|
||||
|
||||
for(std::uint_fast32_t x = 0; x < width; x++) {
|
||||
for(std::uint_fast32_t y = 0; y < height; y++) {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ Make sure that the window has focus.
|
|||
## Highlighted Code Snippet
|
||||
|
||||
```cpp
|
||||
EventListener<MousePoint> clickListener(&window.onMouseLeftClick, [](MousePoint point){
|
||||
std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y);
|
||||
EventListener<MousePoint> clickListener(&window.onMouseLeftClick, [&window](MousePoint point){
|
||||
std::cout << std::format("Clicked on X:{} Y:{}!", MappedToPixel(point.x, window.width), MappedToPixel(point.y, window.height));
|
||||
});
|
||||
|
||||
EventListener<void> keyAListener(&window.onKeyDown['a'], [](){
|
||||
|
|
|
|||
|
|
@ -4,15 +4,13 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
// Create a Wayland window named "HelloWindow" with resolution 1280x720
|
||||
// (window creation explained in HelloWindow example)
|
||||
Window window("HelloWindow", 1280, 720);
|
||||
WindowWayland window(1280, 720, "Hello Input!");
|
||||
|
||||
// Listen for left mouse click events on the window
|
||||
// The callback receives the MousePoint struct containing the click coordinates in float pixels from the top left corner
|
||||
EventListener<MousePoint> clickListener(&window.onMouseLeftClick, [](MousePoint point){
|
||||
EventListener<MousePoint> clickListener(&window.onMouseLeftClick, [&window](MousePoint point){
|
||||
// Print the coordinates where the user clicked
|
||||
std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y) << std::endl;
|
||||
std::cout << std::format("Clicked on X:{} Y:{}!", MappedToPixel(point.x, window.width), MappedToPixel(point.y, window.height)) << std::endl;
|
||||
});
|
||||
|
||||
// Listen specifically for the 'a' key being pressed down
|
||||
|
|
@ -29,6 +27,6 @@ int main() {
|
|||
std::cout << std::format("Pressed the {} key!", key) << std::endl;
|
||||
});
|
||||
|
||||
// Start the window event loop, unless the window is started events will not trigger.
|
||||
//Start the window event loop, unless the window is started events will not trigger.
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,27 +4,31 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
Window<true, false, false, false> window(1280, 720);
|
||||
WindowWayland window(1280, 720, "Hello Input!");
|
||||
|
||||
UiElement<true, true>& element = window.CreateElement<true, true>(
|
||||
UiElementBufferMouseBuffer* element = new UiElementBufferMouseBuffer(
|
||||
2, //bufferWidth: the width of this elements pixel buffer
|
||||
1, //bufferHeight: the height of this elements pixel buffer
|
||||
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.5f, //relativeSizeX: the relative x size this element should be scaled to compared to its parent
|
||||
0.5f, //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)
|
||||
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
|
||||
FractionalToMapped(0.5), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
|
||||
FractionalToMapped(0.5), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
|
||||
FractionalToMapped(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)
|
||||
0, //z: this elements Z position
|
||||
false //ignoreScaling: wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale
|
||||
);
|
||||
|
||||
// EventListener<MousePoint> clickListener(&element.onMouseLeftClick, [](MousePoint point){
|
||||
// // Print the coordinates where the user clicked relative to the element's top left corner.
|
||||
// std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y) << std::endl;
|
||||
// });
|
||||
window.elements.push_back(element);
|
||||
|
||||
element.buffer.buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
window.framebuffer.Render();
|
||||
element->UpdatePosition(window);
|
||||
|
||||
EventListener<MousePoint> clickListener(&element.onMouseLeftClick, [](MousePoint point){
|
||||
// Print the coordinates where the user clicked relative to the element's top left corner.
|
||||
std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y) << std::endl;
|
||||
});
|
||||
|
||||
element->buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
window.Render();
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ A empty window with the title "HelloWindow" shows onscreen.
|
|||
## Highlighted Code Snippet
|
||||
|
||||
```cpp
|
||||
Window<true, true, false, false> window;
|
||||
window.framebuffer.Create(1280, 720);
|
||||
window.title.Set("HelloWindow");
|
||||
WindowWayland window(1280, 720, "Hello Window!");
|
||||
window.StartSync();
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
Window<true, true, false, false> window(1280, 720, "HelloWindow");
|
||||
WindowWayland window(1280, 720, "Hello Window!");
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue