Skip to content

Commit

Permalink
input: Separate method for resetting drag select.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Nov 25, 2023
1 parent 6a9eab7 commit 54be1c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
19 changes: 10 additions & 9 deletions libopenage/input/controller/game/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,10 @@ bool Controller::process(const event_arguments &ev_args, const std::shared_ptr<B
return true;
}

void Controller::set_drag_select_start(const std::optional<coord::input> &start) {
void Controller::set_drag_select_start(const coord::input &start) {
std::unique_lock lock{this->mutex};

if (start.has_value()) {
log::log(DBG << "Drag select start at " << start.value());
}
else {
log::log(DBG << "Drag select start cleared");
}

log::log(DBG << "Drag select start at " << start);
this->drag_select_start = start;
}

Expand All @@ -115,6 +109,13 @@ const coord::input Controller::get_drag_select_start() const {
return this->drag_select_start.value();
}

void Controller::reset_drag_select() {
std::unique_lock lock{this->mutex};

log::log(DBG << "Drag select start reset");
this->drag_select_start = std::nullopt;
}

void setup_defaults(const std::shared_ptr<BindingContext> &ctx,
const std::shared_ptr<time::TimeLoop> &time_loop,
const std::shared_ptr<openage::gamestate::GameSimulation> &simulation,
Expand Down Expand Up @@ -212,7 +213,7 @@ void setup_defaults(const std::shared_ptr<BindingContext> &ctx,
params);

// Reset drag selection start
controller->set_drag_select_start(std::nullopt);
controller->reset_drag_select();

return event;
}};
Expand Down
7 changes: 6 additions & 1 deletion libopenage/input/controller/game/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Controller : public std::enable_shared_from_this<Controller> {
*
* @param start Start position of the drag selection.
*/
void set_drag_select_start(const std::optional<coord::input> &start);
void set_drag_select_start(const coord::input &start);

/**
* Get the start position of a drag selection.
Expand All @@ -94,6 +94,11 @@ class Controller : public std::enable_shared_from_this<Controller> {
*/
const coord::input get_drag_select_start() const;

/**
* Reset the drag select start position.
*/
void reset_drag_select();

private:
/**
* Factions controllable by this controller.
Expand Down

0 comments on commit 54be1c7

Please sign in to comment.