Fix the scaling and add nonthreaded
This commit is contained in:
27
main.c
27
main.c
@@ -218,15 +218,15 @@ int init() {
|
||||
|
||||
SDL_PauseAudioDevice(dev, 0);
|
||||
|
||||
init_seven_segment(&displayA, renderer, 480, 240, 60, 120);
|
||||
init_seven_segment(&displayB, renderer, 545, 240, 60, 120);
|
||||
init_seven_segment(&displayC, renderer, 610, 240, 60, 120);
|
||||
init_seven_segment(&displayD, renderer, 675, 240, 60, 120);
|
||||
init_seven_segment(&displayA, renderer, 477, 240, 60, 120);
|
||||
init_seven_segment(&displayB, renderer, 542, 240, 60, 120);
|
||||
init_seven_segment(&displayC, renderer, 607, 240, 60, 120);
|
||||
init_seven_segment(&displayD, renderer, 672, 240, 60, 120);
|
||||
|
||||
init_seven_segment(&displayE, renderer, 480, 375, 60, 120);
|
||||
init_seven_segment(&displayF, renderer, 545, 375, 60, 120);
|
||||
init_seven_segment(&displayG, renderer, 610, 375, 60, 120);
|
||||
init_seven_segment(&displayH, renderer, 675, 375, 60, 120);
|
||||
init_seven_segment(&displayE, renderer, 477, 375, 60, 120);
|
||||
init_seven_segment(&displayF, renderer, 542, 375, 60, 120);
|
||||
init_seven_segment(&displayG, renderer, 607, 375, 60, 120);
|
||||
init_seven_segment(&displayH, renderer, 672, 375, 60, 120);
|
||||
|
||||
init_switches(&switchesA, renderer, 500, 500, 100, 100);
|
||||
init_switches(&switchesB, renderer, 625, 500, 100, 100);
|
||||
@@ -644,10 +644,19 @@ int processEvent(SDL_Event e) {
|
||||
}
|
||||
}
|
||||
} else if (e.type == SDL_MOUSEBUTTONDOWN) {
|
||||
SDL_Rect viewport;
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
|
||||
SDL_Rect mouset;
|
||||
mouset.w = 1;
|
||||
mouset.h = 1;
|
||||
SDL_GetMouseState(&mouset.x, &mouset.y);
|
||||
// Translate mouse coordinates to viewport space
|
||||
SDL_Rect mouse;
|
||||
mouse.w = 1;
|
||||
mouse.h = 1;
|
||||
SDL_GetMouseState(&mouse.x, &mouse.y);
|
||||
mouse.x = ((mouset.x - viewport.x) * SCREEN_WIDTH) / viewport.w;
|
||||
mouse.y = (mouset.y - viewport.y) * SCREEN_HEIGHT / viewport.h;
|
||||
toggle_switch(mouse, &switchesA);
|
||||
toggle_switch(mouse, &switchesB);
|
||||
toggle_switch(mouse, &switchesC);
|
||||
|
@@ -72,15 +72,15 @@ void init_switches(Switches *switches, SDL_Renderer *renderer, int x, int y, int
|
||||
|
||||
switches->rect->x = 0;
|
||||
switches->rect->y = 0;
|
||||
switches->rect->w = width;
|
||||
switches->rect->h = height;
|
||||
switches->rect->w = width + 2;
|
||||
switches->rect->h = height + 2;
|
||||
|
||||
switches->outRect->x = x;
|
||||
switches->outRect->y = y;
|
||||
switches->outRect->w = width;
|
||||
switches->outRect->h = height;
|
||||
switches->outRect->w = width + 2;
|
||||
switches->outRect->h = height + 2;
|
||||
|
||||
switches->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||
switches->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width + 2, height + 2);
|
||||
if (!switches->texture) {
|
||||
fprintf(stderr, "Failed to create texture: %s\n", SDL_GetError());
|
||||
exit(EXIT_FAILURE);
|
||||
|
@@ -77,7 +77,7 @@ void init_editor(TextEditor *editor, BitmapFont *font, int x, int y, SDL_Rendere
|
||||
editor->highlightedLineRect->x = 2;
|
||||
editor->highlightedLineRect->y = 2;
|
||||
editor->highlightedLineRect->w = editor->outRect->w - (2 * editor->highlightedLineRect->x);
|
||||
editor->highlightedLineRect->h = editor->font->size;
|
||||
editor->highlightedLineRect->h = editor->font->size + 1;
|
||||
|
||||
editor->cursorRect->x = 3 + editor->cursor_pos * font->size + editor->outRect->x;
|
||||
editor->cursorRect->y =
|
||||
@@ -333,16 +333,16 @@ void editor_render(TextEditor *editor, SDL_Renderer *renderer, CPU *cpu, uint8_t
|
||||
if (editorIndex == 0) {
|
||||
targetLine = cpu->addrToLineMapper[instrLine] - editor->cursor_line_offset;
|
||||
editor->highlightedLineRect->w = editor->rect->w - 1;
|
||||
editor->highlightedLineRect->x = 2;
|
||||
editor->highlightedLineRect->x = 0;
|
||||
}
|
||||
if (editorIndex == 1) {
|
||||
targetLine = (instrLine / 2) - editor->cursor_line_offset;
|
||||
editor->highlightedLineRect->w = (editor->rect->w / 5 * 2) - 2;
|
||||
editor->highlightedLineRect->w = (editor->rect->w / 5 * 2) - 8;
|
||||
editor->highlightedLineRect->x =
|
||||
2 + (11 * editor->font->size) + (instrLine % 2 ? (28 * editor->font->size) : 0);
|
||||
4 + (11 * editor->font->size) + (instrLine % 2 ? (28 * editor->font->size) : 0);
|
||||
|
||||
}
|
||||
editor->highlightedLineRect->y = 2 + ((editor->font->size + 1) * targetLine);
|
||||
editor->highlightedLineRect->y = 1 + ((editor->font->size + 1) * targetLine);
|
||||
SDL_Rect highlightedLineAbs = *editor->highlightedLineRect;
|
||||
highlightedLineAbs.x += editor->outRect->x;
|
||||
highlightedLineAbs.y += editor->outRect->y;
|
||||
|
Reference in New Issue
Block a user