Skip to content

Commit

Permalink
Implement #19
Browse files Browse the repository at this point in the history
Bordless windows can still be dragged by grabing abhold of anywhere on the application
  • Loading branch information
ZackeryRSmith committed Apr 20, 2023
1 parent dee0e9f commit c754b44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cat": 4,
"cat": 1,
"cats": {
"osu": {
"mouse": true,
Expand Down Expand Up @@ -62,6 +62,7 @@
},

"decoration": {
"borderless": false,
"leftHanded": false,
"backgroundColor": [224, 22, 66],
"offsetX": [0, 11],
Expand Down
27 changes: 25 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi

// loading configs
std::shared_ptr<Cat> cat = data::init();

bool borderless = data::cfg["decoration"]["borderless"].asBool();

window.create(sf::VideoMode(cat->window_width, cat->window_height), "Bongo Cat for osu!", sf::Style::Titlebar | sf::Style::Close);
window.create(sf::VideoMode(cat->window_width, cat->window_height), "BongoCat+", borderless ? sf::Style::None : sf::Style::Titlebar | sf::Style::Close);
window.setFramerateLimit(MAX_FRAMERATE);

// initialize input
Expand All @@ -27,14 +29,18 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
bool is_reload = false;
bool is_show_input_debug = false;

// used if window is borderless
sf::Vector2i grabbed_offset;
bool grabbed_window = false;

while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;

case sf::Event::KeyPressed:
// get reload config prompt
if (event.key.code == sf::Keyboard::R && event.key.control) {
Expand All @@ -53,6 +59,23 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
break;
}

case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left && borderless) {
grabbed_offset = window.getPosition() - sf::Mouse::getPosition();
grabbed_window = true;
}
break;

case sf::Event::MouseButtonReleased:
if (event.mouseButton.button == sf::Mouse::Left && borderless)
grabbed_window = false;
break;

case sf::Event::MouseMoved:
if (grabbed_window && borderless)
window.setPosition(sf::Mouse::getPosition() + grabbed_offset);
break;

default:
is_reload = false;
}
Expand Down

0 comments on commit c754b44

Please sign in to comment.