come up with a commit message for this diff --git a/src/gui/component.cpp…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
come up with a commit message for this
diff --git a/src/gui/component.cpp b/src/gui/component.cpp index 61eef69..16ac96f 100644 --- a/src/gui/component.cpp +++ b/src/gui/component.cpp @@ -1,11 +1,20 @@ #include "component.hpp" #include "event.h" -whim::gui::Component::Component(){
this->eventListeners[ev->type]) {
diff --git a/src/gui/component.hpp b/src/gui/component.hpp index 0363e3f..5045964 100644 --- a/src/gui/component.hpp +++ b/src/gui/component.hpp @@ -17,7 +17,8 @@ public: virtual void render() = 0; virtual std::vector hitbox() = 0; rendering::Screen *screen;
std::unordered_map<std::string, std::vector<void()(Event ev, Component* self)>> eventListeners;
void addEventListener(std::string type, void(func)(Event ev, Component* self)); void triggerEvent(Event* ev);
// ID and name are both unique diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 73076f3..8bab896 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -62,16 +62,16 @@ void whim::gui::GUI::updateRenderchain() { } } } -whim::gui::Component* whim::gui::GUI::componentByCoords(int x, int y){
if(ev.attribute_moving == true){
whim::gui::Component* mouseOver = componentByCoords(ev.x, ev.y);
if(mouseOver != this->mouseOverComponent){
if (ev.attribute_moving == true) {
whim::gui::Component *mouseOver = componentByCoords(ev.x, ev.y);
if (mouseOver != this->mouseOverComponent) {
MouseEvent lev{"mouseLeave", ev};
this->mouseOverComponent->triggerEvent(&lev);
MouseEvent eev{"mouseEnter", ev};
@@ -101,12 +101,40 @@ void whim::gui::GUI::tick() { this->mouseOverComponent = mouseOver; } }
// Left click = select component
else if ((ev.button == input::mouse::leftclick ||
ev.button == input::mouse::middleclick ||
ev.button == input::mouse::rightclick) &&
!ev.isUp && !ev.attribute_mousewheel) {
whim::gui::Component *selected = componentByCoords(ev.x, ev.y);
if (selected != this->selectedComponent) {
MouseEvent sev{"select", ev};
selected->triggerEvent(&sev);
MouseEvent uev{"unselect", ev};
this->selectedComponent->triggerEvent(&uev);
this->selectedComponent = selected;
}
// Send click/middlecilck/rightclick event
MouseEvent cev{"mousedown", ev};
selected->triggerEvent(&cev);
} else if ((ev.button == input::mouse::leftclick ||
ev.button == input::mouse::middleclick ||
KeyEvent ev{"type", keyname, chr };
selectedComponent->triggerEvent(&ev);
KeyEvent ev{"type", keyname, chr};
selectedComponent->triggerEvent(&ev);
Add event handling and component addition to GUI components
In the src/gui/component.cpp file, the following changes were made:
#include <vector>addEventListener to handle adding event listeners to the component.In the src/gui/component.hpp file, the following changes were made:
eventListeners declaration to use a std::unordered_map with a vector of event functions instead of a single event function.In the src/gui/gui.cpp file, the following changes were made:
componentByCoords to find the component at a given coordinate.keyPressed event handling to use KeyEvent instead of Event.The commit message for these changes could be:
"Add event handling and component addition to GUI components: Added a new function addEventListener to handle adding event listeners to the component. Updated the eventListeners declaration to use a std::unordered_map with a vector of event functions instead of a single event function. Added a new function componentByCoords to find the component at a given coordinate. Updated the keyPressed event handling to use KeyEvent instead of Event. Added new event handling for mouse events, including click, left click, middle click, right click, mouse wheel, and mouse move events."
ev.button == input::mouse::rightclick) &&
ev.isUp == true && !ev.attribute_mousewheel) {
whim::gui::Component *target = componentByCoords(ev.x, ev.y);
MouseEvent uev{"mouseup", ev};
target->triggerEvent(&uev);
} else if (ev.attribute_mousewheel) {
whim::gui::Component *target = componentByCoords(ev.x, ev.y);
MouseEvent sev{"mousewheel", ev};
target->triggerEvent(&sev);
}