Update
This commit is contained in:
132
main.c
132
main.c
@@ -56,7 +56,7 @@ int init() {
|
||||
printf("Renderer could not be created SDL_Error: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
smallFont = prepText(renderer, 10, "../PublicPixel.ttf", 255, 255, 255, 255);
|
||||
smallFont = prepText(renderer, 12, "../PublicPixel.ttf", 255, 255, 255, 255);
|
||||
init_editor(&codeEditor, &smallFont, 50, 50, renderer);
|
||||
activeEditor = &codeEditor;
|
||||
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
@@ -87,6 +87,128 @@ int render() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Keycode ConvertKPToNonKP(SDL_Keycode keycode) {
|
||||
switch (keycode) {
|
||||
case SDLK_KP_0:
|
||||
return SDLK_0;
|
||||
case SDLK_KP_1:
|
||||
return SDLK_1;
|
||||
case SDLK_KP_2:
|
||||
return SDLK_2;
|
||||
case SDLK_KP_3:
|
||||
return SDLK_3;
|
||||
case SDLK_KP_4:
|
||||
return SDLK_4;
|
||||
case SDLK_KP_5:
|
||||
return SDLK_5;
|
||||
case SDLK_KP_6:
|
||||
return SDLK_6;
|
||||
case SDLK_KP_7:
|
||||
return SDLK_7;
|
||||
case SDLK_KP_8:
|
||||
return SDLK_8;
|
||||
case SDLK_KP_9:
|
||||
return SDLK_9;
|
||||
case SDLK_KP_PERIOD:
|
||||
return SDLK_PERIOD;
|
||||
case SDLK_KP_COMMA:
|
||||
return SDLK_COMMA;
|
||||
case SDLK_KP_DIVIDE:
|
||||
return SDLK_SLASH;
|
||||
case SDLK_KP_MULTIPLY:
|
||||
return SDLK_ASTERISK;
|
||||
case SDLK_KP_MINUS:
|
||||
return SDLK_MINUS;
|
||||
case SDLK_KP_PLUS:
|
||||
return SDLK_PLUS;
|
||||
case SDLK_KP_ENTER:
|
||||
return SDLK_RETURN;
|
||||
case SDLK_KP_EQUALS:
|
||||
return SDLK_EQUALS;
|
||||
case SDLK_KP_LEFTPAREN:
|
||||
return SDLK_LEFTPAREN;
|
||||
case SDLK_KP_RIGHTPAREN:
|
||||
return SDLK_RIGHTPAREN;
|
||||
case SDLK_KP_LEFTBRACE:
|
||||
return SDLK_LEFTBRACKET;
|
||||
case SDLK_KP_RIGHTBRACE:
|
||||
return SDLK_RIGHTBRACKET;
|
||||
case SDLK_KP_TAB:
|
||||
return SDLK_TAB;
|
||||
case SDLK_KP_BACKSPACE:
|
||||
return SDLK_BACKSPACE;
|
||||
case SDLK_KP_A:
|
||||
return SDLK_a;
|
||||
case SDLK_KP_B:
|
||||
return SDLK_b;
|
||||
case SDLK_KP_C:
|
||||
return SDLK_c;
|
||||
case SDLK_KP_D:
|
||||
return SDLK_d;
|
||||
case SDLK_KP_E:
|
||||
return SDLK_e;
|
||||
case SDLK_KP_F:
|
||||
return SDLK_f;
|
||||
case SDLK_KP_XOR:
|
||||
return SDLK_CARET;
|
||||
case SDLK_KP_PERCENT:
|
||||
return SDLK_PERCENT;
|
||||
case SDLK_KP_LESS:
|
||||
return SDLK_LESS;
|
||||
case SDLK_KP_GREATER:
|
||||
return SDLK_GREATER;
|
||||
case SDLK_KP_AMPERSAND:
|
||||
return SDLK_AMPERSAND;
|
||||
case SDLK_KP_DBLAMPERSAND:
|
||||
return SDLK_AMPERSAND; // No direct match, best alternative
|
||||
case SDLK_KP_VERTICALBAR:
|
||||
return SDLK_BACKSLASH; // Vertical bar alternative
|
||||
case SDLK_KP_DBLVERTICALBAR:
|
||||
return SDLK_BACKSLASH; // No direct match
|
||||
case SDLK_KP_COLON:
|
||||
return SDLK_COLON;
|
||||
case SDLK_KP_HASH:
|
||||
return SDLK_HASH;
|
||||
case SDLK_KP_SPACE:
|
||||
return SDLK_SPACE;
|
||||
case SDLK_KP_AT:
|
||||
return SDLK_AT;
|
||||
case SDLK_KP_EXCLAM:
|
||||
return SDLK_EXCLAIM;
|
||||
case SDLK_KP_MEMSTORE:
|
||||
return SDLK_UNKNOWN; // No direct match
|
||||
case SDLK_KP_MEMRECALL:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_MEMCLEAR:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_MEMADD:
|
||||
return SDLK_PLUS;
|
||||
case SDLK_KP_MEMSUBTRACT:
|
||||
return SDLK_MINUS;
|
||||
case SDLK_KP_MEMMULTIPLY:
|
||||
return SDLK_ASTERISK;
|
||||
case SDLK_KP_MEMDIVIDE:
|
||||
return SDLK_SLASH;
|
||||
case SDLK_KP_PLUSMINUS:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_CLEAR:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_CLEARENTRY:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_BINARY:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_OCTAL:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_DECIMAL:
|
||||
return SDLK_UNKNOWN;
|
||||
case SDLK_KP_HEXADECIMAL:
|
||||
return SDLK_UNKNOWN;
|
||||
default:
|
||||
return keycode; // If it's not a KP key, return it unchanged
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int processEvent(SDL_Event e) {
|
||||
if (e.type == SDL_QUIT) { return 0; }
|
||||
else if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
@@ -97,7 +219,7 @@ int processEvent(SDL_Event e) {
|
||||
SDL_Rect viewport = {0, 0, newWidth, newHeight};
|
||||
SDL_RenderSetViewport(renderer, &viewport);
|
||||
} else if (e.type == SDL_KEYDOWN) {
|
||||
int keySym = e.key.keysym.sym;
|
||||
int keySym = ConvertKPToNonKP(e.key.keysym.sym);
|
||||
switch (keySym) {
|
||||
case SDLK_UP:
|
||||
if (activeEditor) {
|
||||
@@ -122,18 +244,20 @@ int processEvent(SDL_Event e) {
|
||||
case SDLK_RETURN:
|
||||
case SDLK_RETURN2:
|
||||
if (activeEditor && !activeEditor->readOnly) {
|
||||
insert_line_rel(activeEditor);
|
||||
insert_line_rel(activeEditor, renderer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (activeEditor && !activeEditor->readOnly) {
|
||||
if (activeEditor && !activeEditor->readOnly && activeEditor->cursor_pos < MAX_LINE_WIDTH) {
|
||||
if (keySym >= 32 && keySym <= 126) {
|
||||
if (keySym > 0x60 && keySym < 0x7b) {
|
||||
keySym -= 0x20;
|
||||
}
|
||||
insert_character(activeEditor, (keySym & 0xff), renderer);
|
||||
} else if (keySym == SDLK_BACKSPACE || keySym == SDLK_DELETE) {
|
||||
remove_character(activeEditor, renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user