fullscreen button

This commit is contained in:
ohsqueezy 2023-12-05 17:57:55 -05:00
parent 26c5312567
commit 0121b33cbe
5 changed files with 48 additions and 18 deletions

View File

@ -62,7 +62,8 @@
"hue shift": 10.0,
"hue shift frequency": 0.025,
"flash length": 1.1,
"flash darken factor": 2.0
"flash darken factor": 2.0,
"fullscreen enabled": true
},
"configuration":
@ -257,7 +258,11 @@
"character dimensions": [60.0, 80.0],
"character scale": [0.2, 0.15],
"character y": -0.5
}
},
"fullscreen texture": "resource/fullscreen.png",
"fullscreen translation": [-1.45, -0.85],
"fullscreen scale": 0.07,
"fullscreen scale ratio": 0.75
},
"world": [

2
lib/sb

@ -1 +1 @@
Subproject commit a6a110141d3e6bfbc66a7b6065a3199c76ba8ae9
Subproject commit fb68938889ce200fc8623a5608d3c7adb58a9b34

BIN
resource/fullscreen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -702,6 +702,19 @@ void Cakefoot::set_up_buttons()
set_up_buttons();
});
}
/* Set up fullscreen button */
sb::Texture fullscreen_texture {configuration()("button", "fullscreen texture").get<std::string>()};
fullscreen_texture.load();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
sb::Plane fullscreen_plane;
fullscreen_plane.texture(fullscreen_texture);
button.at("fullscreen") = sb::Pad<>{fullscreen_plane, configuration()("button", "fullscreen translation"), configuration()("button", "fullscreen scale"),
configuration()("button", "fullscreen scale ratio")};
button.at("fullscreen").on_state_change([&](bool state){
display.toggle_fullscreen();
});
}
void Cakefoot::toggle_challenge()
@ -1767,18 +1780,23 @@ void Cakefoot::respond(SDL_Event& event)
}
}
/* Always collide with volume button */
if ((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEMOTION) && button.at("volume").collide(mouse_ndc, view, projection))
/* Always collide with volume button and fullscreen if enabled */
for (const std::string& name : {"volume", "fullscreen"})
{
if (event.type == SDL_MOUSEBUTTONDOWN)
if (name != "fullscreen" || configuration()("display", "fullscreen enabled"))
{
button.at("volume").press();
}
else
{
hovering = true;
}
}
if ((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEMOTION) && button.at(name).collide(mouse_ndc, view, projection))
{
if (event.type == SDL_MOUSEBUTTONDOWN)
{
button.at(name).press();
}
else
{
hovering = true;
}
break;
} } }
/* Set the cursor image appropriately */
if (hovering && SDL_GetCursor() == SDL_GetDefaultCursor())
@ -2282,10 +2300,16 @@ void Cakefoot::update(float timestamp)
button.at("play").draw(uniform["mvp"], view, projection, uniform["texture enabled"]);
}
/* Always draw the volume button */
sb::Plane::position->bind("vertex_position", shader_program);
sb::Plane::color->bind("vertex_color", shader_program);
button.at("volume").draw(uniform["mvp"], view, projection, uniform["texture enabled"]);
/* Always draw the volume and fullscreen buttons if enabled */
for (const std::string& name : {"volume", "fullscreen"})
{
if (name != "fullscreen" || configuration()("display", "fullscreen enabled"))
{
sb::Plane::position->bind("vertex_position", shader_program);
sb::Plane::color->bind("vertex_color", shader_program);
button.at(name).draw(uniform["mvp"], view, projection, uniform["texture enabled"]);
}
}
/* Update display */
SDL_GL_SwapWindow(window());

View File

@ -221,7 +221,8 @@ private:
{"name 2 decrement", sb::Pad<>()},
{"name 3", sb::Pad<>()},
{"name 3 increment", sb::Pad<>()},
{"name 3 decrement", sb::Pad<>()}
{"name 3 decrement", sb::Pad<>()},
{"fullscreen", sb::Pad<>()}
};
std::shared_ptr<TTF_Font> large_font {font(configuration()("display", "default font path").get<std::string>(), 72)},
small_font {font(configuration()("display", "default font path").get<std::string>(), 12)};