Browse Source

added psuedo code, started struct and function layouts

Iver 1 month ago
parent
commit
c7bf3ce36b

+ 6 - 0
.vscode/settings.json

@@ -0,0 +1,6 @@
+{
+    "files.associations": {
+        "*.cl": "opencl",
+        "headers": "c"
+    }
+}

BIN
LG example.xcf


BIN
fonts/times_new_roman.ttf


BIN
images/test_image.bmp


+ 129 - 0
src/headers/lemonguice.h

@@ -0,0 +1,129 @@
+#ifndef LEMON_GUICE_H
+#define LEMON_GUICE_H
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "../headers/sourparse.h"
+
+enum {
+    LG_WIDGET_TYPE_PANEL = 0,
+    LG_WIDGET_TYPE_TEXT = 1,
+    LG_WIDGET_TYPE_BUTTON = 2,
+    LG_WIDGET_TYPE_INPUT = 3,
+    LG_WIDGET_TYPE_IMAGE = 4,
+};
+
+enum {
+    LG_WIDGET_ALIGNMENT_LEFT = 0,
+    LG_WIDGET_ALIGNMENT_CENTER_HORIZONTAL = 1,
+    LG_WIDGET_ALIGNMENT_RIGHT = 2,
+    LG_WIDGET_ALIGNMENT_UP = 3,
+    LG_WIDGET_ALIGNMENT_CENTER_VERTICAL = 4,
+    LG_WIDGET_ALIGNMENT_DOWN = 5,
+};
+
+
+typedef struct {
+    uint32_t* image_data;
+    int width;
+    int height;
+} LG_image;
+
+typedef struct {
+    SP_font* font;
+} LG_font_face;
+
+typedef struct {
+    LG_font_face* font_face;
+    uint32_t font_size;
+    uint32_t font_color;
+    uint8_t flags; // e.g., use defualt kerning or custom
+    int32_t kerning;
+    uint8_t font_alignment; // left, center, right, top, bottom, et cetera
+} LG_font_style;
+
+typedef struct {
+    uint32_t background_color;
+    
+    uint32_t border_color;
+    uint32_t border_size;
+    uint32_t border_radius;
+    
+    int32_t width;
+    int32_t height;
+    
+    uint8_t widget_alignment_horizontal;
+    uint8_t widget_alignment_vertical;
+    
+    int32_t margin;
+    int32_t margin_left;  // specific margin directions 
+    int32_t margin_right; // should be -1 if auto
+    int32_t margin_top;
+    int32_t margin_bottom;
+    
+    int32_t padding;
+    int32_t padding_left;  // specific margin directions 
+    int32_t padding_right; // should be -1 if auto
+    int32_t padding_top;
+    int32_t padding_bottom;
+} LG_widget_style;
+
+typedef struct {
+    char* text;
+    LG_font_style* font_style;
+} LG_text_data;
+
+typedef struct {
+    LG_image* image;
+} LG_image_widget_data;
+
+typedef struct {
+    LG_text_data placeholder_text_data;
+    LG_text_data input_text_data;
+} LG_input_field_widget_data;
+
+typedef struct {
+    LG_text_data text_data;
+} LG_button_widget_data;
+
+typedef struct {
+    LG_text_data text_data;
+} LG_text_widget_data;
+
+typedef struct {
+    uint32_t type; // 0 panel, 1 text, 2 button, 3 input, 4 image
+    uint32_t id;
+    LG_image_widget_data image_widget_data;
+    LG_input_field_widget_data input_field_widget_data;
+    LG_button_widget_data button_widget_data;
+    LG_text_widget_data text_widget_data;
+    LG_widget_style* widget_style;
+    LG_widget** children;
+    uint32_t child_count;
+    LG_widget* parent;
+} LG_widget;
+
+typedef struct {
+    LG_font_face* default_font_face;    
+    LG_font_style* default_font_style;
+    LG_widget* default_widget;
+    uint32_t current_id;
+} LG_context;
+
+// functions
+
+LG_font_face* LG_new_font_face(char* filename);
+
+LG_font_style* LG_new_font_style();
+
+LG_widget* LG_new_window();
+
+LG_widget* LG_add_panel_widget(LG_widget* parent_widget);
+
+LG_widget* LG_add_text_widget(LG_widget* parent_widget);
+
+LG_widget* LG_add_button_widget(LG_widget* parent_widget);
+
+LG_image* LG_load_image(char* filename);
+
+#endif // LEMON_GUICE_H

