Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window size customization #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/header.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#define BONGO_KEYPRESS_THRESHOLD 0
#define WINDOW_WIDTH 612
#define WINDOW_HEIGHT 352
#define BASE_WIDTH 612
#define BASE_HEIGHT 352
#define MAX_FRAMERATE 60

#include <iostream>
Expand Down Expand Up @@ -51,29 +51,29 @@ void cleanup();
namespace osu {
bool init();

void draw();
void draw(const sf::RenderStates& rstates);
}; // namespace osu

namespace taiko {
bool init();

void draw();
void draw(const sf::RenderStates& rstates);
}; // namespace taiko

namespace ctb {
bool init();

void draw();
void draw(const sf::RenderStates& rstates);
}; // namespace ctb

namespace mania {
bool init();

void draw();
void draw(const sf::RenderStates& rstates);
}; // namespace mania

namespace custom {
bool init();

void draw();
void draw(const sf::RenderStates& rstates);
}; // namespace custom
16 changes: 8 additions & 8 deletions src/ctb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool init() {
return true;
}

void draw() {
void draw(const sf::RenderStates& rstates) {
window.draw(bg);

// drawing left-right keypresses
Expand Down Expand Up @@ -78,34 +78,34 @@ void draw() {

if (!left_key_state && !right_key_state) {
key_state = 0;
window.draw(mid);
window.draw(mid, rstates);
}
if (key_state == 1) {
if ((clock() - timer_right_key) / CLOCKS_PER_SEC > BONGO_KEYPRESS_THRESHOLD) {
window.draw(left);
window.draw(left, rstates);
timer_left_key = clock();
} else {
window.draw(mid);
window.draw(mid, rstates);
}
} else if (key_state == 2) {
if ((clock() - timer_left_key) / CLOCKS_PER_SEC > BONGO_KEYPRESS_THRESHOLD) {
window.draw(right);
window.draw(right, rstates);
timer_right_key = clock();
} else {
window.draw(mid);
window.draw(mid, rstates);
}
}

bool is_dash = false;
for (Json::Value &v : dash_key_value) {
if (input::is_pressed(v.asInt())) {
window.draw(dash);
window.draw(dash, rstates);
is_dash = true;
break;
}
}
if (!is_dash) {
window.draw(up);
window.draw(up, rstates);
}
}
}; // namespace ctb
18 changes: 10 additions & 8 deletions src/custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct key {
return false;
}

void draw() {
window.draw(sprite);
void draw(const sf::RenderStates& rstates) {
window.draw(sprite, rstates);
timer = clock();
}
};
Expand Down Expand Up @@ -85,7 +85,7 @@ struct key_container {
}
}

