Commit e48416cf by beoran

Work on moving the Zori GUI from Ruby down to C.

parent 0d1ede8a
......@@ -28,6 +28,7 @@ struct ui_state {
/* HUD page and widgets */
struct ui_state_hud {
int background_image;
zori_id page;
zori_id dialog;
} hud;
......
......@@ -432,8 +432,8 @@ struct zori_widget;
/* Event handler results. */
enum zori_handle_result {
ZORI_HANDLE_ERROR = -1, /* An error ocurred, stop propagating to children.*/
ZORI_HANDLE_DONE = 0, /* The event was handled and consumed, no need to propagate to children automatically (widget may re-send event manually to children.)*/
ZORI_HANDLE_ERROR = -1, /* An error ocurred, stop propagating to siblings as wel.*/
ZORI_HANDLE_DONE = 0, /* The event was handled and consumed, no need to propagate to children automatically (widget may re-send event manually to children.) Sibling still receive the event. */
ZORI_HANDLE_IGNORE = 1, /* Event wasn't handled, propagate to children. */
ZORI_HANDLE_PASS = 2, /* Event was handled, but needs to be propagated.*/
};
......@@ -620,6 +620,17 @@ struct zori_widget_array miao_of_type(struct zori_widget *);
struct zori_screen;
struct zori_console;
/** Icons of the root style (see below) */
struct zori_root_style_icons {
zori_bitmap * paused;
};
/* Style elements specific for the root element. These are global to the
* whole GUI under the given root.*/
struct zori_root_style {
struct zori_root_style_icons icons;
};
/*
* Root level widget, my spread out over several displays.
* In Zori, there can only be a single root level widget active.
......@@ -631,7 +642,9 @@ struct zori_root {
/* Current active screen widget if any. */
struct zori_screen * active_screen;
/* Current active console if any. */
struct zori_console * console;
struct zori_console * console;
/*- Style elements for all the GUI, not per widget. */
struct zori_root_style style;
};
/* Forward declaration of a page. */
......
......@@ -5,24 +5,66 @@
#define ZORI_WIDGET_TYPE_LONGTEXT ZORI_WIDGET_TYPE('z','l','t','x')
/* A descriptor for the current state of the longtext */
struct zori_longtext_state {
/*- Time waited between display of characters */
double wait;
/*- Virtual text page we are currently on. */
int page;
/*- Line of text we are currently on. */
int line;
/*- Currently paused or not. */
int paused;
/*- Total amount of lines to display for this text. */
int total;
/*- Current position in current line. */
int position;
/*- Animation timer. */
double anitime;
};
/** Flags for the settings of a longtext widget.*/
enum zori_longtext_setting_flag {
/*- Disable animation of pause marker. */
ZORI_LONGTEXT_SETTING_FLAG_STATIC_MARKER = 1 << 0,
/*- Show letters oneby one in stead of space separated words. */
ZORI_LONGTEXT_SETTING_FLAG_SHOW_LETTERS = 1 << 1,
};
/* A descriptor for the configurable size settings of a
* longtext. */
struct zori_longtext_settings {
/*- Amount of lines to display in one virtual page of text. */
int lines;
/*- Vertcal spacing between lines. */
int spacing;
/*- Delay between display of the individual characters. */
double delay;
/*- Several flags that modify the behavior of the box. */
enum zori_longtext_setting_flag flags;
};
struct zori_longtext {
struct zori_widget widget;
int align;
zori_string * caption;
zori_string * text;
int line_start, line_stop, line_pos; /* Current text "window". */
int line_max, line_height; /* text constants. */
int page_lines;
/* Text "window" size for one "page" of text in amount of lines. */
int paused;
double delay;
double delay_total;
/*- Configurable settings. */
struct zori_longtext_settings settings;
/*- Current state. */
struct zori_longtext_state state;
};
#include "zori_longtext_proto.h"
#include "zori_longtext_proto.h"
#endif
......@@ -15,13 +15,7 @@ struct zori_page {
};
struct zori_page * zori_widget_to_page(struct zori_widget * widget);
struct zori_page * zori_page_new(zori_id id, struct zori_widget * parent);
zori_id zori_new_page(zori_id id, zori_id parent_id);
#include "zori_page_proto.h"
#endif
......
/* This file was generated by runcprotoall */
#ifndef CPROTO /* Needed to protect cproto from itself. */
#ifndef zori_page_proto_included
/* src/zori/zori_page.c */
struct zori_page *zori_widget_to_page(struct zori_widget *widget);
struct zori_page *zori_id_to_page(zori_id id);
int zori_page_on_draw(union zori_event *event);
struct zori_page *zori_page_new(zori_id id, struct zori_widget *parent);
zori_id zori_new_page(zori_id id, zori_id parent_id);
#endif /* zori_page_proto_included */
#endif /* CPROTO */
\ No newline at end of file
......@@ -3,7 +3,9 @@
#include "zori.h"
#define ZORI_WIDGET_TYPE_SCREEN ZORI_WIDGET_TYPE('z','s','c','r')
enum {
ZORI_WIDGET_TYPE_SCREEN = ZORI_WIDGET_TYPE('z','s','c','r')
};
/* The top level widget for a single display. */
struct zori_screen {
......@@ -18,10 +20,7 @@ struct zori_screen {
};
zori_id zori_new_screen(zori_id id, zori_display * display);
struct zori_screen * zori_widget_to_screen(struct zori_widget * widget);
#include "zori_screen_proto.h"
#endif
......
/* This file was generated by runcprotoall */
#ifndef CPROTO /* Needed to protect cproto from itself. */
#ifndef zori_screen_proto_included
/* src/zori/zori_screen.c */
struct zori_screen *zori_widget_to_screen(struct zori_widget *widget);
struct zori_screen *zori_get_screen(zori_id id);
int zori_screen_on_mouse_axes(union zori_event *event);
int zori_screen_on_sysevent(union zori_event *event);
void zori_draw_cursor(const struct zori_cursor *cursor);
void zori_draw_cursors(const struct zori_cursors *cursors);
int zori_screen_on_overdraw(union zori_event *event);
struct zori_screen *zori_screen_init(struct zori_screen *screen, zori_display *display);
struct zori_screen *zori_screen_new(zori_id id, zori_display *display);
zori_id zori_new_screen(zori_id id, zori_display *display);
zori_id zori_active_page(zori_id screen_id);
zori_id zori_screen_go(zori_id screen_id, zori_id page_id, void *data);
struct zori_cursor *zori_cursor_set_style(struct zori_cursor *cursor, struct zori_style style);
struct zori_screen *zori_screen_set_keyjoy_cursor_style(struct zori_screen *screen, struct zori_style style);
struct zori_screen *zori_screen_set_mouse_cursor_style(struct zori_screen *screen, struct zori_style style);
zori_id zori_set_keyjoy_cursor_style(zori_id id, struct zori_style style);
zori_id zori_set_mouse_cursor_style(zori_id id, struct zori_style style);
#endif /* zori_screen_proto_included */
#endif /* CPROTO */
\ No newline at end of file
......@@ -3,70 +3,7 @@
struct zori_widget;
void zori_widget_cleanup_widget_only(struct zori_widget * widget);
void zori_widget_destroy_widget_only(struct zori_widget * widget);
void zori_widget_call_destructor_and_destroy(struct zori_widget * widget);
void zori_widget_destroy(struct zori_widget * widget);
int zori_widget_accepts_event(struct zori_widget *widget, union zori_event *event);
int zori_widget_self_raise_event(struct zori_widget *widget, union zori_event *event);
int zori_widget_raise_event(struct zori_widget *widget, union zori_event *event);
int zori_widget_raise_system_event(struct zori_widget *widget, zori_system_event *sysev);
int zori_widget_raise_draw_event(struct zori_widget *widget);
int zori_widget_raise_overdraw_event(struct zori_widget *widget);
int zori_widget_raise_done_event(struct zori_widget *widget);
int zori_widget_raise_free_event(struct zori_widget *widget);
int zori_widget_raise_update_event(struct zori_widget *widget, double dt);
int zori_widget_raise_action_event(struct zori_widget *widget);
int zori_widget_raise_internal_action_event(struct zori_widget * widget);
int zori_widget_raise_internal_close_event(struct zori_widget * widget);
int zori_widget_raise_close_event(struct zori_widget *widget, struct zori_widget *from);
int zori_widget_compare(const void *v1, const void *v2);
struct zori_handler *zori_widget_add_handler(struct zori_widget *widget, zori_event_type type, zori_handler_func *handler, void *data);
struct zori_handler *zori_widget_add_handlers(struct zori_widget *widget, struct zori_handler *handlers, size_t amount);
struct zori_widget *zori_widget_done(struct zori_widget *widget);
void zori_widget_free(struct zori_widget *widget);
struct zori_widget *zori_widget_add_child(struct zori_widget *parent, struct zori_widget *child);
zori_id zori_widget_margins_(struct zori_widget *widget, int left, int top, int right, int bottom);
zori_id zori_widget_margin_(struct zori_widget *widget, int size);
void zori_widget_draw_background(struct zori_widget *widget);
enum zori_handle_result
zori_widget_must_draw_children(struct zori_widget * widget);
int zori_widget_visible(struct zori_widget *widget);
int zori_widget_active(struct zori_widget *widget);
int zori_widget_active_(struct zori_widget *widget, int set);
int zori_widget_visible_(struct zori_widget *widget, int set);
int zori_widget_hover(struct zori_widget *widget);
int zori_widget_hover_(struct zori_widget *widget, int set);
int zori_widget_marked(struct zori_widget *widget);
int zori_widget_marked_(struct zori_widget *widget, int set);
int zori_widget_ready(struct zori_widget *widget);
int zori_widget_ready_(struct zori_widget *widget, int set);
int zori_xy_inside_widget_p(struct zori_widget *widget, double x, double y);
zori_font *zori_widget_font(struct zori_widget *widget);
zori_color zori_widget_forecolor(struct zori_widget *widget);
zori_color zori_widget_backcolor(struct zori_widget *widget);
int zori_widget_h(struct zori_widget *widget);
int zori_widget_w(struct zori_widget *widget);
int zori_widget_x(struct zori_widget *widget);
int zori_widget_y(struct zori_widget *widget);
int zori_widget_count_children(struct zori_widget *widget);
struct zori_widget *zori_widget_get_child(struct zori_widget *widget, int index);
zori_id zori_widget_paddings_(struct zori_widget *widget, int left, int top, int right, int bottom);
zori_id zori_widget_padding_(struct zori_widget *widget, int size);
zori_font *zori_widget_text_font(struct zori_widget *widget);
struct zori_widget *zori_widget_init(struct zori_widget *widget, zori_widget_type type, zori_id id, struct zori_widget *parent, zori_rebox *box, struct zori_style *style);
struct zori_widget *zori_widget_initall(struct zori_widget *widget, zori_widget_type type, int id, struct zori_widget *parent, zori_rebox *box, struct zori_style *style, struct zori_handler *handlers, size_t amount);
void zori_widget_handle_event(struct zori_widget *widget, union zori_event *event);
struct zori_widget *zori_widget_find_parent(struct zori_widget *widget, _Bool (*predicate)(struct zori_widget *parent, void *extra), void *extra);
bool zori_widget_is_type(struct zori_widget * widget, zori_widget_type type);
_Bool zori_widget_is_type_predicate(struct zori_widget *widget, void *extra);
struct zori_widget *zori_widget_get_parent_of_type(struct zori_widget *widget, zori_widget_type type);
struct zori_screen *zori_widget_get_screen(struct zori_widget *widget);
int zori_mark_widget(struct zori_widget *widget);
zori_id zori_widget_set_int_result(struct zori_widget * widget, int value);
zori_id zori_widget_set_string_result(struct zori_widget * widget, zori_string * value);
zori_id zori_widget_set_closed_result(struct zori_widget * widget, int value);
#include "zori_widget_proto.h"
#endif
......
/* This file was generated by runcprotoall */
#ifndef CPROTO /* Needed to protect cproto from itself. */
#ifndef zori_widget_proto_included
/* src/zori/zori_widget.c */
_Bool zori_widget_is_type(struct zori_widget *widget, zori_widget_type type);
_Bool zori_widget_is_type_predicate(struct zori_widget *widget, void *extra);
struct zori_widget *zori_widget_get_parent_of_type(struct zori_widget *widget, zori_widget_type type);
struct zori_screen *zori_widget_get_screen(struct zori_widget *widget);
int zori_widget_accepts_event(struct zori_widget *widget, union zori_event *event);
int zori_widget_self_raise_event(struct zori_widget *widget, union zori_event *event);
int zori_widget_raise_event(struct zori_widget *widget, union zori_event *event);
int zori_widget_raise_system_event(struct zori_widget *widget, zori_system_event *sysev);
int zori_widget_raise_draw_event(struct zori_widget *widget);
int zori_widget_raise_overdraw_event(struct zori_widget *widget);
int zori_widget_raise_done_event(struct zori_widget *widget);
int zori_widget_raise_free_event(struct zori_widget *widget);
int zori_widget_raise_update_event(struct zori_widget *widget, double dt);
int zori_widget_raise_action_event(struct zori_widget *widget);
int zori_widget_raise_internal_action_event(struct zori_widget *widget);
int zori_widget_raise_close_event(struct zori_widget *widget, struct zori_widget *from);
int zori_widget_compare(const void *v1, const void *v2);
struct zori_handler *zori_widget_add_handler(struct zori_widget *widget, zori_event_type type, zori_handler_func *handler, void *data);
struct zori_handler *zori_widget_add_handlers(struct zori_widget *widget, struct zori_handler *handlers, size_t amount);
struct zori_style *zori_widget_get_mark_style(struct zori_widget *widget);
struct zori_style *zori_widget_get_hover_style(struct zori_widget *widget);
struct zori_widget *zori_widget_done(struct zori_widget *widget);
void zori_widget_free(struct zori_widget *widget);
struct zori_widget *zori_widget_add_child(struct zori_widget *parent, struct zori_widget *child);
zori_id zori_widget_margins_(struct zori_widget *widget, int left, int top, int right, int bottom);
zori_id zori_widget_margin_(struct zori_widget *widget, int size);
void zori_widget_draw_background(struct zori_widget *widget);
enum zori_handle_result zori_widget_must_draw_children(struct zori_widget *widget);
int zori_widget_visible(struct zori_widget *widget);
int zori_widget_active(struct zori_widget *widget);
int zori_widget_active_(struct zori_widget *widget, int set);
int zori_widget_visible_(struct zori_widget *widget, int set);
int zori_widget_live(struct zori_widget *widget);
int zori_widget_live_(struct zori_widget *widget, int set);
int zori_widget_hover(struct zori_widget *widget);
int zori_widget_hover_(struct zori_widget *widget, int set);
int zori_widget_marked(struct zori_widget *widget);
int zori_widget_marked_(struct zori_widget *widget, int set);
int zori_widget_ready(struct zori_widget *widget);
int zori_widget_ready_(struct zori_widget *widget, int set);
int zori_xy_inside_widget_p(struct zori_widget *widget, double x, double y);
zori_font *zori_widget_font(struct zori_widget *widget);
zori_color zori_widget_forecolor(struct zori_widget *widget);
zori_color zori_widget_backcolor(struct zori_widget *widget);
int zori_widget_h(struct zori_widget *widget);
int zori_widget_w(struct zori_widget *widget);
int zori_widget_x(struct zori_widget *widget);
int zori_widget_y(struct zori_widget *widget);
int zori_widget_count_children(struct zori_widget *widget);
struct zori_widget *zori_widget_get_child(struct zori_widget *widget, int index);
zori_id zori_widget_paddings_(struct zori_widget *widget, int left, int top, int right, int bottom);
zori_id zori_widget_padding_(struct zori_widget *widget, int size);
zori_font *zori_widget_text_font(struct zori_widget *widget);
struct zori_widget *zori_widget_init(struct zori_widget *widget, zori_widget_type type, zori_id id, struct zori_widget *parent, zori_rebox *box, struct zori_style *style);
struct zori_widget *zori_widget_initall(struct zori_widget *widget, zori_widget_type type, int id, struct zori_widget *parent, zori_rebox *box, struct zori_style *style, struct zori_handler *handlers, size_t amount);
void zori_widget_handle_event(struct zori_widget *widget, union zori_event *event);
struct zori_widget *zori_widget_find_parent(struct zori_widget *widget, _Bool (*predicate)(struct zori_widget *parent, void *extra), void *extra);
int zori_mark_widget(struct zori_widget *widget);
zori_id zori_widget_set_int_result(struct zori_widget *widget, int value);
zori_id zori_widget_set_string_result(struct zori_widget *widget, zori_string *value);
zori_id zori_widget_set_closed_result(struct zori_widget *widget, int value);
zori_id zori_set_mark_style(zori_id id, struct zori_style style);
zori_id zori_set_hover_style(zori_id id, struct zori_style style);
void zori_widget_move_self_by(struct zori_widget *widget, int dx, int dy);
void zori_widget_resize_self_by(struct zori_widget *widget, int dw, int dh);
void zori_widget_move_by(struct zori_widget *widget, int dx, int dy);
void zori_widget_move_to(struct zori_widget *widget, int x, int y);
void zori_widget_move_self_to(struct zori_widget *widget, int x, int y);
void zori_widget_resize_self_to(struct zori_widget *widget, int w, int h);
void zori_widget_fit_to_children(struct zori_widget *widget);
#endif /* zori_widget_proto_included */
#endif /* CPROTO */
\ No newline at end of file
......@@ -3,7 +3,7 @@
#include "mem.h"
#include "monolog.h"
/*
GLuint glh_shader_make(GLenum type, char * data) {
const GLchar * gldata = (const GLchar *) data;
GLint status;
......@@ -63,3 +63,4 @@ GLuint gl_program_make(GLuint * shaders, int amount) {
return program;
}
*/
......@@ -255,34 +255,47 @@ int monolog_log(char * file, int line, char * level, char * format, ...) {
}
/* Log function helper. */
static int monolog_log_to_stdio(
FILE * fout, char * file, int line, char * level, char * format,
va_list args) {
int res;
if (fout) {
fprintf(fout, "%s: %s: %d: ", level, file, line);
res = vfprintf(fout, format, args);
if (format[strlen(format) - 1] != '\n') {
fputc('\n', fout);
}
return res;
}
return -1;
}
/* Log function for logger that logs to stdout. */
int monolog_stdout_logger
(char * file, int line, char * level, void * data, char * format, va_list args)
{
(void) data;
printf("%s: %s: %d: ", level, file, line);
return vprintf(format, args);
return monolog_log_to_stdio(stdout, file, line, level, format, args);
}
/* Log function for logger that logs to stderr. */
int monolog_stderr_logger
(char * file, int line, char * level, void * data, char * format, va_list args)
{
int res;
(void) data;
fprintf(stderr, "%s: %s: %d: ", level, file, line);
return vfprintf(stderr, format, args);
return monolog_log_to_stdio(stderr, file, line, level, format, args);
}
/** Log function for logger that logs to a FILE. */
int monolog_file_logger
(char * file, int line, char * level, void * data, char * format, va_list args) {
int res;
FILE * fout = data;
if (fout) {
fprintf(fout, "%s: %s: %d: ", level, file, line);
return vfprintf(fout, format, args);
}
return -1;
return monolog_log_to_stdio(fout, file, line, level, format, args);
}
......
......@@ -607,7 +607,7 @@ State * state_init(State * self, BOOL fullscreen) {
#define STATE_FONTNAME "GranaPadano.ttf"
#define STATE_FONT_INDEX 20000
if(!store_load_ttf_font(STATE_FONT_INDEX, "font/" STATE_FONTNAME, -16, 0)) {
if(!store_load_ttf_font(STATE_FONT_INDEX, "font/" STATE_FONTNAME, -24, 0)) {
return state_errmsg_(self, "Error loading " STATE_FONTNAME);
}
......@@ -654,7 +654,7 @@ State * state_init(State * self, BOOL fullscreen) {
style.text.color = color_rgb(255,255,255);
style.back.color = color_rgba(64,0,0, 191);
Rebox bounds = { {20, 20} , {600, 400} };
self->console = zori_console_new(1, &bounds, &style);
self->console = zori_console_new(-1, &bounds, &style);
if(!self->console) {
return state_errmsg_(self, "Out of memory when allocating console.");
}
......
......@@ -19,17 +19,19 @@
static struct ui_state the_ui_state;
char POEM_TEXT[] = "After mankind's summer, winter suddenly came"
"Most reached for the stars, but some remained"
"The earth scarred by the Ancients unhostpitable"
"The hopes low, and so much wisdom forgotten"
"Yet when it seemed the last hour struck"
"Our hope returned, a savior arose"
"Lord Kei, who by Creator's grace"
"Restored the Trees that guard us all from harm"
"Thus ushered in a new millennial spring"
"Lord Kei, watch over us and protect us"
"Until the Travellers return with bounty of the stars";
char POEM_TEXT[] =
"µµµµµ µµµµµµµµµ µµµµµµµ µµµµµµ µµµµµµµµ µµµµ\n"
"After mankind's summer, winter suddenly came\n"
"Most reached for the stars, but some remained\n"
"The earth scarred by the Ancients unhostpitable\n"
"The hopes low, and so much wisdom forgotten\n"
"Yet when it seemed the last hour struck\n"
"Our hope returned, a savior arose\n"
"Lord Kei, who by Absolute grace\n"
"Restored the Trees that guard us all from harm\n"
"Thus ushered in a new millennial spring\n"
"Lord Kei, watch over us and protect us\n"
"Until the Travellers return with bounty of the stars\n";
char INTRO_TEXT[] = "Millennia have passed since mankind first traveled to the moon. "
"Civilizations rose as never before, yet to fall again. "
......@@ -51,7 +53,11 @@ void ui_state_init_hud(struct ui_state * ui,
ui->hud.page = zori_new_page(-1, ui->screen);
LOG_NOTE("HUD page: %d\n", ui->hud.page);
box = rebox_make(10, 300, 620, 200);
ui->hud.dialog = zori_new_longtext(-1, ui->hud.page, &box, INTRO_TEXT);
ui->hud.dialog = zori_new_longtext(-1, ui->hud.page, &box, POEM_TEXT);
ui->hud.background_image = ui->main.background_image;
/* store_load_bitmap_id(1004, "/image/background/bluesky2.jpg"); */
zori_set_background_bitmap(ui->hud.page,
store_get_bitmap(ui->hud.background_image));
}
/* Set up Zori GUI. */
......@@ -80,8 +86,8 @@ zori_font * font
}
ui->main.background_image = store_load_bitmap_id(1000, "/image/background/eruta_mainmenu.png");
ui->mouse_image = store_load_bitmap_id(1001, "image/gin/fountain-pen_32.png");
ui->keyjoy_image = store_load_bitmap_id(1002, "image/gin/fountain-pen_32.png");
ui->mouse_image = store_load_bitmap_id(1001, "/image/gin/fountain-pen_32.png");
ui->keyjoy_image = store_load_bitmap_id(1002, "/image/gin/fountain-pen_32.png");
......@@ -134,6 +140,7 @@ zori_font * font
}
ui_state_init_hud(ui, display, font);
zori_screen_go(ui->screen, ui->main.page, NULL);
}
......@@ -144,16 +151,28 @@ void ui_handle_main_menu(struct ui_state * ui, int selected) {
LOG_NOTE("Resume");
} else if (selected == ui->main.button.new) {
LOG_NOTE("New");
zori_screen_go(ui->screen, ui->hud.page, NULL);
}
}
void ui_handle_dialog_text(struct ui_state * ui, int selected) {
LOG_NOTE("Dialog finished: %d\n", selected);
}
void ui_state_update(struct ui_state * ui,
zori_display * display, zori_font * font) {
int value = 0;
if ((value = zori_result(ui->main.menu))) {
value = zori_result(ui->main.menu);
if (value) {
ui_handle_main_menu(ui, value);
}
}
value = zori_result(ui->hud.dialog);
if (value) {
ui_handle_dialog_text(ui, value);
}
}
......
......@@ -37,7 +37,7 @@ static char utf8_length_table[256] = {
/* Returns the length of the utf8 character that starts at
* str, or negative if str doesn ot point to the beginning byte of
* str, or negative if str does not point to the beginning byte of
* of a valid utf8 character.
*/
int utf8_decode_length(char * str) {
......
......@@ -110,6 +110,7 @@ zori_id zori_initialize_root(void) {
if (the_zori_root) return ZORI_ID_OK;
the_zori_root = calloc(1, sizeof(*the_zori_root));
if (!the_zori_root) return ZORI_ID_ENOMEM;
the_zori_root->style.icons.paused = NULL;
return ZORI_ID_OK;
}
......@@ -304,8 +305,8 @@ void zori_draw_all(void) {
/* Dispatches system events throughout the GUI. */
int zori_handle_system_event(zori_system_event * sysev) {
/* All events are passed on to the console regardless if it is active.
* Otherwise, theget events go into the system. */
/* All events are passed on to the console if it is active.
* Otherwise, the events are passed to the root widget. */
if (!the_zori_root) {
return ZORI_ID_EINVAL;
}
......@@ -373,5 +374,13 @@ int zori_result_string(zori_id id, char ** result, size_t * size);
int zori_result_buffer(zori_id id, char ** result, size_t * size);
int zori_mouse_button_event_unpack
(const union zori_event * event, float * x, float * y, int * b) {
int ok = event->type == ZORI_SYSTEM_EVENT_MOUSE_BUTTON_DOWN;
ok = ok || (event->type == ZORI_SYSTEM_EVENT_MOUSE_BUTTON_UP);
if (!ok) return 0;
* x = event->sys.ev->mouse.x;
* y = event->sys.ev->mouse.y;
* b = event->sys.ev->mouse.button;
return event->sys.ev->mouse.button + 1;
}
......@@ -313,8 +313,7 @@ int zori_console_draw(union zori_event * zevent) {
/** Activates or deactivates the console. */
void zori_console_active_(struct zori_console * self, int active) {
if(!self) return;
zori_widget_active_(&self->widget, active);
zori_widget_visible_(&self->widget, active);
zori_widget_live_(&self->widget, active);
}
/** Returns nonzero if console is active zero if not. */
......
......@@ -6,9 +6,15 @@
#include "zori_widget.h"
#include "zori_caption.h"
#include "zori_longtext.h"
#include "zori_page.h"
#include <math.h>
#define ZORI_LONGTEXT_LINE_POS_MAX 99999
#define ZORI_LONGTEXT_ANIMATION_CYCLE_TIME 4.0
#define ZORI_LONGTEXT_PAUSE_MARKER_DAMPER 2.0
#define ZORI_LONGTEXT_PAUSE_MARKER_SCALE 0.75
#define ZORI_LONGTEXT_DEFAULT_DELAY 0.2
struct zori_longtext * zori_widget_to_longtext(struct zori_widget * widget) {
......@@ -17,17 +23,43 @@ struct zori_longtext * zori_widget_to_longtext(struct zori_widget * widget) {
}
static bool
zori_longtext_calculate_lines_aid(int line_num, const zori_string *line, void * extra) {
struct zori_longtext * longtext = extra;
longtext->state.total = line_num + 1;
return true;
}
/** Calculates the amount of lines needed for the longtext as per al_do_multiline_text
* The value is set in longtext->state.total and returned;
*/
int zori_longtext_calculate_lines(struct zori_longtext * longtext) {
double width = longtext->widget.inner.size.x;
longtext->state.total = 0;
al_do_multiline_ustr(zori_widget_font(&longtext->widget), width,
longtext->text, zori_longtext_calculate_lines_aid, longtext);
return longtext->state.total;
}
struct zori_longtext *
zori_longtext_set(struct zori_longtext * longtext, const zori_string * text) {
if (longtext) {
if (longtext->text) {
ustr_free(longtext->text);
longtext->text = NULL;
longtext->state.total = 0;
}
if (text) {
longtext->text = ustr_dup(text);
if (!longtext->text) {
LOG_ERROR("Out of memory in longtext setup.");
longtext->state.total = 0;
LOG_ERROR("Out of memory in longtext setup.\n");
return NULL;
} else {
zori_longtext_calculate_lines(longtext);
LOG_DEBUG("Longtext lines: %d\n", longtext->state.total);
}
}
}
......@@ -53,40 +85,74 @@ void zori_longtext_done(struct zori_longtext * longtext) {
zori_longtext_set(longtext, NULL);
}
/** Gets the number of lines in one page. Always returns at least 1. */
int zori_longtext_page_lines(struct zori_longtext * longtext) {
if (!longtext) return 1;
if (longtext->settings.lines > 1) {
return longtext->settings.lines;
}
return 1;
}
/** Gets the current text page for a longtext. */
/** Sets the number of lines in one page. Sets at least 1. */
int zori_longtext_page_lines_(struct zori_longtext * longtext, int pl) {
if (!longtext) return -1;
if (pl < 1) {
pl = 1;
}
longtext->settings.lines = pl;
return longtext->settings.lines;
}
/** Gets the current text page for a longtext. Page 0 is the first page, etc.*/
int zori_longtext_page(struct zori_longtext * longtext) {
int pl = 1;
if (!longtext) return -2;
return longtext->line_start / longtext->page_lines;
return longtext->state.page;
}
/** Gets the last page number for a longtext or negative on error. */
/** Gets the last page number (inclusive) for a longtext or negative on error. */
int zori_longtext_last_page(struct zori_longtext * longtext) {
int pl = 1;
if (!longtext) return -2;
return longtext->line_max / longtext->page_lines;
pl = zori_longtext_page_lines(longtext);
return longtext->state.total / pl;
}
/** Advances long text to the given page. Automatically unpauses as well. */
int zori_longtext_page_(struct zori_longtext * longtext, int page) {
int pl = 1;
int line = 1;
if (!longtext) return -2;
if (!longtext) return -2;
if (page < 0) return -3;
int line = page * longtext->page_lines;
pl = zori_longtext_page_lines(longtext);
line = page * pl;
/* Check for page overflow. */
if (line >= longtext->line_max) {
return -5;
LOG_NOTE("Selecting page nr %d, line nr %d, limit of %d", page, line, longtext->state.total);