X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fui_exhibit.cc;h=355d0783acabf28ed45061782fd0024154a9d7be;hp=409bd94946e4ea5d53a7407ac5662f159508d315;hb=7ffa5c50d9254af9bd746fc5e6bc8e5db8eda675;hpb=37b68f014b46922b885c6344d6b069cba3c9c3c5 diff --git a/src/ui_exhibit.cc b/src/ui_exhibit.cc index 409bd94..355d078 100644 --- a/src/ui_exhibit.cc +++ b/src/ui_exhibit.cc @@ -1,8 +1,28 @@ #include "ui_exhibit.h" +#include "ui.h" #include "app.h" +#include + +static void draw_titlebar(); +static void draw_tabs(); +static void layout_text(const char *text); + +static Vec3 pos; +static Vec2 size; +static float text_padding; +static Exhibit *ex; +static int vis_tab; +static float scroll; +static std::vector text_lines; +static AudioStream *voice; + bool exui_init() { + size.x = 150; + size.y = 180; + text_padding = size.x * 0.01; + return true; } @@ -10,12 +30,103 @@ void exui_shutdown() { } +void exui_change_tab(int dir) +{ +} + +void exui_scroll(float delta) +{ +} + +bool exui_raycast(const Ray &ray) +{ + return false; +} + void exui_update(float dt) { + if(exsel_active.ex != ex) { + ex = exsel_active.ex; + scroll = 0.0f; + vis_tab = 0; + text_lines.clear(); + if(voice) voice->stop(); + + if(ex) { + int num_data = ex->data.size(); + for(int i=0; idata[i].type == EXDATA_INFO) { + layout_text(ex->data[i].text.c_str()); + voice = ex->data[i].voice; + } + } + + if(voice) { + voice->play(AUDIO_PLAYMODE_ONCE); + } + } else { + voice = 0; + } + } } void exui_draw() { if(!exsel_active) return; + draw_titlebar(); + draw_tabs(); +} + +static void draw_titlebar() +{ +} + +static void draw_tabs() +{ +} + +static void layout_text(const char *text) +{ + text_lines.clear(); + if(!text) return; + if(!ui_font) return; + + dtx_use_font(ui_font, ui_font_size); + + float pos = text_padding; + text_lines.push_back(text); + const char *last_break = 0; + + while(*text) { + if(*text == '\n') { // paragraph break + text_lines.push_back(text); + text_lines.push_back(++text); + pos = text_padding; + last_break = 0; + continue; + } + + int code = dtx_utf8_char_code(text); + const char *next = dtx_utf8_next_char((char*)text); + pos += dtx_glyph_width(code); + + if(pos >= size.x - text_padding) { + if(text == text_lines.back()) { + // not even a single character fits on a line... abort + warning_log("text layout failed. glyph %d doesn't fit in line (%g)\n", code, size.x - 2.0 * text_padding); + text_lines.clear(); + return; + } + if(last_break) { + text_lines.push_back(last_break + 1); + last_break = 0; + } else { + // no good point to break, just break here + text_lines.push_back(text); + } + pos = text_padding; + } + text = next; + } }