Skip to content
Merged
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
26 changes: 18 additions & 8 deletions src/core/emu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,36 @@ int32_t emu_main(options_config *config, ui_scale *scale) {

while (!IsKeyPressed(KEY_ESCAPE)) {
BeginDrawing();
ClearBackground(BLACK);

if (IsWindowResized()) {
config->display_scaling = GetScreenWidth() / DISPLAY_WIDTH;
config->display_scaling = (uint32_t) fminf(GetScreenWidth() / (float) DISPLAY_WIDTH,
GetScreenHeight() / (float) DISPLAY_HEIGHT);

scale->window_width = DISPLAY_WIDTH * config->display_scaling;
scale->window_height = DISPLAY_HEIGHT * config->display_scaling;
SetWindowSize(scale->window_width, scale->window_height);

scale->button_width = (float) (scale->window_width / 4.8);
scale->button_height = (float) ((float) scale->window_height / 16);
scale->button_x = (float) ((float) scale->window_width / 2 - (scale->window_width / 9.6));
scale->font_size = (scale->window_height / 12);
scale->button_width = (float) (GetScreenWidth() / 4.8);
scale->button_height = (float) ((float) GetScreenHeight() / 16);
scale->button_x = (float) ((float) GetScreenWidth() / 2 - (GetScreenWidth() / 9.6));
scale->font_size = (GetScreenWidth() / (int32_t) config->display_scaling);
}

UnloadDroppedFiles(LoadDroppedFiles());

// Draw Pixels from virtual Texture
DrawTextureEx(chip8.display, (Vector2) {0, 0}, 0, (float) config->display_scaling, WHITE);
DrawTexturePro(chip8.display, (Rectangle) {0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT},
(Rectangle) {(GetScreenWidth() - scale->window_width) / 2,
(GetScreenHeight() - scale->window_height) / 2, scale->window_width,
scale->window_height}, (Vector2) {0, 0}, 0, WHITE);

DrawRectangleLines(((GetScreenWidth() - scale->window_width) / 2),
(((GetScreenHeight() - scale->window_height) / 2)), scale->window_width,
scale->window_height, DARKGRAY);

if (config->show_fps) {
DrawText(TextFormat("%dhz", GetFPS() + 1), (int32_t) config->display_scaling, (int32_t) config->display_scaling / 2,
DrawText(TextFormat("%dhz", GetFPS() + 1), (int32_t) config->display_scaling,
(int32_t) config->display_scaling / 2,
(int32_t) (GetScreenHeight() / (config->display_scaling * 1.5)), DARKGREEN);
}

Expand Down
41 changes: 21 additions & 20 deletions src/gui/main_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ void main_window(options_config *config) {
InitWindow(scale.window_width, scale.window_height, WINDOW_TITLE VERSION);

scale.button_width = (float) (scale.window_width / 4.8);
scale.button_height = (float) ((float) scale.window_height / 16);
scale.button_height = (float) ((float) GetScreenHeight() / 16);
scale.button_x = (float) ((float) scale.window_width / 2 - (scale.window_width / 9.6));

scale.font_size = (scale.window_height / 12);
scale.font_size = (GetScreenHeight() / (int32_t)config->display_scaling);
GuiLoadStyleDark();

enum menu_state_counter {
Expand All @@ -70,15 +70,16 @@ void main_window(options_config *config) {
ClearBackground(BLACK);

if (IsWindowResized()) {
config->display_scaling = GetScreenWidth() / DISPLAY_WIDTH;
config->display_scaling = (uint32_t) fminf(GetScreenWidth() / (float) DISPLAY_WIDTH,
GetScreenHeight() / (float) DISPLAY_HEIGHT);

scale.window_width = DISPLAY_WIDTH * config->display_scaling;
scale.window_height = DISPLAY_HEIGHT * config->display_scaling;
SetWindowSize(scale.window_width, scale.window_height);

scale.button_width = (float) (scale.window_width / 4.8);
scale.button_height = (float) ((float) scale.window_height / 16);
scale.button_x = (float) ((float) scale.window_width / 2 - (scale.window_width / 9.6));
scale.font_size = (scale.window_height / 12);
scale.button_width = (float) (GetScreenWidth() / 4.8);
scale.button_height = (float) ((float) GetScreenHeight() / 16);
scale.button_x = (float) ((float) GetScreenWidth() / 2 - (GetScreenWidth() / 9.6));
scale.font_size = (GetScreenWidth() / (int32_t) config->display_scaling);
}

if (IsFileDropped()) { // Initialize Emulation
Expand All @@ -92,22 +93,22 @@ void main_window(options_config *config) {
switch (menu_state) {
/*-------------------------------------------------------------------------------------------------------------*/
case (normal):
DrawText("Chisel8 Emulator", scale.window_width / 2 - (scale.font_size * 4), (scale.window_height / 12),
DrawText("Chisel8 Emulator", GetScreenWidth() / 2 - (scale.font_size * 4), (GetScreenHeight() / 12),
scale.font_size, RAYWHITE);

if (GuiButton((Rectangle) {scale.button_x, scale.window_height / 2 - scale.window_height / 6 - 10,
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() / 2 - GetScreenHeight() / 6 - 10,
scale.button_width, scale.button_height},
GuiIconText(ICON_CPU, "Load ROM"))) {
menu_state = init;
}

if (GuiButton((Rectangle) {scale.button_x, scale.window_height / 2 - scale.window_height / 16,
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() / 2 - GetScreenHeight() / 16,
scale.button_width, scale.button_height},
GuiIconText(ICON_GEAR, "Settings"))) {
menu_state = options;
}

if (GuiButton((Rectangle) {scale.button_x, scale.window_height - (scale.window_height / 6),
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() - (GetScreenHeight() / 6),
scale.button_width, scale.button_height},
GuiIconText(ICON_EXIT, "Quit"))) {
EndDrawing();
Expand All @@ -122,25 +123,25 @@ void main_window(options_config *config) {
// TODO: Call function from options_window source file and actually add options to choose from
// TODO: Should allow the user to change the window scaling and other options...

DrawText("Settings", scale.window_width / 2 - (scale.font_size * 2), (scale.window_height / 12),
DrawText("Settings", GetScreenWidth() / 2 - (scale.font_size * 2), (GetScreenHeight() / 12),
scale.font_size, RAYWHITE);

if (config->volume != 0) {
if (GuiButton((Rectangle) {scale.button_x, scale.window_height - (scale.window_height / 2),
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() - (GetScreenHeight() / 2),
scale.button_width, scale.button_height},
GuiIconText(ICON_AUDIO, "Mute Audio"))) {
temp = config->volume;
config->volume = 0.0f;
}
} else {
if (GuiButton((Rectangle) {scale.button_x, scale.window_height - (scale.window_height / 2),
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() - (GetScreenHeight() / 2),
scale.button_width, scale.button_height},
GuiIconText(ICON_AUDIO, "Unmute Audio"))) {
config->volume = temp;
}
}

if (GuiButton((Rectangle) {scale.button_x, scale.window_height - (scale.window_height / 6),
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() - (GetScreenHeight() / 6),
scale.button_width, scale.button_height},
GuiIconText(ICON_REREDO_FILL, "Return"))) {
menu_state = normal;
Expand All @@ -151,12 +152,12 @@ void main_window(options_config *config) {
/*-------------------------------------------------------------------------------------------------------------*/

case (init):
DrawRectangle(0, 0, scale.window_width, scale.window_height, Fade(RAYWHITE, 0.2f));
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.2f));
DrawText("Please drag a ROM file into the window",
scale.window_width / 2 - (scale.font_size * 10) + (scale.font_size / 2),
(scale.window_height / 2) - scale.font_size * 1.5, scale.font_size, RAYWHITE);
GetScreenWidth() / 2 - (scale.font_size * 10) + (scale.font_size / 2),
(GetScreenHeight() / 2) - scale.font_size * 1.5, scale.font_size, RAYWHITE);

if (GuiButton((Rectangle) {scale.button_x, scale.window_height - (scale.window_height / 6),
if (GuiButton((Rectangle) {scale.button_x, GetScreenHeight() - (GetScreenHeight() / 6),
scale.button_width, scale.button_height},
GuiIconText(ICON_REREDO_FILL, "Return"))) {
menu_state = normal;
Expand Down