void draw() {
void draw(const sf::RenderStates& rstates) {
bool is_any_key_pressed = false;
for (int i = 0; i < keys.size(); i++) {
key& current_key = keys[i];
Expand All @@ -101,7 +101,7 @@ struct key_container {
}
if (!is_any_key_pressed) {
key_state = -1;
window.draw(default_sprite);
window.draw(default_sprite, rstates);
}
if (key_state > -1) {
key& on_key = keys[key_state];
Expand All @@ -112,9 +112,9 @@ struct key_container {
}
}
if ((clock() - last_press) / CLOCKS_PER_SEC > BONGO_KEYPRESS_THRESHOLD) {
on_key.draw();
on_key.draw(rstates);
} else {
window.draw(default_sprite);
window.draw(default_sprite, rstates);
}
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ bool init() {
return true;
}

void draw() {
void draw(const sf::RenderStates& rstates) {
window.draw(bg);

if (is_mouse) {
Expand All @@ -181,6 +181,8 @@ void draw() {
int x_paw_start = paw_draw_info["pawStartingPoint"][0].asInt();
int y_paw_start = paw_draw_info["pawStartingPoint"][1].asInt();
auto [x, y] = input::get_xy();
// Add extra custom height from the base height this bezier calculation is based on
y += data::cfg["decoration"]["window_height"].asInt() - BASE_HEIGHT;
int oof = 6;
std::vector<double> pss = {(float) x_paw_start, (float) y_paw_start};
double dist = hypot(x_paw_start - x, y_paw_start - y);
Expand Down Expand Up @@ -325,7 +327,7 @@ void draw() {
}

for (key_container& current : key_containers) {
current.draw();
current.draw(rstates);
}

// drawing mouse at the bottom
Expand Down
2 changes: 2 additions & 0 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void create_config() {
"verticalPosition": 0
},
"decoration": {
"window_width": 612,
"window_height": 352,
"leftHanded": false,
"rgb": [255, 255, 255],
"offsetX": [0, 11],
Expand Down
2 changes: 1 addition & 1 deletion src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool init() {
}

// initialize debug resource
debugBackground.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
debugBackground.setSize(sf::Vector2f(data::cfg["decoration"]["window_width"].asInt(), data::cfg["decoration"]["window_height"].asInt()));
debugBackground.setFillColor(sf::Color(0, 0, 0, 128));

debugText.setFont(debugFont);
Expand Down
24 changes: 16 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ int main(int argc, char ** argv) {
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#endif

window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Bongo Cat for osu!", sf::Style::Titlebar | sf::Style::Close);
window.setFramerateLimit(MAX_FRAMERATE);

// loading configs
while (!data::init()) {
continue;
}

Json::Value windowWidth = data::cfg["decoration"]["window_width"];
Json::Value windowHeight = data::cfg["decoration"]["window_height"];
window.create(sf::VideoMode(windowWidth.asInt(), windowHeight.asInt()), "Bongo Cat for osu!", sf::Style::Titlebar | sf::Style::Close);
window.setFramerateLimit(MAX_FRAMERATE);


// initialize input
if (!input::init()) {
return EXIT_FAILURE;
Expand Down Expand Up @@ -67,22 +70,27 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
int blue_value = rgb[2].asInt();
int alpha_value = rgb.size() == 3 ? 255 : rgb[3].asInt();

// Translation for artifacts when resize is applied
sf::Transform transform = sf::Transform();
transform.translate(0, windowHeight.asInt()-BASE_HEIGHT);
sf::RenderStates rstates = sf::RenderStates(transform);

window.clear(sf::Color(red_value, green_value, blue_value, alpha_value));
switch (mode) {
case 1:
osu::draw();
osu::draw(rstates);
break;
case 2:
taiko::draw();
taiko::draw(rstates);
break;
case 3:
ctb::draw();
ctb::draw(rstates);
break;
case 4:
mania::draw();
mania::draw(rstates);
break;
case 5:
custom::draw();
custom::draw(rstates);
}

if (is_show_input_debug) {
Expand Down
50 changes: 25 additions & 25 deletions src/mania.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,107 +56,107 @@ bool init() {
return true;
}

void draw_4K() {
void draw_4K(const sf::RenderStates& rstates) {
window.draw(bg);

int left_cnt = 0, right_cnt = 0;
int left_sum = 0, right_sum = 0;

for (int i = 0; i < 2; i++) {
if (input::is_pressed(left_key_value_4K[i])) {
window.draw(left_4K[i]);
window.draw(left_4K[i], rstates);
left_cnt++;
left_sum += i;
}
if (input::is_pressed(right_key_value_4K[i])) {
window.draw(right_4K[i]);
window.draw(right_4K[i], rstates);
right_cnt++;
right_sum += i;
}
}

// draw left hand
if (left_cnt == 0) {
window.draw(left_handup);
window.draw(left_handup, rstates);
} else {
double avg = 1.0 * left_sum / left_cnt;
if (avg == 0) {
window.draw(left_hand[0]);
window.draw(left_hand[0], rstates);
} else if (avg == 0.5) {
window.draw(left_hand[1]);
window.draw(left_hand[1], rstates);
} else {
window.draw(left_hand[2]);
window.draw(left_hand[2], rstates);
}
}

// draw right hand
if (right_cnt == 0) {
window.draw(right_handup);
window.draw(right_handup, rstates);
} else {
double avg = 1.0 * right_sum / right_cnt;
if (avg == 0) {
window.draw(right_hand[0]);
window.draw(right_hand[0], rstates);
} else if (avg == 0.5) {
window.draw(right_hand[1]);
window.draw(right_hand[1], rstates);
} else {
window.draw(right_hand[2]);
window.draw(right_hand[2], rstates);
}
}
}

void draw_7K() {
void draw_7K(const sf::RenderStates& rstates) {
window.draw(bg);

int left_cnt = 0, right_cnt = 0;
int left_sum = 0, right_sum = 0;

for (int i = 0; i < 4; i++) {
if (input::is_pressed(left_key_value_7K[i])) {
window.draw(left_7K[i]);
window.draw(left_7K[i], rstates);
left_cnt++;
left_sum += i;
}
if (input::is_pressed(right_key_value_7K[i])) {
window.draw(right_7K[i]);
window.draw(right_7K[i], rstates);
right_cnt++;
right_sum += i;
}
}

// draw left hand
if (left_cnt == 0) {
window.draw(left_handup);
window.draw(left_handup, rstates);
} else {
double avg = 1.0 * left_sum / left_cnt;
if (avg < 1.0) {
window.draw(left_hand[0]);
window.draw(left_hand[0], rstates);
} else if (avg <= 2.0) {
window.draw(left_hand[1]);
window.draw(left_hand[1], rstates);
} else {
window.draw(left_hand[2]);
window.draw(left_hand[2], rstates);
}
}

// draw right hand
if (right_cnt == 0) {
window.draw(right_handup);
window.draw(right_handup, rstates);
} else {
double avg = 1.0 * right_sum / right_cnt;
if (avg < 1.0) {
window.draw(right_hand[0]);
window.draw(right_hand[0], rstates);
} else if (avg <= 2.0) {
window.draw(right_hand[1]);
window.draw(right_hand[1], rstates);
} else {
window.draw(right_hand[2]);
window.draw(right_hand[2], rstates);
}
}
}

void draw() {
void draw(const sf::RenderStates& rstates) {
if (is_4K) {
draw_4K();
draw_4K(rstates);
} else {
draw_7K();
draw_7K(rstates);
}
}
}; // namespace mania
Loading