Improve things
This commit is contained in:
62
main.c
62
main.c
@@ -3,6 +3,7 @@
|
||||
#include <threads.h>
|
||||
#include "util/font.h"
|
||||
#include "assembler/assembler.h"
|
||||
#include "util/texteditor.h"
|
||||
|
||||
//Screen dimension constants
|
||||
const int SCREEN_WIDTH = 1280;
|
||||
@@ -16,15 +17,19 @@ SDL_Window *window = NULL;
|
||||
//The surface contained by the window
|
||||
SDL_Renderer *renderer = NULL;
|
||||
|
||||
SDL_Rect rect1;
|
||||
|
||||
BitmapFont smallFont;
|
||||
|
||||
CPU cpu;
|
||||
|
||||
TextEditor codeEditor;
|
||||
|
||||
TextEditor *activeEditor;
|
||||
|
||||
char programString[65535];
|
||||
|
||||
int init() {
|
||||
|
||||
|
||||
//Initialize SDL
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
||||
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
|
||||
@@ -52,13 +57,19 @@ int init() {
|
||||
return 1;
|
||||
}
|
||||
smallFont = prepText(renderer, 10, "../PublicPixel.ttf", 255, 255, 255, 255);
|
||||
init_editor(&codeEditor, &smallFont, 50, 50, renderer);
|
||||
activeEditor = &codeEditor;
|
||||
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0);
|
||||
generate_string_display(&codeEditor, renderer);
|
||||
init_cpu(&cpu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Rect rect1;
|
||||
SDL_Rect rect2;
|
||||
|
||||
int render() {
|
||||
SDL_SetRenderDrawColor(renderer, 128, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
@@ -70,10 +81,7 @@ int render() {
|
||||
rect1.h = 10;
|
||||
SDL_RenderFillRect(renderer, &rect1);
|
||||
|
||||
char textTemp[12];
|
||||
sprintf(textTemp, "%d", rect1.x);
|
||||
|
||||
renderText(renderer, smallFont, textTemp, 100, 100);
|
||||
editor_render(&codeEditor, renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
return 0;
|
||||
@@ -85,9 +93,49 @@ int processEvent(SDL_Event e) {
|
||||
int newWidth = e.window.data1;
|
||||
int newHeight = e.window.data2;
|
||||
|
||||
// Adjust the viewport to match the new window size
|
||||
// Adjust the viewport to match the new window size;
|
||||
SDL_Rect viewport = {0, 0, newWidth, newHeight};
|
||||
SDL_RenderSetViewport(renderer, &viewport);
|
||||
} else if (e.type == SDL_KEYDOWN) {
|
||||
int keySym = e.key.keysym.sym;
|
||||
switch (keySym) {
|
||||
case SDLK_UP:
|
||||
if (activeEditor) {
|
||||
move_cursor_relative(activeEditor, -1, 0);
|
||||
}
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
if (activeEditor) {
|
||||
move_cursor_relative(activeEditor, 1, 0);
|
||||
}
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
if (activeEditor) {
|
||||
move_cursor_relative(activeEditor, 0, -1);
|
||||
}
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if (activeEditor) {
|
||||
move_cursor_relative(activeEditor, 0, 1);
|
||||
}
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_RETURN2:
|
||||
if (activeEditor && !activeEditor->readOnly) {
|
||||
insert_line_rel(activeEditor);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (activeEditor && !activeEditor->readOnly) {
|
||||
if (keySym >= 32 && keySym <= 126) {
|
||||
if (keySym > 0x60 && keySym < 0x7b) {
|
||||
keySym -= 0x20;
|
||||
}
|
||||
insert_character(activeEditor, (keySym & 0xff), renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user