34 lines
1.4 KiB
C++
34 lines
1.4 KiB
C++
import Crafter.Graphics;
|
|
import Crafter.Event;
|
|
import std;
|
|
using namespace Crafter;
|
|
|
|
int main() {
|
|
// Create a Wayland window named "HelloWindow" with resolution 1280x720
|
|
// (window creation explained in HelloWindow example)
|
|
WindowWaylandWayland window("HelloWindow", 1280, 720);
|
|
|
|
// 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){
|
|
// Print the coordinates where the user clicked
|
|
std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y) << 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();
|
|
}
|