+ 13 - 0
src/headers/pitmap.h

@@ -0,0 +1,13 @@
+#ifndef PITMAP_H
+#define PITMAP_H
+
+#include <stdint.h>
+
+typedef struct {
+    uint32_t* frame_buffer;
+    int width, height;
+} PM_image;
+
+PM_image* PM_load_image(char* filename, unsigned char debug_mode);
+
+#endif

+ 63 - 0
src/headers/sourparse.h

@@ -0,0 +1,63 @@
+#ifndef SOURPARSE_H
+#define SOURPARSE_H
+
+#include "stdint.h"
+
+typedef struct {
+    uint16_t left, right;
+    int16_t value; // kerning value for the above pair. If it's more than 0, the cahracters will be moved apart. If it's less than 0, the characters will be moved closer
+} SP_kerning_pair;
+
+typedef struct {
+    int16_t ascender;
+    int16_t descender;
+    int16_t line_gap;
+    uint16_t advance_max_width;
+    int16_t min_left_side_bearing;
+    int16_t min_right_side_bearing;
+    int16_t x_max_extent;
+    int16_t carat_slope_rise;
+    int16_t carat_slope_run;
+    int16_t carat_offset;
+    int16_t metric_data_format;
+    uint16_t number_of_h_metrics;
+} SP_hhea_table;
+
+typedef struct {
+    uint16_t advance_width;
+    int16_t left_side_bearing;
+} SP_long_hor_metric;
+
+typedef struct {
+    int scale_x, scale01, scale10, scale_y;
+    int glyph_index;
+    int16_t arg1, arg2;
+} SP_component;
+
+typedef struct {
+    int *x_coords, *y_coords, *contour_end_indicies; 
+    int number_of_points, number_of_contours, number_of_components;
+    int advance_width;
+    uint8_t *flags;
+    int16_t x_min, y_min, x_max, y_max;
+    SP_component *components;
+    int is_composite;
+} SP_glyph;
+
+typedef struct {
+    int current_byte, number_of_glyphs, number_of_kerning_pairs, *glyph_offsets; 
+    uint16_t *unicode_to_glyph_indicies;
+    float units_per_em;
+    uint8_t *buffer;
+    SP_glyph *glyphs;
+    int16_t index_to_loca_format;
+    SP_long_hor_metric *h_metrics;
+    SP_hhea_table hhea_table;
+    int16_t *left_side_bearings;
+    SP_kerning_pair *kerning_pairs; 
+} SP_font;
+
+SP_font* SP_load_font(char *filename);
+void SP_free_font(SP_font* font);
+
+#endif

+ 38 - 0
src/launch_program/main.c

@@ -0,0 +1,38 @@
+#include "src/headers/lemonguice.h"
+
+int main(){
+    LG_init(); // init
+
+    LG_font_face* font_face = LG_new_font_face("fonts/times_new_roman.ttf");
+    LG_font_style* font_style = LG_new_font_style();
+
+    font_style->font_color = 0xFFFFFFFF;
+    font_style->font_face = font_face;
+    font_style->font_size = 20;
+
+
+    LG_widget* root_panel = LG_new_window(); // create new SDL window, return the root panel 
+
+    // LG_add_child_panel(root_panel, new_panel); // maybe?
+
+    LG_widget* left_panel = LG_new_child_panel(root_panel);
+    LG_widget* right_panel = LG_new_child_panel(root_panel);
+
+    LG_widget* button = LG_add_button_widget(left_panel);
+
+    button->button_widget_data.text_data.font_style = font_style;
+
+    LG_widget* text_1 = LG_add_text_widget(left_panel);
+
+    text_1->text_widget_data.text_data.font_style = font_style;
+
+    LG_widget* text_2 = LG_add_text_widget(left_panel);
+
+    text_2->text_widget_data.text_data.font_style = font_style;
+
+    LG_widget* image = LG_add_image_widget(right_panel);
+
+    image->image_widget_data.image = LG_load_image("images/test_image.bmp");
+
+    return 0;
+}

BIN
src/libraries/libpitmap.so


BIN
src/libraries/libsourparse.so


+ 129 - 0
src/library/main.c

