Skip to content

Commit

Permalink
Mouse handler refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
khrykin committed Jan 31, 2020
1 parent 24997a8 commit f6eb20a
Show file tree
Hide file tree
Showing 42 changed files with 1,546 additions and 1,466 deletions.
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ set(CMAKE_CXX_STANDARD 17)
find_package(Boost COMPONENTS filesystem REQUIRED)
find_package(catch2 REQUIRED)
find_package(Qt5 COMPONENTS Widgets Network Test REQUIRED)
find_library(uf8Proc_LIBRARY_PATH utf8Proc)
find_package(nlohmann_json REQUIRED)

find_library(uf8Proc_LIBRARY_PATH libutf8proc.a libutf8proc.lib utf8proc)

if (APPLE)
find_package(Qt5 COMPONENTS MacExtras REQUIRED)
endif ()

find_package(nlohmann_json REQUIRED)
message(${uf8Proc_LIBRARY_PATH})

include_directories(.)
include_directories(models)
Expand Down Expand Up @@ -78,10 +80,10 @@ set(MODELS ${MODELS_PLATFORM_FILES}
models/notifier.cpp
models/notifier.h
models/utility.h
models/mousehandler.cpp
models/mousehandler.h
models/mouse_handler.cpp
models/mouse_handler.h
models/mousehandleroperations.cpp
models/mousehandleroperations.h)
models/mousehandleroperations.h models/selection.cpp models/selection.h models/event.cpp models/event.h)

set(MODELS_TESTS
models/tests/activity_tests.cpp
Expand Down Expand Up @@ -114,16 +116,16 @@ set(UI
ui/sessionsmainwidget.h
ui/activitylistwidget.cpp
ui/activitylistwidget.h
ui/activitylistitemwidget.cpp
ui/activitylistitemwidget.h
ui/activitywidget.cpp
ui/activitywidget.h
ui/strategysettingswidget.cpp
ui/strategysettingswidget.h
ui/slotboard.cpp
ui/slotboard.h
ui/slotboardwidget.cpp
ui/slotboardwidget.h
ui/slidinganimator.cpp
ui/slidinganimator.h
ui/slotswidget.cpp
ui/slotboard.h
ui/slotboardwidget.h
ui/slotruler.cpp
ui/slotruler.h
ui/sessionwidget.cpp
Expand Down Expand Up @@ -176,7 +178,7 @@ set(UI
ui/searchbox.cpp
ui/searchbox.h
ui/dynamicpalette.cpp
ui/dynamicpalette.h)
ui/dynamicpalette.h ui/slotboardcircleswidget.cpp ui/slotboardcircleswidget.h)

set(UTILITY
${version_file}
Expand Down
42 changes: 42 additions & 0 deletions models/event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Created by Dmitry Khrykin on 2020-01-30.
//

#include "event.h"

stg::event::event(stg::event::key_modifiers modifiers)
: modifiers(modifiers) {
}

stg::mouse_event::mouse_event(const stg::point &position,
stg::event::key_modifiers modifiers)
: event(modifiers),
position(position) {
}

bool stg::event::is(stg::event::key_modifiers mod) const {
return modifiers == mod;
}

bool stg::event::with(stg::event::key_modifiers mod) const {
return (modifiers & mod) == mod;
}

std::ostream &stg::operator<<(std::ostream &os, const stg::mouse_event &e) {
os << "mouse_event {\n";
os << " position: [" << e.position.x << ", " << e.position.y << "]\n";
os << " modifiers: [";
if (e.with(mouse_event::left_key)) {
os << " left_key ";
}
if (e.with(mouse_event::right_key)) {
os << " right_key ";
}
if (e.with(mouse_event::ctrl_key)) {
os << " ctrl_key ";
}
os << "]\n";
os << "}\n";

return os;
}
51 changes: 51 additions & 0 deletions models/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Created by Dmitry Khrykin on 2020-01-30.
//

#ifndef STRATEGR_EVENT_H
#define STRATEGR_EVENT_H

#include "geometry.h"

namespace stg {
struct event {
using key_modifiers = uint8_t;

static constexpr key_modifiers left_key = 1u << 0u;
static constexpr key_modifiers right_key = 1u << 1u;
static constexpr key_modifiers ctrl_key = 1u << 2u;

explicit event(key_modifiers modifiers);

template<class QtLikeEvent>
event(QtLikeEvent *evt) {
if (evt->modifiers() == 0x04000000) {
modifiers |= ctrl_key;
};
}

bool is(key_modifiers mod) const;
bool with(key_modifiers mod) const;

key_modifiers modifiers = 0;
};

struct mouse_event : public event {
mouse_event(const point &position, key_modifiers modifiers);

template<class QtLikeEvent>
mouse_event(QtLikeEvent *evt) : event(evt), position(evt->pos()) {
if (evt->buttons() == 1) {
modifiers |= left_key;
} else if (evt->buttons() == 2) {
modifiers |= right_key;
}
}

friend std::ostream &operator<<(std::ostream &os, const mouse_event &e);
point position;
};
};


#endif //STRATEGR_EVENT_H
2 changes: 2 additions & 0 deletions models/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace stg {
int x = 0;
int y = 0;

explicit point(int x = 0, int y = 0) : x(x), y(y) {}

/**
* Implicit constructor for Qt-like point
*/
Expand Down
Loading

0 comments on commit f6eb20a

Please sign in to comment.