From b989a577e19b1af14d431a082869cd5086497efc Mon Sep 17 00:00:00 2001 From: Philip Minakov Date: Sun, 1 Oct 2023 14:36:00 +0400 Subject: [PATCH] Create project --- .gitignore | 6 + CMakeLists.txt | 38 +++++ src/files.c | 188 ++++++++++++++++++++++ src/freetype/freetype.c | 101 ++++++++++++ src/freetype/freetype_cache.c | 104 ++++++++++++ src/gui.c | 147 +++++++++++++++++ src/include/sie/files.h | 21 +++ src/include/sie/freetype/freetype.h | 13 ++ src/include/sie/freetype/freetype_cache.h | 30 ++++ src/include/sie/gui.h | 33 ++++ src/include/sie/menu/menu.h | 32 ++++ src/include/sie/menu/menu_list.h | 34 ++++ src/include/sie/resources.h | 18 +++ src/include/sie/settings.h | 9 ++ src/include/sie/sie.h | 13 ++ src/include/sie/strings.h | 7 + src/menu/menu.c | 108 +++++++++++++ src/menu/menu_list.c | 182 +++++++++++++++++++++ src/resources.c | 90 +++++++++++ src/settings.c | 9 ++ src/strings.c | 24 +++ 21 files changed, 1207 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/files.c create mode 100644 src/freetype/freetype.c create mode 100644 src/freetype/freetype_cache.c create mode 100644 src/gui.c create mode 100644 src/include/sie/files.h create mode 100644 src/include/sie/freetype/freetype.h create mode 100644 src/include/sie/freetype/freetype_cache.h create mode 100644 src/include/sie/gui.h create mode 100644 src/include/sie/menu/menu.h create mode 100644 src/include/sie/menu/menu_list.h create mode 100644 src/include/sie/resources.h create mode 100644 src/include/sie/settings.h create mode 100644 src/include/sie/sie.h create mode 100644 src/include/sie/strings.h create mode 100644 src/menu/menu.c create mode 100644 src/menu/menu_list.c create mode 100644 src/resources.c create mode 100644 src/settings.c create mode 100644 src/strings.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5385232 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# dirs +/.idea/ +/build/ + +# files +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7c03bae --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.14.1) + +get_filename_component(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../include ABSOLUTE) +get_filename_component(LIB_DIR ${CMAKE_SOURCE_DIR}/../lib ABSOLUTE) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR}) + +macro(push_library lib) + set(LIBS "${LIBS} ${LIB_DIR}/${lib}") +endmacro() + +set(CMAKE_C_COMPILER_WORKS 1) +set(CMAKE_CXX_COMPILER_WORKS 1) +set(CMAKE_C_COMPILER "arm-eabi-gcc") +set(CMAKE_LINKER "arm-eabi-ld") + +include_directories(${INCLUDE_DIR}) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msoft-float -fshort-wchar -marm -mlittle-endian -mcpu=arm926ej-s") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -nostdlib -pipe -fno-exceptions -fdata-sections -ffunction-sections") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Werror") + +push_library(libcrt.a) +push_library(libcrt_helper.so) +push_library(libc-1.0.so) +push_library(libgcc-4.6.1.so) +push_library(libft-2.4.6-1.so) + +set(CMAKE_SHARED_LINKER_FLAGS "-zmax-page-size=1 -marmelf -nostdlib --defsym __ex=0") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -shared -s -Bsymbolic -Bsymbolic-function -soname=libsie.so") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rpath-link ${LIB_DIR} ${LIBS}") +set(CMAKE_C_CREATE_SHARED_LIBRARY " -o ") + +project(sieelf_libsie) +file(GLOB_RECURSE SOURCES "src/*.c") + +add_library(sie SHARED ${SOURCES}) + +add_custom_command(TARGET sie POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/include/sie/ ${INCLUDE_DIR}/sie/) diff --git a/src/files.c b/src/files.c new file mode 100644 index 0000000..57dbd48 --- /dev/null +++ b/src/files.c @@ -0,0 +1,188 @@ +#include +#include +#include "include/sie/files.h" + +SIE_FILE *Sie_Files_Find(const char *mask) { + SIE_FILE *top = NULL; + SIE_FILE *current = NULL; + SIE_FILE *prev = NULL; + + DIR_ENTRY de; + unsigned int err; + if (FindFirstFile(&de, mask, &err)) { + do { + size_t len; + + current = malloc(sizeof(SIE_FILE)); + zeromem(current, sizeof(SIE_FILE)); + + // file_name + len = strlen(de.file_name); + current->file_name = malloc(sizeof(char) * (len + 1)); + strcpy(current->file_name, de.file_name); + // file_attr + current->file_attr = de.file_attr; + if (!prev) { + top = current; + } else { + prev->next = current; + current->prev = prev; + } + prev = current; + } while (FindNextFile(&de, &err)); + FindClose(&de, &err); + } + return top; +} + +void Sie_Files_Destroy(SIE_FILE *top) { + SIE_FILE *p = top; + while (p) { + SIE_FILE *next = p->next; + mfree(p->file_name); + mfree(p); + p = next; + } +} + +unsigned int Sie_Files_GetCount(SIE_FILE *top) { + unsigned int count = 0; + while (top) { + top = top->next; + count++; + } + return count; +} + +SIE_FILE *Sie_Files_GetFileByID(SIE_FILE *top, unsigned int id) { + SIE_FILE *file = NULL; + unsigned int i = 0; + while (top) { + if (i == id) { + file = top; + break; + } + top = top->next; + i++; + } + return file; +} + +SIE_FILE *Sie_Files_GetFileByFileName(SIE_FILE *top, const char *file_name) { + SIE_FILE *file = NULL; + while (top) { + if (strcmp(top->file_name, file_name) == 0) { + file = top; + break; + } + top = top->next; + } + return file; +} + +void Sie_Files_DeleteElement(SIE_FILE *top, SIE_FILE *element) { + SIE_FILE *p = top; + while (p) { + if (p == element) { + SIE_FILE *prev = element->prev; + SIE_FILE *next = element->next; + if (prev) { + prev->next = next; + } + if (next) { + next->prev = prev; + } + mfree(element); + break; + } + p = p->next; + } +} + +SIE_FILE *Sie_Files_Sort(SIE_FILE *top, int cmp(SIE_FILE*, SIE_FILE*), int keep_folders_on_top) { + SIE_FILE *new_top = NULL; + SIE_FILE *prev = NULL; + SIE_FILE *current = NULL; + + SIE_FILE *p = NULL; + SIE_FILE *p2 = NULL; + + p = top; + while (p) { + SIE_FILE *found = p; + p2 = p->next; + while (p2) { + if (cmp(p2, found)) { + found = p2; + } + p2 = p2->next; + } + current = malloc(sizeof(SIE_FILE)); + memcpy(current, found, sizeof(SIE_FILE)); + Sie_Files_DeleteElement(p, found); + if (found == p) { + p = p->next; + } + + current->prev = prev; + current->next = NULL; + if (!prev) { + new_top = current; + } else { + prev->next = current; + } + prev = current; + } + + if (keep_folders_on_top) { + SIE_FILE *top_dir = NULL; + SIE_FILE *top_file = NULL; + SIE_FILE *last_dir = NULL; + SIE_FILE *last_file = NULL; + p = new_top; + while (p) { + if (p->file_attr & FA_DIRECTORY) { + SIE_FILE *current_dir = malloc(sizeof(SIE_FILE)); + memcpy(current_dir, p, sizeof(SIE_FILE)); + Sie_Files_DeleteElement(p, p); + current_dir->next = NULL; + current_dir->prev = last_dir; + if (!last_dir) { + top_dir = current_dir; + } else { + last_dir->next = current_dir; + } + last_dir = current_dir; + } else { + SIE_FILE *current_file = malloc(sizeof(SIE_FILE)); + memcpy(current_file, p, sizeof(SIE_FILE)); + Sie_Files_DeleteElement(p, p); + current_file->next = NULL; + current_file->prev = last_file; + if (!last_file) { + top_file = current_file; + } else { + last_file->next = current_file; + } + last_file = current_file; + } + p = p->next; + } + if (top_dir) { + last_dir->next = top_file; + } + if (top_file) { + top_file->prev = last_dir; + } + new_top = (top_dir) ? top_dir : top_file; + } + + return new_top; +} + +SIE_FILE *Sie_Files_SortByName(SIE_FILE *top, int keep_folders_on_top) { + int cmp(SIE_FILE *f1, SIE_FILE *f2) { + return (strcmpi(f1->file_name, f2->file_name) < 0); + } + return Sie_Files_Sort(top, cmp, keep_folders_on_top); +} diff --git a/src/freetype/freetype.c b/src/freetype/freetype.c new file mode 100644 index 0000000..4eefe10 --- /dev/null +++ b/src/freetype/freetype.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include FT_FREETYPE_H +#include "../include/sie/gui.h" +#include "../include/sie/freetype/freetype_cache.h" + +FT_Library *FT_LIBRARY = NULL; +FT_Face *FT_FACE_REGULAR = NULL; +unsigned int FT_CLIENTS_COUNT = 0; + +void Sie_FT_Init() { + if (!FT_LIBRARY) { + FT_LIBRARY = malloc(sizeof(FT_Library)); + FT_Init_FreeType(FT_LIBRARY); + if (!FT_FACE_REGULAR) { + FT_FACE_REGULAR = malloc(sizeof(FT_Face)); + FT_New_Face(*FT_LIBRARY, "0:\\ZBin\\fonts\\Roboto-Regular.ttf", + 0, FT_FACE_REGULAR); + } + } + FT_CLIENTS_COUNT++; +} + +void Sie_FT_Destroy() { + if (FT_CLIENTS_COUNT) { + FT_CLIENTS_COUNT--; + } + if (!FT_CLIENTS_COUNT) { + if (FT_LIBRARY) { + if (FT_FACE_REGULAR) { + FT_Done_Face(*FT_FACE_REGULAR); + mfree(FT_FACE_REGULAR); + FT_FACE_REGULAR = NULL; + } + FT_Done_FreeType(*FT_LIBRARY); + mfree(FT_LIBRARY); + FT_LIBRARY = NULL; + Sie_FT_Cache_Destroy(); + } + } +} + +int Sie_FT_GetMaxHeight(int font_size) { + FT_Face *face = FT_FACE_REGULAR; + FT_Set_Pixel_Sizes(*face, 0, font_size); + const int max_ascender = ((*face)->size->metrics.ascender >> 6); + const int max_descender = abs(((*face)->size->metrics.descender >> 6)); + return max_ascender + max_descender; +} + +void Sie_FT_GetStringSize(WSHDR *ws, int font_size, unsigned int *w, unsigned int *h) { + FT_Face *face = FT_FACE_REGULAR; + SIE_FT_CACHE *ft_cache = Sie_FT_Cache_GetOrCreate(face, font_size); + SIE_FT_CC_CACHE *ft_cc_cache = NULL; + + unsigned int width = 0, height = Sie_FT_GetMaxHeight(font_size); + FT_ULong charcode; + for (unsigned int i = 0; i < wstrlen(ws); i++) { + charcode = ws->wsbody[1 + i]; + ft_cc_cache = Sie_FT_Cache_CCGetOrAdd(face, ft_cache, charcode); + width += ft_cc_cache->h_advance; + } + *w = width; + *h = height; +} + +void Sie_FT_DrawString(WSHDR *ws, int x, int y, int font_size, const char *rgb) { + char _rgb[3]; + FT_Face *face = FT_FACE_REGULAR; + SIE_FT_CACHE *ft_cache = Sie_FT_Cache_GetOrCreate(face, font_size); + SIE_FT_CC_CACHE *ft_cc_cache = NULL; + + FT_Set_Pixel_Sizes(*face, 0, font_size); + if (rgb) { + memcpy(_rgb, rgb, 3); + } else { + memset(_rgb, 0xFF, 3); + } + + IMGHDR img; + size_t size; + FT_ULong charcode; + for (int i = 0; i < wstrlen(ws); i++) { + charcode = ws->wsbody[1 + i]; + ft_cc_cache = Sie_FT_Cache_CCGetOrAdd(face, ft_cache, charcode); + + size = ft_cc_cache->img->w * ft_cc_cache->img->h * 4; + memcpy(&img, ft_cc_cache->img, sizeof(IMGHDR)); + img.bitmap = malloc(size); + memcpy(img.bitmap, ft_cc_cache->img->bitmap, size); + for (int j = 0; j < size; j += 4) { + img.bitmap[j + 0] = _rgb[2]; // b + img.bitmap[j + 1] = _rgb[1]; // g + img.bitmap[j + 2] = _rgb[0]; // r + } + Sie_GUI_DrawIMGHDR(&img, x, y + ft_cc_cache->y_offset, img.w, img.h); + mfree(img.bitmap); + x += ft_cc_cache->h_advance; + } +} diff --git a/src/freetype/freetype_cache.c b/src/freetype/freetype_cache.c new file mode 100644 index 0000000..1955822 --- /dev/null +++ b/src/freetype/freetype_cache.c @@ -0,0 +1,104 @@ +#include "../include/sie/freetype/freetype_cache.h" + +SIE_FT_CACHE *FT_CACHE; +unsigned int FT_CACHE_SIZE; + +SIE_FT_CACHE *Sie_FT_Cache_GetOrCreate(const FT_Face *face, int font_size) { + SIE_FT_CACHE *ft_cache = NULL; + for (unsigned int i = 0; i < FT_CACHE_SIZE; i++) { + if (FT_CACHE[i].face == face && FT_CACHE[i].font_size == font_size) { + ft_cache = &(FT_CACHE[i]); + } + } + if (ft_cache) { + return ft_cache; + } else { + FT_CACHE = realloc(FT_CACHE, sizeof(SIE_FT_CACHE) * (FT_CACHE_SIZE + 1)); + ft_cache = &(FT_CACHE[FT_CACHE_SIZE]); + ft_cache->face = (FT_Face *)face; + ft_cache->font_size = font_size; + ft_cache->size = 0; + ft_cache->cache = NULL; + FT_CACHE_SIZE++; + return ft_cache; + } +} + +void Sie_FT_Cache_Destroy() { + for (int i = 0; i < FT_CACHE_SIZE; i++) { + SIE_FT_CACHE ft_cache = FT_CACHE[i]; + for (unsigned int j = 0; j < ft_cache.size; j++) { + SIE_FT_CC_CACHE ft_wc_cache = ft_cache.cache[j]; + mfree(ft_wc_cache.img->bitmap); + mfree(ft_wc_cache.img); + } + mfree(ft_cache.cache); + } + mfree(FT_CACHE); + FT_CACHE = NULL; + FT_CACHE_SIZE = 0; +} + +SIE_FT_CC_CACHE *Sie_FT_Cache_CCGet(SIE_FT_CACHE *ft_cache, FT_ULong charcode) { + SIE_FT_CC_CACHE *ft_cc_cache = NULL; + for (unsigned int i = 0; i < ft_cache->size; i++) { + ft_cc_cache = &(ft_cache->cache[i]); + if (ft_cc_cache->charcode == charcode) { + return ft_cc_cache; + } + } + return NULL; +} + +SIE_FT_CC_CACHE *Sie_FT_Cache_CCAdd(FT_Face *face, SIE_FT_CACHE *ft_cache, FT_ULong charcode) { + FT_UInt glyph_index; + FT_Bitmap *bitmap; + + glyph_index = FT_Get_Char_Index(*face, charcode); + FT_Load_Glyph((*face), glyph_index, FT_LOAD_DEFAULT); + FT_Render_Glyph((*face)->glyph, FT_RENDER_MODE_NORMAL); + bitmap = &((*face)->glyph->bitmap); + + IMGHDR *img = malloc(sizeof(IMGHDR)); + img->w = bitmap->width; + img->h = bitmap->rows; + img->bpnum = 0x0A; + img->bitmap = malloc(img->w * img->h * 4); + + uint8_t im[img->h][img->w]; + for (int _y = 0, j = 0; _y < img->h; _y++) { + for (int _x = 0; _x < img->w; _x++, j++) { + im[_y][_x] = bitmap->buffer[j]; + } + } + for (int j = 0, _y = 0; _y < img->h; _y++) { + for (int _x = 0; _x < img->w; _x++, j++) { + img->bitmap[4 * j + 3] = im[_y][_x]; + } + } + + int h_advance = 0; + int y_offset = 0; + const int max_ascender = ((*face)->size->metrics.ascender >> 6); + h_advance = ((*face)->glyph->metrics.horiAdvance >> 6); + y_offset = -((*face)->glyph->bitmap_top) + max_ascender; + + ft_cache->cache = realloc(ft_cache->cache, sizeof(SIE_FT_CC_CACHE) * (ft_cache->size + 1)); + SIE_FT_CC_CACHE *cc_cache = &(ft_cache->cache[ft_cache->size]); + zeromem(cc_cache, sizeof(SIE_FT_CC_CACHE)); + cc_cache->charcode = charcode; + cc_cache->img = img; + cc_cache->y_offset = y_offset; + cc_cache->h_advance = h_advance; + ft_cache->size++; + return cc_cache; +} + +SIE_FT_CC_CACHE *Sie_FT_Cache_CCGetOrAdd(FT_Face *face, SIE_FT_CACHE *ft_cache, FT_ULong charcode) { + SIE_FT_CC_CACHE *cc_cache = NULL; + cc_cache = Sie_FT_Cache_CCGet(ft_cache, charcode); + if (!cc_cache) { + cc_cache = Sie_FT_Cache_CCAdd(face, ft_cache, charcode); + } + return cc_cache; +} diff --git a/src/gui.c b/src/gui.c new file mode 100644 index 0000000..a53d8e7 --- /dev/null +++ b/src/gui.c @@ -0,0 +1,147 @@ +#include +#include +#include "include/sie/freetype/freetype.h" +#include "include/sie/gui.h" + +#define FONT_SIZE_ICONBAR 14 +#define FONT_SIZE_HEADER 20 +#define COLOR_HEADER_BG {0x00, 0x00, 0x00, 0x35} + +extern IMGHDR *SIE_RES_IMG_WALLPAPER; + +GBSTMR TIMER_DRAW_ICONBAR; + +SIE_GUI_SURFACE *Sie_GUI_Surface_Init(int type, int (*OnKey)(void *data, GUI_MSG *msg)) { + SIE_GUI_SURFACE *surface = malloc(sizeof(SIE_GUI_SURFACE)); + zeromem(surface, sizeof(SIE_GUI_SURFACE)); + surface->type = type; + surface->OnKey = OnKey; + surface->ws_hdr = AllocWS(128); + return surface; +}; + +void Sie_GUI_Surface_Destroy(SIE_GUI_SURFACE *surface) { + FreeWS(surface->ws_hdr); + mfree(surface); +} + +void Sie_GUI_Surface_Draw(const SIE_GUI_SURFACE *surface) { + Sie_GUI_DrawIconBar(); + Sie_GUI_DrawHeader(surface->ws_hdr); +} + +void Sie_GUI_Surface_OnFocus() { + GBS_StartTimerProc(&TIMER_DRAW_ICONBAR, 216, Sie_GUI_DrawIconBar); +} + +void Sie_GUI_Surface_OnUnFocus() { + GBS_StopTimer(&TIMER_DRAW_ICONBAR); +} + +int Sie_GUI_Surface_OnKey(SIE_GUI_SURFACE *surface, void *data, GUI_MSG *msg) { + if (surface->OnKey) { + return surface->OnKey(data, msg); + } + return 0; +} + +/**********************************************************************************************************************/ + +void Sie_GUI_DrawIMGHDR(IMGHDR *img, int x, int y, int w, int h) { + RECT rc; + DRWOBJ drwobj; + StoreXYWHtoRECT(&rc, x, y, w, h); + SetPropTo_Obj5(&drwobj, &rc, 0, img); + SetColor(&drwobj, NULL, NULL); + DrawObject(&drwobj); +} + +void Sie_GUI_DrawBleedIMGHDR(IMGHDR *img, int x, int y, int x2, int y2, int bleed_x, int bleed_y) { + RECT rc; + DRWOBJ drwobj; + StoreXYXYtoRECT(&rc, x, y, x2, y2); + SetPropTo_Obj5(&drwobj, &rc, 0, img); + SetProp2ImageOrCanvas(&drwobj, &rc, 0, img, bleed_x, bleed_y); + SetColor(&drwobj, NULL, NULL); + DrawObject(&drwobj); +} + +void Sie_GUI_DrawIconBar() { + if (IsTimerProc(&TIMER_DRAW_ICONBAR)) { + GBS_StopTimer(&TIMER_DRAW_ICONBAR); + } + + Sie_GUI_DrawIMGHDR(SIE_RES_IMG_WALLPAPER, 0, 0, ScreenW(), YDISP); + + + char str[64]; + int x = 0, y = 0; + unsigned int w = 0, h = 0; + WSHDR *ws = AllocWS(64); + // заряд аккумулятора + wsprintf(ws, "%d%%", *RamCap()); + Sie_FT_GetStringSize(ws, FONT_SIZE_ICONBAR, &w, &h); + x = SCREEN_X2 - PADDING_ICONBAR - w; + y = 0 + (YDISP - h) / 2; + Sie_FT_DrawString(ws, x, y, FONT_SIZE_ICONBAR, NULL); + // часы + TTime time; + GetDateTime(NULL, &time); + wsprintf(ws, "%02d:%02d", time.hour, time.min); + Sie_FT_GetStringSize(ws, FONT_SIZE_ICONBAR, &w, &h); + x = x - PADDING_ICONBAR - (int)w; + Sie_FT_DrawString(ws, x, y, FONT_SIZE_ICONBAR, NULL); + // другая инфа + sprintf(str, "%d Б", GetFreeRamAvail()); + utf8_2ws(ws, str, 64); + Sie_FT_DrawString(ws, + 0 + PADDING_ICONBAR, + 0 + (YDISP - Sie_FT_GetMaxHeight(FONT_SIZE_ICONBAR)) / 2, + FONT_SIZE_ICONBAR, NULL); + FreeWS(ws); + + GBS_StartTimerProc(&TIMER_DRAW_ICONBAR, 216, Sie_GUI_DrawIconBar); +} + +void Sie_GUI_DrawHeader(WSHDR *ws) { + const char color_bg[] = COLOR_HEADER_BG; + const int header_x = 0; + const int header_y = YDISP; + const int header_x2 = SCREEN_X2; + const int header_y2 = header_y + HeaderH(); + Sie_GUI_DrawBleedIMGHDR(SIE_RES_IMG_WALLPAPER, + header_x, header_y, header_x2, header_y2, + 0, YDISP); + DrawRectangle(header_x, header_y, header_x2, header_y2 - 1, 0, color_bg, color_bg); + + int text_x = 0; + int text_y = 0; + + char str[64]; + WSHDR *ws_left = AllocWS(64); + WSHDR *ws_right = AllocWS(64); + ws_2str(ws, str, wstrlen(ws)); + char *p = strchr(str, '\t'); + if (p) { + const int len_left = p - str; + if (len_left > 0) { + str_2ws(ws_left, str, len_left); + } + str_2ws(ws_right, p + 1, strlen(str) - (p - str - 1)); + } else { + wstrcpy(ws_left, ws); + } + text_x = 0 + PADDING_HEADER; + text_y = YDISP + (HeaderH() - Sie_FT_GetMaxHeight(FONT_SIZE_HEADER)) / 2; + if (wstrlen(ws_left)) { + Sie_FT_DrawString(ws_left, text_x, text_y, FONT_SIZE_HEADER, NULL); + } + if (wstrlen(ws_right)) { + unsigned int w = 0, h = 0; + Sie_FT_GetStringSize(ws_right, FONT_SIZE_HEADER, &w, &h); + text_x = SCREEN_X2 - 1 - PADDING_HEADER - w; + Sie_FT_DrawString(ws_right, text_x, text_y, FONT_SIZE_HEADER, NULL); + } + FreeWS(ws_left); + FreeWS(ws_right); +} diff --git a/src/include/sie/files.h b/src/include/sie/files.h new file mode 100644 index 0000000..78ae769 --- /dev/null +++ b/src/include/sie/files.h @@ -0,0 +1,21 @@ +#ifndef __SIE_FILES_H__ +#define __SIE_FILES_H__ + +typedef struct { + void *prev; + void *next; + char *file_name; + short file_attr; +} SIE_FILE; + +SIE_FILE *Sie_Files_Find(const char *mask); +void Sie_Files_Destroy(SIE_FILE *top); + +unsigned int Sie_Files_GetCount(SIE_FILE *top); +SIE_FILE *Sie_Files_GetFileByID(SIE_FILE *top, unsigned int id); +SIE_FILE *Sie_Files_GetFileByFileName(SIE_FILE *top, const char *file_name); + +SIE_FILE *Sie_Files_Sort(SIE_FILE *top, int cmp(SIE_FILE*, SIE_FILE*), int keep_folders_on_top); +SIE_FILE *Sie_Files_SortByName(SIE_FILE *top, int keep_folders_on_top); + +#endif diff --git a/src/include/sie/freetype/freetype.h b/src/include/sie/freetype/freetype.h new file mode 100644 index 0000000..e13a39e --- /dev/null +++ b/src/include/sie/freetype/freetype.h @@ -0,0 +1,13 @@ +#ifndef __SIE_FREETYPE_H__ +#define __SIE_FREETYPE_H__ + +#include + +extern void Sie_FT_Init(); +extern void Sie_FT_Destroy(); + +int Sie_FT_GetMaxHeight(int font_size); +void Sie_FT_GetStringSize(WSHDR *ws, int font_size, unsigned int *w, unsigned int *h); +void Sie_FT_DrawString(WSHDR *ws, int x, int y, int font_size, const char *rgb); + +#endif diff --git a/src/include/sie/freetype/freetype_cache.h b/src/include/sie/freetype/freetype_cache.h new file mode 100644 index 0000000..2e51eaf --- /dev/null +++ b/src/include/sie/freetype/freetype_cache.h @@ -0,0 +1,30 @@ +#ifndef __SIE_FREETYPE_CACHE_H__ +#define __SIE_FREETYPE_CACHE_H__ + +#include +#include +#include +#include FT_FREETYPE_H + +typedef struct { + FT_ULong charcode; + IMGHDR *img; + int y_offset; + int h_advance; +} SIE_FT_CC_CACHE; + +typedef struct { + FT_Face *face; + int font_size; + SIE_FT_CC_CACHE *cache; + unsigned int size; +} SIE_FT_CACHE; + +SIE_FT_CACHE *Sie_FT_Cache_GetOrCreate(const FT_Face *face, int font_size); +void Sie_FT_Cache_Destroy(); + +SIE_FT_CC_CACHE *Sie_FT_Cache_CCGet(SIE_FT_CACHE *ft_cache, FT_ULong charcode); +SIE_FT_CC_CACHE *Sie_FT_Cache_CCAdd(FT_Face *face, SIE_FT_CACHE *ft_cache, FT_ULong charcode); +SIE_FT_CC_CACHE *Sie_FT_Cache_CCGetOrAdd(FT_Face *face, SIE_FT_CACHE *ft_cache, FT_ULong charcode); + +#endif \ No newline at end of file diff --git a/src/include/sie/gui.h b/src/include/sie/gui.h new file mode 100644 index 0000000..7c586e1 --- /dev/null +++ b/src/include/sie/gui.h @@ -0,0 +1,33 @@ +#ifndef __SIE_GUI_H__ +#define __SIE_GUI_H__ + +#include +#include + +#define SIE_GUI_SURFACE_TYPE_DEFAULT 0x00 + +typedef struct { + int type; + int (*OnKey)(void *data, GUI_MSG *msg); + WSHDR *ws_hdr; +} SIE_GUI_SURFACE; + +SIE_GUI_SURFACE *Sie_GUI_Surface_Init(int type, int (*OnKey)(void *data, GUI_MSG *msg)); +void Sie_GUI_Surface_Destroy(SIE_GUI_SURFACE *surface); +void Sie_GUI_Surface_Draw(const SIE_GUI_SURFACE *surface); +void Sie_GUI_Surface_OnFocus(); +void Sie_GUI_Surface_OnUnFocus(); +int Sie_GUI_Surface_OnKey(SIE_GUI_SURFACE *surface, void *data, GUI_MSG *msg); + +#define SCREEN_X2 (ScreenW() - 1) +#define SCREEN_Y2 (ScreenH() - 1) + +#define PADDING_ICONBAR 5 +#define PADDING_HEADER 5 + +void Sie_GUI_DrawIMGHDR(IMGHDR *img, int x, int y, int w, int h); +void Sie_GUI_DrawBleedIMGHDR(IMGHDR *img, int x, int y, int x2, int y2, int bleed_x, int bleed_y); +void Sie_GUI_DrawIconBar(); +void Sie_GUI_DrawHeader(WSHDR *ws); + +#endif diff --git a/src/include/sie/menu/menu.h b/src/include/sie/menu/menu.h new file mode 100644 index 0000000..a571a4d --- /dev/null +++ b/src/include/sie/menu/menu.h @@ -0,0 +1,32 @@ +#ifndef __SIE_MENU_H__ +#define __SIE_MENU_H__ + +#include +#include + +#define SIE_MENU_MAX_COLS 3 +#define SIE_MENU_MAX_ROWS 4 + +typedef struct { + WSHDR *ws; + IMGHDR *icon; + void (*proc)(); +} SIE_MENU_ITEM; + +typedef struct { + SIE_MENU_ITEM *items; + unsigned int n_items; + int col, row; + int max_cols, max_rows; +} SIE_MENU; + +#define Sie_Menu_Index(col, row) (row * SIE_MENU_MAX_COLS + col) + +SIE_MENU *Sie_Menu_Init(SIE_MENU_ITEM *items, int n_items, int col, int row); +void Sie_Menu_Destroy(SIE_MENU *menu); + +void Sie_Menu_Draw(SIE_MENU *menu); +void Sie_Menu_Redraw(SIE_MENU *menu); +void Sie_Menu_OnKey(SIE_MENU *menu, GUI_MSG *msg); + +#endif diff --git a/src/include/sie/menu/menu_list.h b/src/include/sie/menu/menu_list.h new file mode 100644 index 0000000..73458f8 --- /dev/null +++ b/src/include/sie/menu/menu_list.h @@ -0,0 +1,34 @@ +#ifndef __SIE_MENU_LIST_H__ +#define __SIE_MENU_LIST_H__ + +#include + +#define SIE_MENU_LIST_MAX_ITEMS 7 +#define SIE_MENU_LIST_KEY_PREV UP_BUTTON +#define SIE_MENU_LIST_KEY_NEXT DOWN_BUTTON +#define SIE_MENU_LIST_KEY_ENTER ENTER_BUTTON + +typedef struct { + IMGHDR *icon; + WSHDR *ws; + void (*proc)(void); +} SIE_MENU_LIST_ITEM; + +typedef struct { + SIE_MENU_LIST_ITEM *items; + unsigned int n_items; + + unsigned int row; + unsigned int offset; +} SIE_MENU_LIST; + +SIE_MENU_LIST *Sie_Menu_List_Init(SIE_MENU_LIST_ITEM *items, unsigned int n_items); +void Sie_Menu_List_Destroy(SIE_MENU_LIST *menu); + +void Sie_Menu_List_DrawMenu(SIE_MENU_LIST *menu); +void Sie_Menu_List_DrawEmpty(); +void Sie_Menu_List_Refresh(SIE_MENU_LIST *menu); +void Sie_Menu_List_Draw(SIE_MENU_LIST *menu); +void Sie_Menu_List_OnKey(SIE_MENU_LIST *menu, GUI_MSG *msg); + +#endif diff --git a/src/include/sie/resources.h b/src/include/sie/resources.h new file mode 100644 index 0000000..5dd4807 --- /dev/null +++ b/src/include/sie/resources.h @@ -0,0 +1,18 @@ +#ifndef __SIE_RESOURCES_H__ +#define __SIE_RESOURCES_H__ + +#include + +typedef struct { + char ext[16]; + IMGHDR *icon; +} SIE_RESOURCES_EXT; + +void Sie_Resources_Init(); +void Sie_Resources_Destroy(); + +void Sie_Resources_SetWallpaper(WSHDR *ws); + +SIE_RESOURCES_EXT *Sie_Resources_ExtLoad(const char *file_name, const char *ext); + +#endif diff --git a/src/include/sie/settings.h b/src/include/sie/settings.h new file mode 100644 index 0000000..bc662d9 --- /dev/null +++ b/src/include/sie/settings.h @@ -0,0 +1,9 @@ +#ifndef __SIE_SETTINGS_H__ +#define __SIE_SETTINGS_H__ + +#include + +int Settings_UpdateWS(WSHDR *ws, const char *entry, const char *keyword); +int Settings_ReadWS(WSHDR *ws, const char *entry, const char *keyword); + +#endif diff --git a/src/include/sie/sie.h b/src/include/sie/sie.h new file mode 100644 index 0000000..8b285c4 --- /dev/null +++ b/src/include/sie/sie.h @@ -0,0 +1,13 @@ +#ifndef __SIE_H__ +#define __SIE_H__ + +#include "gui.h" +#include "files.h" +#include "strings.h" +#include "settings.h" +#include "resources.h" +#include "menu/menu.h" +#include "menu/menu_list.h" +#include "freetype/freetype.h" + +#endif diff --git a/src/include/sie/strings.h b/src/include/sie/strings.h new file mode 100644 index 0000000..8b10f2c --- /dev/null +++ b/src/include/sie/strings.h @@ -0,0 +1,7 @@ +#ifndef __SIE_STRINGS_H__ +#define __SIE_STRINGS_H__ + +void Sie_Strings_ToLower(char *str); +char *Sie_Strings_GetExtByFileName(const char *file_name); + +#endif diff --git a/src/menu/menu.c b/src/menu/menu.c new file mode 100644 index 0000000..680e774 --- /dev/null +++ b/src/menu/menu.c @@ -0,0 +1,108 @@ +#include +#include +#include "../include/sie/gui.h" +#include "../include/sie/menu/menu.h" + +SIE_MENU *Sie_Menu_Init(SIE_MENU_ITEM *items, int n_items, int col, int row) { + SIE_MENU *menu = malloc(sizeof(SIE_MENU)); + menu->items = items; + menu->n_items = n_items; + menu->col = col; + menu->row = row; + menu->max_cols = min(n_items, SIE_MENU_MAX_COLS); + menu->max_rows = (n_items + SIE_MENU_MAX_COLS - 1) / SIE_MENU_MAX_COLS; + return menu; +} + +void Sie_Menu_Destroy(SIE_MENU *menu) { + if (menu) { + if (menu->items) { + SIE_MENU_ITEM *item; + for (int i = 0; i < menu->n_items; i++) { + item = &(menu->items[i]); + FreeWS(item->ws); + mfree(item->icon->bitmap); + mfree(item->icon); + } + } + mfree(menu); + } +} + +void Sie_Menu_Draw(SIE_MENU *menu) { + extern IMGHDR *SIE_RES_IMG_WALLPAPER; + + const int width = ScreenW(); + const int height = ScreenH() - YDISP - HeaderH(); + const int icon_area_width = width / SIE_MENU_MAX_COLS; + const int icon_area_height = height / SIE_MENU_MAX_ROWS; + + Sie_GUI_DrawBleedIMGHDR(SIE_RES_IMG_WALLPAPER, 0, YDISP + HeaderH(), ScreenW(), ScreenH(), 0, YDISP + HeaderH()); + + int x = 0; + int y = 0; + SIE_MENU_ITEM *item = NULL; + for (int i = 0, column = 0, row = 0; i < menu->n_items; i++) { + if (row + 1 >= SIE_MENU_MAX_ROWS + 1) { + break; + } + + item = (SIE_MENU_ITEM *)&menu->items[i]; + x = 0 + column * icon_area_width; + y = YDISP + HeaderH() + row * icon_area_height; + x += (icon_area_width - item->icon->w) / 2; + y += (icon_area_height - item->icon->h) / 2; + + Sie_GUI_DrawIMGHDR(item->icon, x, y, item->icon->w, item->icon->h); + + if ((column + 1) % SIE_MENU_MAX_COLS == 0) { + row += 1; + column = 0; + continue; + } + column += 1; + } +} + +void Sie_Menu_Redraw(SIE_MENU *menu) { + const int id_idle_menu = Sie_Menu_Index(menu->col, menu->row); + Sie_GUI_DrawHeader(menu->items[id_idle_menu].ws); + Sie_Menu_Draw(menu); +} + +void Sie_Menu_OnKey(SIE_MENU *menu, GUI_MSG *msg) { + if (msg->gbsmsg->msg == KEY_DOWN || msg->gbsmsg->msg == LONG_PRESS) { + switch (msg->gbsmsg->submess) { + case UP_BUTTON: + menu->row--; + if (menu->row < 0) { + menu->row = menu->max_rows - 1; + } + Sie_Menu_Redraw(menu); + case RIGHT_BUTTON: + menu->col++; + if (menu->col >= menu->max_cols) { + menu->col = 0; + } + Sie_Menu_Redraw(menu); + break; + case DOWN_BUTTON: + menu->row++; + if (menu->row >= menu->max_rows) { + menu->row = 0; + } + Sie_Menu_Redraw(menu); + break; + case LEFT_BUTTON: + menu->col--; + if (menu->col < 0) { + menu->col = menu->max_cols - 1; + } + Sie_Menu_Redraw(menu); + break; + case ENTER_BUTTON: + menu->items[menu->row].proc(); + break; + } + } +} diff --git a/src/menu/menu_list.c b/src/menu/menu_list.c new file mode 100644 index 0000000..7515f4a --- /dev/null +++ b/src/menu/menu_list.c @@ -0,0 +1,182 @@ +#include +#include +#include "../include/sie/gui.h" +#include "../include/sie/freetype/freetype.h" +#include "../include/sie/menu/menu_list.h" + +extern IMGHDR *SIE_RES_IMG_WALLPAPER; + +#define FONT_SIZE 18 +#define FONT_SIZE_EMPTY 22 +#define COLOR_SELECT_BG {0x00, 0x00, 0x00, 0x35} +#define COLOR_SELECT_TEXT {0xFF, 0xFF, 0xFF} +#define COLOR_INDICATOR_BG {0x00, 0x00, 0x00, 0x35} +#define COLOR_INDICATOR {0xFF, 0xFF, 0x00, 0x64} +#define COLOR_EMPTY_TEXT {0xFF, 0xFF, 0xFF} + +SIE_MENU_LIST *Sie_Menu_List_Init(SIE_MENU_LIST_ITEM *items, unsigned int n_items) { + SIE_MENU_LIST *menu = malloc(sizeof(SIE_MENU_LIST)); + zeromem(menu, sizeof(SIE_MENU_LIST)); + menu->items = items; + menu->n_items = n_items; + return menu; +} + +void Sie_Menu_List_Destroy(SIE_MENU_LIST *menu) { + if (menu) { + if (menu->items) { + SIE_MENU_LIST_ITEM *item; + for (unsigned int i = 0; i < menu->n_items; i++) { + item = &(menu->items[i]); + FreeWS(item->ws); + } + mfree(menu->items); + } + mfree(menu); + } +} + +void Sie_Menu_List_DrawIndicator(SIE_MENU_LIST *menu) { + const char color[] = COLOR_INDICATOR; + const char color_bg[] = COLOR_INDICATOR_BG; + + const int bg_h_offset = 2; + const int bg_v_offset = 2; + const int bg_w = 2; + const int bg_h = ScreenH() - HeaderH() - YDISP - bg_v_offset * 2; + + const int bg_x = SCREEN_X2 - bg_h_offset - bg_w; + const int bg_y = YDISP + HeaderH() + bg_v_offset; + const int bg_x2 = SCREEN_X2 - bg_h_offset; + const int bg_y2 = bg_y + bg_h; + DrawRectangle(bg_x, bg_y, ScreenW() - bg_h_offset, bg_y2, 1, color_bg, color_bg); + + const int indicator_x = bg_x - 1; + const int indicator_x2 = bg_x2 + 1; + const float indicator_h = (float)bg_h / (float)menu->n_items; + const float indicator_y = (float)bg_y + indicator_h * (float)menu->row; + const float indicator_y2 = indicator_y + indicator_h; + DrawRectangle(indicator_x, (int)(indicator_y), indicator_x2, (int)(indicator_y2), 0, color, color); +} + +void Sie_Menu_List_DrawMenu(SIE_MENU_LIST *menu) { +#define show_indicator (menu->n_items > SIE_MENU_LIST_MAX_ITEMS) + + const char color_select_bg[] = COLOR_SELECT_BG; + const char color_select_text[] = COLOR_SELECT_TEXT; + + const int h_offset = 3; + const int v_offset = 2; + const int header_h = HeaderH(); + const int width = ScreenW(); + const int height = ScreenH() - 1 - YDISP - header_h - v_offset; + const float item_h = (float)height / SIE_MENU_LIST_MAX_ITEMS; + const int item_w = (show_indicator) ? width - 6 - 1 - h_offset : width - 1 - h_offset; + + Sie_GUI_DrawBleedIMGHDR(SIE_RES_IMG_WALLPAPER, 0, 0 + YDISP + HeaderH(), SCREEN_X2, SCREEN_Y2, 0, YDISP + HeaderH()); + + int c = min(menu->n_items, SIE_MENU_LIST_MAX_ITEMS); + for (unsigned int i = 0; i < c; i++) { + const SIE_MENU_LIST_ITEM *item = &(menu->items[menu->offset + i]); + IMGHDR *img = item->icon; + WSHDR *ws = item->ws; + + const int x = 3; + const int x2 = item_w; + const float y = (float)(YDISP + header_h + 1 + (float)v_offset / 2) + (float)i * item_h; + const float y2 = y + item_h - (float)v_offset / 2; + const float text_y = y + (item_h - (float)Sie_FT_GetMaxHeight(FONT_SIZE)) / 2; + + char *color_text = NULL; + int text_x = x + 8; + int icon_x = 0; + float icon_y = 0; + if (i == (menu->row - menu->offset)) { + DrawRoundedFrame(x, (int)y, x2, (int)y2, + 6, 6, 0, + color_select_bg, color_select_bg); + color_text = (char*)color_select_text; + } + if (img) { + icon_x = text_x; + text_x = icon_x + img->w + 6; + icon_y = y + (item_h - (float)img->h) / 2; + Sie_GUI_DrawIMGHDR(img, icon_x, (int)icon_y, img->w, img->h); + } + Sie_FT_DrawString(ws, text_x, (int)text_y, FONT_SIZE, color_text); + } + if (show_indicator) { + Sie_Menu_List_DrawIndicator(menu); + } +} + +void Sie_Menu_List_DrawEmpty() { + Sie_GUI_DrawBleedIMGHDR(SIE_RES_IMG_WALLPAPER, 0, YDISP, SCREEN_X2, SCREEN_Y2, 0, YDISP); + + char *str = "<Пусто>"; + size_t len = strlen(str); + WSHDR *ws = AllocWS((int)(len + 1)); + utf8_2ws(ws, str, len); + unsigned int w = 0, h = 0; + Sie_FT_GetStringSize(ws, FONT_SIZE_EMPTY, &w, &h); + const int x = ScreenW() / 2 - (int)w / 2; + const int y = YDISP + HeaderH() + (ScreenH() - YDISP - HeaderH()) / 2 - (int)w / 2; + const char color[] = COLOR_EMPTY_TEXT; + Sie_FT_DrawString(ws, x, y, FONT_SIZE_EMPTY, color); + FreeWS(ws); +} + +void Sie_Menu_List_Refresh(SIE_MENU_LIST *menu) { + if (menu->n_items > SIE_MENU_LIST_MAX_ITEMS) { + if (menu->row >= (unsigned int)(SIE_MENU_LIST_MAX_ITEMS / 2)) { + if (menu->row < menu->n_items - (unsigned int)(SIE_MENU_LIST_MAX_ITEMS / 2)) { + menu->offset = menu->row - (unsigned int)(SIE_MENU_LIST_MAX_ITEMS) / 2; + } else { + menu->offset = menu->n_items - SIE_MENU_LIST_MAX_ITEMS; + } + } else { + menu->offset = 0; + } + } +} + +void Sie_Menu_List_Draw(SIE_MENU_LIST *menu) { + if (menu->n_items) { + Sie_Menu_List_DrawMenu(menu); + } else { + Sie_Menu_List_DrawEmpty(); + } +} + +void Sie_Menu_List_OnKey(SIE_MENU_LIST *menu, GUI_MSG *msg) { + if (msg->gbsmsg->msg == KEY_DOWN || msg->gbsmsg->msg == LONG_PRESS) { + switch (msg->gbsmsg->submess) { + case SIE_MENU_LIST_KEY_PREV: + if (menu->row != 0) { + menu->row--; + } else { + menu->row = menu->n_items - 1; + } + Sie_Menu_List_Refresh(menu); + Sie_Menu_List_Draw(menu); + break; + case SIE_MENU_LIST_KEY_NEXT: + menu->row++; + if (menu->row >= menu->n_items) { + menu->row = 0; + } + Sie_Menu_List_Refresh(menu); + Sie_Menu_List_Draw(menu); + break; + case SIE_MENU_LIST_KEY_ENTER: + if (menu->n_items) { + void (*proc)(); + proc = menu->items[menu->row].proc; + if (proc) { + proc(); + } + } + break; + } + } +} diff --git a/src/resources.c b/src/resources.c new file mode 100644 index 0000000..0b598f6 --- /dev/null +++ b/src/resources.c @@ -0,0 +1,90 @@ +#include +#include +#include "include/sie/settings.h" +#include "include/sie/resources.h" + +IMGHDR *SIE_RES_IMG_WALLPAPER; +SIE_RESOURCES_EXT *SIE_RES_EXT; +unsigned int SIE_RES_EXT_COUNT; +unsigned int SIE_RES_CLIENTS; + +void Sie_Resources_Init() { + if (!SIE_RES_IMG_WALLPAPER) { + size_t len; + char *path; + WSHDR *ws = AllocWS(1024); + Settings_ReadWS(ws, NULL, "wallpaper"); + len = wstrlen(ws); + path = malloc(len + 1); + ws_2str(ws, path, len); + FreeWS(ws); + SIE_RES_IMG_WALLPAPER = CreateIMGHDRFromPngFile(path, 0); + mfree(path); + } + SIE_RES_CLIENTS++; +} + +void Sie_Resources_Destroy() { + if (SIE_RES_CLIENTS) { + SIE_RES_CLIENTS--; + } + if (!SIE_RES_CLIENTS) { + if (SIE_RES_IMG_WALLPAPER) { + mfree(SIE_RES_IMG_WALLPAPER->bitmap); + mfree(SIE_RES_IMG_WALLPAPER); + } + SIE_RES_IMG_WALLPAPER = NULL; + for (unsigned int i = 0; i < SIE_RES_EXT_COUNT; i++) { + SIE_RESOURCES_EXT *res_ext = &(SIE_RES_EXT[i]); + mfree(res_ext->icon->bitmap); + mfree(res_ext->icon); + } + } +} + +/**********************************************************************************************************************/ + +void Sie_Resources_SetWallpaper(WSHDR *ws) { + if (SIE_RES_IMG_WALLPAPER) { + mfree(SIE_RES_IMG_WALLPAPER->bitmap); + mfree(SIE_RES_IMG_WALLPAPER); + } + Settings_UpdateWS(ws, NULL, "wallpaper"); + + size_t len = wstrlen(ws); + char *path = malloc(len + 1); + ws_2str(ws, path, len); + SIE_RES_IMG_WALLPAPER = CreateIMGHDRFromPngFile(path, 0); + mfree(path); +} + +/**********************************************************************************************************************/ + +SIE_RESOURCES_EXT *Sie_Resources_ExtGet(const char *ext) { + SIE_RESOURCES_EXT *res_ext = NULL; + for (unsigned int i = 0; i < SIE_RES_EXT_COUNT; i++) { + if (strcmp(SIE_RES_EXT[i].ext, ext) == 0) { + res_ext = &(SIE_RES_EXT)[i]; + } + } + return res_ext; +} + +SIE_RESOURCES_EXT *Sie_Resources_ExtLoad(const char *file_name, const char *ext) { + const char *dir = "0:\\zbin\\img\\libsie\\ext\\"; + SIE_RESOURCES_EXT *res_ext = Sie_Resources_ExtGet(ext); + if (!res_ext) { + char *path = malloc(strlen(dir) + strlen(file_name) + 1); + sprintf(path, "%s%s", dir, file_name); + IMGHDR *img = CreateIMGHDRFromPngFile(path, 0); + mfree(path); + if (img) { + SIE_RES_EXT = realloc(SIE_RES_EXT, sizeof(SIE_RESOURCES_EXT) * (SIE_RES_EXT_COUNT + 1)); + res_ext = &(SIE_RES_EXT[SIE_RES_EXT_COUNT]); + strcpy(res_ext->ext, ext); + res_ext->icon = img; + SIE_RES_EXT_COUNT++; + } + } + return res_ext; +} diff --git a/src/settings.c b/src/settings.c new file mode 100644 index 0000000..4ee9c55 --- /dev/null +++ b/src/settings.c @@ -0,0 +1,9 @@ +#include + +int Settings_UpdateWS(WSHDR *ws, const char *entry, const char *keyword) { + return SettingsAE_Update_ws(ws, 9, (char *)entry, (char *)keyword); +} + +int Settings_ReadWS(WSHDR *ws, const char *entry, const char *keyword) { + return SettingsAE_Read_ws(ws, 9, (char *)entry, (char *)keyword); +} diff --git a/src/strings.c b/src/strings.c new file mode 100644 index 0000000..80942c0 --- /dev/null +++ b/src/strings.c @@ -0,0 +1,24 @@ +#include +#include +#include + +void Sie_Strings_ToLower(char *str) { + for (unsigned int i = 0; i < strlen(str); i++) { + str[i] = tolower(str[i]); + } +} + +char *Sie_Strings_GetExtByFileName(const char *file_name) { + char *p = strrchr(file_name, '.'); + if (p) { + p++; + size_t len = strlen(file_name) - (p - file_name); + if (len) { + char *ext = malloc(len + 1); + strncpy(ext, p, len); + ext[len] = '\0'; + return ext; + } + } + return NULL; +}