@@ -0,0 +1,129 @@
+#include "headers/lemonguice.h"
+#include "headers/sourparse.h"
+#include "headers/pitmap.h"
+
+LG_context context;
+
+LG_font_face* LG_new_font_face(char* filename){
+    LG_font_face* font_face = malloc(sizeof(LG_font_face));
+    
+    font_face->font = SP_load_font(filename);
+
+    return font_face;
+}
+
+LG_font_style* LG_new_font_style(){
+    LG_font_style* font_style = malloc(sizeof(LG_new_font_style));
+
+    *font_style = *context.default_font_style;
+
+    return font_style;
+}
+
+LG_widget* LG_new_window(){
+    LG_widget* widget = malloc(sizeof(LG_widget));
+
+    *widget = *context.default_widget;
+
+    widget->id = context.current_id++;
+    widget->children = NULL;
+    widget->parent = NULL;
+    widget->type = LG_WIDGET_TYPE_PANEL;
+
+    return widget;
+}
+
+LG_widget* LG_add_widget(LG_widget* parent_widget){
+    LG_widget* widget = malloc(sizeof(LG_widget));
+
+    *widget = *context.default_widget;
+
+    parent_widget->children = realloc(parent_widget->children, sizeof(LG_widget*) * ++parent_widget->child_count);
+
+    parent_widget->children[parent_widget->child_count - 1] = &widget;    
+
+    widget->id = context.current_id++;
+
+    return widget;
+}
+
+LG_widget* LG_add_panel_widget(LG_widget* parent_widget){
+    LG_widget* widget = LG_add_widget(parent_widget);
+
+    widget->type = LG_WIDGET_TYPE_PANEL;
+
+    return widget;
+}
+
+LG_widget* LG_add_text_widget(LG_widget* parent_widget){
+    LG_widget* widget = LG_add_widget(parent_widget);
+
+    widget->type = LG_WIDGET_TYPE_TEXT;
+
+    return widget;
+}
+
+LG_widget* LG_add_button_widget(LG_widget* parent_widget){
+    LG_widget* widget = LG_add_widget(parent_widget);
+
+    widget->type = LG_WIDGET_TYPE_BUTTON;
+
+    return widget;
+}
+
+LG_image* LG_load_image(char* filename){
+    LG_image* image = malloc(sizeof(LG_image));
+
+    PM_image* temp_image = PM_load_image(filename, 0);
+
+    image->image_data = temp_image->frame_buffer;
+    image->width = temp_image->width;
+    image->height = temp_image->height;
+
+    free(temp_image);
+}
+
+int LG_init(){
+    context.default_font_face = LG_new_font_face("fonts/times_new_roman.ttf");
+
+    context.default_font_style = malloc(sizeof(LG_font_style));
+
+    context.default_font_style->flags = 0;
+    // xxxxx 0<- 1 for center 0<- 0 for left, 1 for right 0<- 0 for up, 1 for down
+    context.default_font_style->font_alignment = 1 << 2;
+    context.default_font_style->font_color = 0xAAAAAAFF;
+    context.default_font_style->font_face = context.default_font_face;
+    context.default_font_style->font_size = 16;
+    context.default_font_style->kerning = -1;
+
+    context.default_widget = malloc(sizeof(LG_widget));
+
+    context.default_widget->id = context.current_id++;
+    context.default_widget->children = NULL;
+    context.default_widget->child_count = 0;
+    context.default_widget->parent = NULL;
+    context.default_widget->type = LG_WIDGET_TYPE_PANEL;
+    context.default_widget->widget_style->background_color = 0x2E2E2EFF;
+    context.default_widget->widget_style->border_color = 0x000000FF;
+    context.default_widget->widget_style->border_radius = 0;
+    context.default_widget->widget_style->border_size = 4;
+    context.default_widget->widget_style->height = -1;
+    context.default_widget->widget_style->width = -1;
+    context.default_widget->widget_style->margin = 0;
+    context.default_widget->widget_style->margin = -1;
+    context.default_widget->widget_style->margin = -1;
+    context.default_widget->widget_style->margin = -1;
+    context.default_widget->widget_style->margin = -1;
+    context.default_widget->widget_style->padding = 20;
+    context.default_widget->widget_style->padding = -1;
+    context.default_widget->widget_style->padding = -1;
+    context.default_widget->widget_style->padding = -1;
+    context.default_widget->widget_style->padding = -1;
+    context.default_widget->widget_style->widget_alignment_horizontal = LG_WIDGET_ALIGNMENT_CENTER_HORIZONTAL;
+    context.default_widget->widget_style->widget_alignment_vertical = LG_WIDGET_ALIGNMENT_CENTER_VERTICAL;
+
+
+    context.current_id = 0;
+
+    return 0;
+}