Commit 137271ef by beoran

Long text implemented but not tested, moving GUI setup to ui.c but move is not complete yet.

parent 177647ed
#ifndef ui_H_INCLUDED
#define ui_H_INCLUDED
/* Data struct for the particular GUI state */
struct ui_state {
zori_id screen;
zori_id console;
/* main page/menu */
struct ui_state_main {
zori_id page;
zori_id menu;
/* menu buttons */
struct ui_state_main_buttons {
zori_id resume;
zori_id new;
zori_id settings;
} button;
} main;
/* HUD page and widgets */
struct ui_state_hud {
zori_id page;
} hud;
/* Settings page and widgets */
struct ui_state_settings {
zori_id page;
zori_id menu;
} settings;
};
void ui_setup(void);
void ui_state_init(struct ui_state * ui);
......
......@@ -284,11 +284,12 @@ static inline void * zori_event_set_data(union zori_event * event, void * data)
return event->any.data = data;
}
/* A style part is a color, image and font applied to a part of the GUI. */
/* A style part is a color, image, font, and font flags applied to a part of the GUI. */
struct zori_stylepart {
zori_color color;
zori_bitmap * bitmap;
zori_font * font;
int font_flags;
};
/* A style is a set of style parts for different parts of the GUI. */
......@@ -589,6 +590,9 @@ int zori_widget_x(struct zori_widget *widget);
int zori_widget_y(struct zori_widget *widget);
int zori_xy_inside_widget_p(struct zori_widget * widget, double x, double y);
zori_font * zori_widget_text_font(struct zori_widget * widget);
zori_font * zori_text_font(zori_id id);
void zori_widget_drawroundframe(struct zori_widget *self);
......
......@@ -3,6 +3,8 @@
#include "zori.h"
#define ZORI_WIDGET_TYPE_LONGTEXT ZORI_WIDGET_TYPE('z','l','t','x')
struct zori_longtext {
struct zori_widget widget;
int align;
......@@ -14,10 +16,51 @@ struct zori_longtext {
int page_lines;
/* Text "window" size for one "page" of text in amount of lines. */
int paused;
double delay;
double delay_total;
};
struct zori_longtext *zori_widget_to_longtext(struct zori_widget *widget);
struct zori_longtext *zori_longtext_set(struct zori_longtext *longtext, const zori_string *text);
struct zori_longtext *zori_longtext_set_cstr(struct zori_longtext *longtext, const char *cstr);
struct zori_longtext *zori_longtext_init_cstr(struct zori_longtext *longtext, const char *cstr);
void zori_longtext_done(struct zori_longtext *longtext);
int zori_longtext_page(struct zori_longtext *longtext);
int zori_longtext_last_page(struct zori_longtext *longtext);
int zori_longtext_page_(struct zori_longtext *longtext, int page);
int zori_longtext_at_end(struct zori_longtext *longtext);
void zori_longtext_update_longtext(struct zori_longtext *longtext, double dt);
int zori_longtext_longtext_at_end(struct zori_longtext *longtext);
void zori_longtext_draw_text(struct zori_longtext *longtext);
void zori_longtext_draw_partial_text(struct zori_longtext *longtext);
void zori_draw_longtext(struct zori_longtext *longtext);
zori_id zori_set_line_stop(zori_id index, int stop);
zori_id zori_line_start_(zori_id index, int start);
int zori_delay_(zori_id index, double delay);
int zori_line_stop(int index);
int zori_line_start(int index);
double zori_delay(int index);
int zori_page_lines_(zori_id index, int lines);
int zori_page_lines(int index);
int zori_paused_(zori_id index, int paused);
int zori_paused(zori_id index);
int zori_page(zori_id index);
int zori_last_page(zori_id index);
int zori_at_end(zori_id index);
int zori_page_(zori_id index, int page);
int zori_next_page(zori_id index);
int zori_previous_page(int index);
int zori_longtext_on_mouse_axes(union zori_event *event);
int zori_longtext_on_mouse_click(union zori_event *event);
int zori_longtext_on_draw(union zori_event *event);
struct zori_longtext *zori_longtext_init(struct zori_longtext *longtext, const char *text);
struct zori_longtext *zori_longtext_new(zori_id id, zori_id parent_id, zori_box *box, const char *text);
zori_id zori_new_longtext(zori_id id, zori_id parent, zori_box *box, const char *text);
#endif
......@@ -500,44 +500,7 @@ int state_initjoystick(State * self) {
/* Initialize the GUI for the Eruta engine. */
State * state_init_gui(State * self, BOOL fullscreen) {
/* Set up Zori GUI. */
zori_id main_page, main_menu;
struct zori_style style;
Rebox box;
memset(&style, 0, sizeof(style));
style.text.font = self->font;
style.text.color = color_rgb(255,255,255);
style.back.color = color_rgba(64,0,0, 191);
if ( !ZORI_ID_OK_P(zori_start(&style)) ) {
return state_errmsg_(self, "Out of memory when allocating GUI.");
}
self->ui.screen = zori_new_screen(-1, self->display);
if(!ZORI_ID_OK_P(self->ui.screen)) {
return state_errmsg_(self, "Could not init GUI screen.\n");
}
main_page = zori_new_page(-1, self->ui.screen);
LOG_NOTE("Main page: %d\n", main_page);
box = rebox_make(280, 80, 140, 240);
main_menu = zori_new_menu(-1, main_page, &box);
LOG_NOTE("Main menu: %d\n", main_menu);
{
Rebox box = rebox_make(300, 100, 100, 60);
zori_id button = zori_new_button(-1, main_menu, &box, "Button 1");
LOG_NOTE("Button: %d\n", button);
}
{
Rebox box = rebox_make(300, 200, 100, 60);
zori_id button = zori_new_button(-1, main_menu, &box, "Button 2");
LOG_NOTE("Button: %d\n", button);
}
return self;
ui_state_init(&self->ui);
}
......
#include "eruta.h"
#include "image.h"
#include "store.h"
#include "zori.h"
#include "zori_screen.h"
#include "zori_console.h"
#include "zori_button.h"
#include "zori_page.h"
#include "zori_menu.h"
#include "ui.h"
/* This file contains the concrete implementation of the Eruta GUI
* and it's various GUI screens and pages. */
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 INTRO_TEXT[] = "Millennia have passed since mankind first traveled to the moon. "
"Civilizations rose as never before, yet to fall again. "
"When all hope seemed lost, the 21 trees sprouted from the earth. "
"They brought mysterious powers that protected and strengthened mankind. "
"Hi!\n\n"
"Hello µ world, this is me, 無 life should be\nfun for everyone!";
char INTRO_TEXT2[] = "Something happened, and I was changed!";
zori_id ui_state_make_sub_menu(zori_id parent, int x, int y, int w, int bh);
void ui_state_init(struct ui_state * ui) { }
#ifdef COMMENT_
/* Set up Zori GUI. */
void ui_state_init(struct ui_state * ui, zori_displkay * display) {
struct zori_style style;
Rebox box;
memset(&style, 0, sizeof(style));
style.text.font = self->font;
style.text.color = color_rgb(255,255,255);
style.back.color = color_rgba(64,0,0, 191);
if ( !ZORI_ID_OK_P(zori_start(&style)) ) {
return state_errmsg_(self, "Out of memory when allocating GUI.");
}
self->ui.screen = zori_new_screen(-1, self->display);
if(!ZORI_ID_OK_P(self->ui.screen)) {
return state_errmsg_(self, "Could not init GUI screen.\n");
}
self->ui.main_page = zori_new_page(-1, self->ui.screen);
LOG_NOTE("Main page: %d\n", self->ui.main_page);
box = rebox_make(280, 80, 140, 240);
self->ui.main_menu = zori_new_menu(-1, main_page, &box);
LOG_NOTE("Main menu: %d\n", self->ui.main_menu);
{
Rebox box = rebox_make(300, 100, 100, 60);
self->ui.continue_button = zori_new_button(-1, main_menu, &box, "Continue");
LOG_NOTE("Button: %d\n", self->ui.continue_button);
}
{
Rebox box = rebox_make(300, 200, 100, 60);
self->ui.new_button = zori_new_button(-1, main_menu, &box, "New");
LOG_NOTE("Button: %d\n", self->ui.new_button);
}
}
INTRO_TEXT2 =
def make_sub_menu(parent, x, y, w, h, bh)
sub_menu = parent.make_menu(x, y, w, h, nil)
sub_menu.make_button(x, y + 20, w - 20, bh, "Sub choice 1") do
puts "choice 1"
end
sub_menu.make_button(x, y + 30 + bh, w - 20, bh, "Sub choice 2") do
puts "choice 2"
end
sub_menu.make_button(x, y + 40 + 2* bh, w - 20, bh, "Sub choice 3") do
puts "choice 3"
end
sub_menu.fit_children
sub_menu.hide
return sub_menu
end
def do_main_menu
main_music = Music.load(:main, '/music/nethis-the_writer.ogg')
$lote = nil
$lobe = nil
if PLAY_MUSIC
res = main_music.play!
end
# res = nil
# $main_menu = MainMenu.new
# $main_menu.active = true
Zori.make_page(:default) do |m|
State.talk_box = m.make_longtext(10, 310, 620, 160, "Testing 1 2 3")
State.talk_box.graph.each { |g| g.font = Eruta::Zori.font.id }
State.talk_box.delay = 0.1
State.talk_box.page_lines = 5
State.talk_box.page = 0
State.talk_box.hide
end
Zori.make_page(:main_menu) do |m|
if MAIN_BACKGROUND
main_back = Bitmap.load(:main_back,
'/image/background/eruta_mainmenu.png')
p main_back, main_back.width, main_back.height, main_back.name, main_back.id
main_back = Bitmap.load(:main_back,
'/image/background/eruta_mainmenu.png')
p main_back, main_back.width, main_back.height, main_back.name, main_back.id
p Bitmap[:main_back]
p Store[:bitmap_main_back]
m.graph_image(0, 0, main_back.id)
end
main_menu = m.make_menu(250, 190, 120, 440, nil)
ma = main_menu
main_button_1 = ma.make_button(260, 200, 100, 30, "Continue")
sub_menu = make_sub_menu(main_button_1, 50, 190, 120, 440, 30)
sub_menu.hide
main_button_2 = ma.make_button(260, 240, 100, 30, "New") do
do_start_test_map
Zori.go(:default)
end
main_button_3 = ma.make_button(260, 280, 100, 30, "Settings") do
Zori.go(:settings)
end
main_button_4 = ma.make_button(260, 320, 100, 30, "Instructions")
main_button_5 = ma.make_button(260, 360, 100, 30, "µ£éè")
main_button_5 << sub_menu
main_button_5= ma.make_button(260, 400, 100, 30, "Quit") do
Eruta.quit
end
main_menu.fit_children
end
Zori.make_page(:settings) do |se|
lote2 = se.make_longtext(100, 10, 160, 100, INTRO_TEXT)
lote2.delay = 1
lote2.page = 0
lote2.page_lines = 3
# $lote2.line_stop = 999990
settings_menu = se.make_menu(480, 380, 120, 440, nil)
sm = settings_menu
settings_ok_button = sm.make_button(500, 300, 100, 30, "Font 1") do
if lote2
lote2.graph.each { |g| g.font = 0 }
end
end
settings_ok_button = sm.make_button(500, 350, 100, 30, "Font 2") do
if lote2
lote2.graph.each { |g| g.font = Eruta::Zori.font.id }
end
lote2.text = INTRO_TEXT2
end
settings_ok_button = sm.make_button(500, 400, 100, 30, "OK") do
Zori.go(:main_menu)
if lote
lote.close
lote = nil
end
end
sm.fit_children
end
Zori[:main_menu].hide
Zori[:settings].hide
Zori.go(:main_menu)
end
#endif
......@@ -309,7 +309,8 @@ zori_id zori_start(struct zori_style * default_style) {
the_default_style->text.font = al_create_builtin_font();
the_default_style->text.color = al_color_name("white");
the_default_style->text.color = al_color_name("white");
the_default_style->text.font_flags= ALLEGRO_ALIGN_LEFT;
the_default_style->border.color = al_color_name("white");
the_default_style->back.color = al_color_name("green");
the_default_style->fore.color = al_color_name("white");
......@@ -421,6 +422,19 @@ zori_id zori_set_padding(zori_id id, int size) {
}
zori_font * zori_widget_text_font(struct zori_widget * widget) {
if ((!widget)) {
return the_default_style->text.font;
}
return widget->style.text.font;
}
zori_font * zori_text_font(zori_id id) {
struct zori_widget * widget = zori_get_widget(id);
return zori_widget_text_font(widget);
}
struct zori_widget * zori_widget_init
( struct zori_widget * widget,
......
......@@ -61,13 +61,16 @@ int zori_screen_on_overdraw(union zori_event * event) {
return ZORI_HANDLE_PASS;
}
/* Handlers must beset up for many events on screen to funnel them all into
* the active page. */
struct zori_handler zori_screen_handlers[] = {
{ ZORI_SYSTEM_EVENT_KEY_DOWN , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_KEY_UP , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_KEY_CHAR , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_MOUSE_AXES, zori_screen_on_mouse_axes , NULL },
{ ZORI_EVENT_OVERDRAW , zori_screen_on_overdraw , NULL },
{ ZORI_SYSTEM_EVENT_KEY_DOWN , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_KEY_UP , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_KEY_CHAR , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_MOUSE_BUTTON_DOWN , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_MOUSE_BUTTON_UP , zori_screen_on_sysevent , NULL },
{ ZORI_SYSTEM_EVENT_MOUSE_AXES , zori_screen_on_mouse_axes , NULL },
{ ZORI_EVENT_OVERDRAW , zori_screen_on_overdraw , NULL },
{ -1, NULL, NULL }
};
......
......@@ -4,23 +4,12 @@
#include "si_test.h"
#include "eruta.h"
#include "image.h"
#include "zori/zori.h"
#include "ui.h"
#include <stdarg.h>
int test_va(int last, ...) {
int res = 0; double d = 0.0; char * str = NULL;
va_list args;
va_start(args, last);
va_list_scan(args, "ifs", &res, &d, &str);
va_end(args);
printf("%d %f %s\n", res, d, str);
return res;
}
TEST_FUNC(ui) {
TEST_INTEQ(1375, test_va(0, 1375, 12.34, "Aha!"));
TEST_DONE();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment