diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 181 |
1 files changed, 124 insertions, 57 deletions
@@ -1,67 +1,134 @@ -#include "memory.h" -#include "plat.h" -#include "rcache.h" -#include "ui.h" +#include <stdio.h> +#include "config.h" #include "library.h" +#include "luigi.h" +#include "memory.h" -UI* ui; -Library* lib; +Library lib; -Font* ffont; -void prog_init(void* memory) { - Heap* fh; - unsigned char* bin; - int bin_size; - int fhs = 1024 * 1024 * 4; - Font* font; - memory_init(memory); - rc_init(); - fh = galloc(sizeof *fh); - init_heap(fh, galloc(fhs), fhs); - bin = load_binary(default_font_location, &bin_size); - font = new_font(fh, bin, default_font_size); - ui = stack_alloc(sizeof *ui); - init_ui(ui, font); - lib = stack_alloc(sizeof *lib); - init_library(lib); - build_library(lib, library_folder); +int libtab_msg( + UIElement *el, + UIMessage msg, + int di, + void *dp +) { + if (msg == UI_MSG_TABLE_GET_ITEM) { + UITableGetItem *m = (UITableGetItem*)dp; + Song* song; + song = &lib.songs[lib.indices[m->index]]; + m->isSelected = 0; + switch (m->column) { + case 0: + return snprintf( + m->buffer, + m->bufferBytes, + "%s", + song->name + ); + case 1: + return snprintf( + m->buffer, + m->bufferBytes, + "%s", + song->artist + ); + case 2: + return snprintf( + m->buffer, + m->bufferBytes, + "%s", + song->album + ); + case 3: + return snprintf( + m->buffer, + m->bufferBytes, + "%s", + song->path + ); + default: return 0; + } + } + return 0; } -void prog_update(void) { - Rectangle l, r, lc, list; - int h, i, c; - rc_begin(); - ui_begin(ui, &l); - rc_add_cmd_rect(&l, theme_background_colour); - - r = rectcut_right(&l, l.w / 2); - h = font_height(ui->font) + theme_padding * 2; - c = lib->song_count; - lc.x = 0; - lc.y = 0; - lc.w = r.w - theme_padding * 2; - lc.h = h * c + theme_padding * (c - 1); - ui_container( - ui, - &r, - &lc, - &lc +int prog_main(void* mem) { + Arena liba; + UIWindow* wi; + UISplitPane* split1, * split2, * split3; + UIPanel* plib, * pctrl, * plist, * pqueue; + UITable* libtab; + memory_init(mem); + init_arena( + &liba, + galloc(library_memory_size), + library_memory_size + ); + build_library(&liba, &lib, library_path); + UIInitialise(); + wi = UIWindowCreate( + 0, + 0, + app_name, + default_window_w, + default_window_h + ); + split1 = UISplitPaneCreate( + &wi->e, + 0, + 0.3f + ); + split3 = UISplitPaneCreate( + &split1->e, + UI_SPLIT_PANE_VERTICAL, + 0.5f ); - list = lc; - list.h = h; - for (i = 0; i < max_songs; i++) { - Song* song = &lib->songs[i]; - if (song->file[0]) { - ui_button(ui, &list, song->name); - list.y += list.h + theme_padding; - } - } - rc_add_cmd_reset_clip(); - ui_end(ui); - rc_flush(); -} + split2 = UISplitPaneCreate( + &split1->e, + 0, + 0.5f + ); + pctrl = UIPanelCreate(&split3->e, UI_PANEL_GRAY); + pctrl->gap = 5; + pctrl->border = UI_RECT_1(5); + + pqueue = UIPanelCreate(&split3->e, UI_PANEL_GRAY); + pqueue->gap = 5; + pqueue->border = UI_RECT_1(5); + UILabelCreate( + &pqueue->e, + 0, + "Queue", + 5 + ); -void prog_deinit(void) { + plist = UIPanelCreate(&split2->e, UI_PANEL_GRAY); + plist->gap = 5; + plist->border = UI_RECT_1(5); + UILabelCreate( + &plist->e, + 0, + "Playlist", + 8 + ); + plib = UIPanelCreate(&split2->e, UI_PANEL_GRAY); + plib->gap = 5; + plib->border = UI_RECT_1(5); + UILabelCreate( + &plib->e, + 0, + "Library", + 7 + ); + libtab = UITableCreate( + &plib->e, + UI_ELEMENT_H_FILL | UI_ELEMENT_V_FILL, + "Track\tArtist\tAlbum\tFilename" + ); + libtab->itemCount = lib.cnt; + libtab->e.messageUser = libtab_msg; + UITableResizeColumns(libtab); + return UIMessageLoop(); } |