Improve things
This commit is contained in:
65
util/texteditor.h
Normal file
65
util/texteditor.h
Normal file
@@ -0,0 +1,65 @@
|
||||
///
|
||||
// Created by bruno on 5.2.2025.
|
||||
///
|
||||
|
||||
#ifndef RISCB_TEXTEDITOR_H
|
||||
#define RISCB_TEXTEDITOR_H
|
||||
|
||||
#define MAX_LINE_WIDTH 34 // Max chars per line (excluding '\0')
|
||||
#define MAX_LINES_ASM 100 // Max number of lines
|
||||
#define MAX_LINES_DISPLAY 10 // Max number of lines
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include "font.h"
|
||||
|
||||
typedef struct {
|
||||
char text[MAX_LINE_WIDTH + 1]; // +1 for null terminator
|
||||
int active; // Flag to check if the line is in use
|
||||
} Line;
|
||||
|
||||
typedef struct {
|
||||
Line lines[MAX_LINES_ASM]; // Array of lines
|
||||
int line_count; // Number of active lines
|
||||
int cursor_line; // Current cursor line
|
||||
int cursor_line_offset; // Current cursor line
|
||||
int cursor_pos; // Current cursor position in line
|
||||
char outputString[MAX_LINE_WIDTH * MAX_LINES_ASM];
|
||||
char displayString[MAX_LINE_WIDTH * MAX_LINES_DISPLAY];
|
||||
SDL_Rect rect;
|
||||
SDL_Rect outRect;
|
||||
SDL_Texture *texture;
|
||||
bool readOnly;
|
||||
BitmapFont *font;
|
||||
} TextEditor;
|
||||
|
||||
// Initialize the text editor
|
||||
void init_editor(TextEditor *editor, BitmapFont *font, int x, int y, SDL_Renderer *renderer);
|
||||
|
||||
// Insert a new line at a specific position
|
||||
void insert_line(TextEditor *editor, int position, const char *text);
|
||||
|
||||
// Insert a new line at a specific position
|
||||
void insert_line_rel(TextEditor *editor);
|
||||
|
||||
void editor_render(TextEditor *editor, SDL_Renderer * renderer);
|
||||
|
||||
// Insert a character at the current cursor position
|
||||
void insert_character(TextEditor *editor, char ch, SDL_Renderer *renderer);
|
||||
|
||||
// Move cursor (handled externally)
|
||||
void move_cursor(TextEditor *editor, int new_line, int new_pos);
|
||||
|
||||
// Move cursor (handled externally)
|
||||
void move_cursor_relative(TextEditor *editor, int line_offset, int pos_offset);
|
||||
|
||||
// Generate a string from a given offset with a max line count
|
||||
void generate_string_display(TextEditor *editor, SDL_Renderer *renderer);
|
||||
|
||||
void generate_string(TextEditor *editor);
|
||||
|
||||
#endif //RISCB_TEXTEDITOR_H
|
Reference in New Issue
Block a user