Something is almost working
This commit is contained in:
@@ -1,67 +1,72 @@
|
||||
///
|
||||
//
|
||||
// Created by bruno on 5.2.2025.
|
||||
///
|
||||
|
||||
// Modified to use dynamic limits.
|
||||
//
|
||||
#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 <stdbool.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
|
||||
char *text; // Dynamically allocated string for this line
|
||||
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;
|
||||
Line *lines; // Dynamic array of lines
|
||||
int line_count; // Number of active lines
|
||||
int max_lines_asm; // Maximum number of lines (e.g. assembly lines)
|
||||
int max_line_width; // Maximum characters per line (excluding '\0')
|
||||
int max_lines_display; // Maximum number of lines for display
|
||||
|
||||
int cursor_line; // Current cursor line
|
||||
int cursor_line_offset; // Display offset (first line in the display)
|
||||
int cursor_pos; // Current cursor position in line
|
||||
|
||||
char *outputString; // Dynamically allocated output string (size: max_line_width * max_lines_asm + 1)
|
||||
char *displayString; // Dynamically allocated display string (size: max_line_width * max_lines_display + 1)
|
||||
SDL_Rect *rect;
|
||||
SDL_Rect *outRect;
|
||||
SDL_Texture *texture;
|
||||
bool readOnly;
|
||||
BitmapFont *font;
|
||||
SDL_Rect *cursorRect;
|
||||
} TextEditor;
|
||||
|
||||
// Initialize the text editor
|
||||
void init_editor(TextEditor *editor, BitmapFont *font, int x, int y, SDL_Renderer *renderer);
|
||||
// Initialize the text editor. The parameters max_line_width, max_lines_asm, and max_lines_display
|
||||
// determine the dynamic sizes for the text editor.
|
||||
void init_editor(TextEditor *editor, BitmapFont *font, int x, int y, SDL_Renderer *renderer,
|
||||
int max_line_width, int max_lines_asm, int max_lines_display, bool readOnly);
|
||||
|
||||
// Insert a new line at a specific position
|
||||
// Other function prototypes remain mostly unchanged but will use the dynamic limits:
|
||||
void insert_line(TextEditor *editor, int position, const char *text, SDL_Renderer *renderer);
|
||||
|
||||
// Insert a new line at a specific position
|
||||
void insert_line_rel(TextEditor *editor, SDL_Renderer *renderer);
|
||||
|
||||
void editor_render(TextEditor *editor, SDL_Renderer * renderer);
|
||||
void editor_render(TextEditor *editor, SDL_Renderer *renderer, bool isActive, bool cursorBlink);
|
||||
|
||||
void remove_character(TextEditor *editor, SDL_Renderer *renderer);
|
||||
void remove_character(TextEditor *editor, bool isDelete, 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);
|
||||
void move_cursor(TextEditor *editor, int new_line, int new_pos, bool keepPos, SDL_Renderer *renderer);
|
||||
|
||||
// Move cursor (handled externally)
|
||||
void move_cursor_relative(TextEditor *editor, int line_offset, int pos_offset);
|
||||
void move_cursor_relative(TextEditor *editor, int line_offset, int pos_offset, bool keepPos, SDL_Renderer *renderer);
|
||||
|
||||
// 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
|
||||
void fill_editor_from_string(TextEditor *editor, const char *content, SDL_Renderer *renderer);
|
||||
|
||||
// A cleanup function to free dynamically allocated memory.
|
||||
void destroy_editor(TextEditor *editor);
|
||||
|
||||
#endif // RISCB_TEXTEDITOR_H
|
||||
|
Reference in New Issue
Block a user