Crafter.Graphics/examples/HelloInput/main.cpp
2025-11-23 04:04:53 +01:00

32 lines
1.4 KiB
C++

import Crafter.Graphics;
import Crafter.Event;
import std;
using namespace Crafter;
int main() {
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, [&window](MousePoint point){
// Print the coordinates where the user clicked
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
// The callback takes no parameters since the key is fixed
EventListener<void> keyAListener(&window.onKeyDown['a'], [](){
// Print confirmation of 'a' key press
std::cout << std::format("Pressed specifically the a key!") << std::endl;
});
// Listen for any key press on the window
// The callback receives the character of the key pressed
EventListener<char> anyKeyListener(&window.onAnyKeyDown, [](char key){
// Print which key was pressed
std::cout << std::format("Pressed the {} key!", key) << std::endl;
});
//Start the window event loop, unless the window is started events will not trigger.
window.StartSync();
}