void gg_label_init(gg_label_t *label, char *text) { gg_align_init((gg_align_t *)label); label->render = gg_label_render; label->destroy = gg_label_destroy; label->id = gg_label_get_class_id(); label->label = strdup(text); label->bouncy = 0; label->enabled = 1; label->colour = col_text; label->bgcolour = col_trans; gg_system_get_string_size(text, &label->width, &label->height); label->height += GG_BOUNCE_AMP; }
void gg_system_draw_string(char *s, int x, int y, gg_colour_t *colour, int bounce, int effect, float align) { int i; unsigned int ticks = gg_system_get_ticks(); gg_rect_t rect_d; rect_d.x = x; if (align != 0.0f) { int width; gg_system_get_string_size(s, &width, NULL); rect_d.x -= width * align; } for (i = 0; i < strlen((char *) s); i++) { int y_off = 0; void *image = driver->get_char_image(s[i]); gg_rect_t rect_s = {0, 0}; if (bounce) { float phase = ((ticks % (1000 / GG_BOUNCE_SPEED)) / (float) (1000 / GG_BOUNCE_SPEED)); if (phase < 0.5) y_off = phase * 2 * (GG_BOUNCE_AMP + 1); else y_off = ((1.0 - phase) * 2) * (GG_BOUNCE_AMP + 1); } gg_system_get_image_size(image, &rect_s.width, &rect_s.height); //printf( "Char i:%c=%i,%i\n", s[i], rect_s.width, rect_s.height ); rect_d.width = rect_s.width; rect_d.height = rect_s.height; rect_d.y = y + y_off; gg_system_draw_image(image, rect_s, rect_d, GG_MODE_SCALE, GG_MODE_SCALE, colour, effect); rect_d.x += rect_s.width+1.0f; ticks += 1000 / GG_BOUNCE_SPEED / GG_BOUNCE_LEN; } }
void gg_dialog_set_style(gg_dialog_t *dialog, gg_dialog_style_t *style) { int size; gg_widget_t *child = gg_bin_get_child(GG_BIN(dialog)); dialog->style = *style; dialog->width = child->width_a + 2 * dialog->style.hor_pad; dialog->height = child->height_a + 2 * dialog->style.vert_pad; if (style->textured) { gg_system_get_image_size(style->border.image[0], &size, NULL); dialog->width += 2 * size; dialog->height += 2 * size; } if (dialog->title) { int text_height; gg_system_get_string_size(dialog->title, NULL, &text_height); dialog->height += text_height * GG_DIALOG_TITLE_FACT; dialog->height += GG_DIALOG_TITLE_SEP_HEIGHT; } }
int gg_dialog_input(gg_widget_t *widget, gg_event_t event) { gg_dialog_t *dialog = GG_DIALOG(widget); gg_widget_t *child = gg_bin_get_child(GG_BIN(widget)); int x, y; if (dialog->flags & GG_DIALOG_HIDDEN) return 0; if (!dialog->modal && event.type == GG_EVENT_KEY && event.key == GG_KEY_ESCAPE ) gg_dialog_close(); if (!dialog->modal && event.type == GG_EVENT_MOUSE && event.mouse.type == GG_MOUSE_BUTTON_DOWN && event.mouse.button == 2 ) gg_dialog_close(); gg_dialog_get_screen_pos(dialog, &x, &y); if (event.type == GG_EVENT_MOUSE) { int size = 0; event.mouse.x -= x; event.mouse.y -= y; if (dialog->style.textured) gg_system_get_image_size(dialog->style.border.image[0], &size, NULL); if (event.mouse.type == GG_MOUSE_BUTTON_DOWN && event.mouse.button == 0) { if (dialog->title) { int text_height; int titlebar_height; gg_system_get_string_size(dialog->title, NULL, &text_height); titlebar_height = text_height * GG_DIALOG_TITLE_FACT; dialog->dialog_state |= GG_DIALOG_LEFT_BUTTON; /* Mouse click outside of dialog */ if (event.mouse.y >= dialog->height || event.mouse.y < 0 || event.mouse.x >= dialog->width || event.mouse.x < 0) return 0; gg_dialog_set_active(dialog); /* Title bar click */ if (event.mouse.y >= dialog->height - size - titlebar_height && event.mouse.y < dialog->height - size && event.mouse.x >= size && event.mouse.x < dialog->width - size) { dialog->dialog_state |= GG_DIALOG_MOVING; dialog->movement_org_x = event.mouse.x; dialog->movement_org_y = event.mouse.y; return 1; } } } else if (event.mouse.type == GG_MOUSE_BUTTON_UP && event.mouse.button == 0) { if (dialog->title) { dialog->dialog_state &= ~GG_DIALOG_LEFT_BUTTON; if (dialog->dialog_state & GG_DIALOG_MOVING) { dialog->dialog_state &= ~GG_DIALOG_MOVING; return 1; } } } if ((event.mouse.type == GG_MOUSE_MOVE) && (dialog->dialog_state & GG_DIALOG_MOVING)) { int xoff = dialog->width * dialog->pos.x_align; int yoff = dialog->height * dialog->pos.y_align; gg_dialog_set_position(dialog, x + event.mouse.x - dialog->movement_org_x + xoff, y + event.mouse.y - dialog->movement_org_y + yoff, dialog->pos.x_align, dialog->pos.y_align); } event.mouse.x -= size + dialog->style.hor_pad; event.mouse.y -= size + dialog->style.vert_pad; if (!(event.mouse.type == GG_MOUSE_MOVE && dialog->dialog_state & GG_DIALOG_LEFT_BUTTON)) { gg_widget_t *child = gg_bin_get_child(GG_BIN(dialog)); if (event.mouse.x >= 0 && event.mouse.x < child->width_a && event.mouse.y >= 0 && event.mouse.y < child->height_a) dialog->set_focus_pos(GG_WIDGET(dialog), event.mouse.x, event.mouse.y); } } if (child->input) return child->input(child, event); return 0; }
void draw_border(void *image[9], char *title, int active, gg_rect_t area, int size) { gg_rect_t source, dest; int image_size; int titlebar_height = 0; gg_system_get_image_size(image[0], &image_size, NULL); source.x = 0; source.y = 0; source.width = image_size; source.height = image_size; if (title) { int text_height; gg_system_get_string_size(title, NULL, &text_height); titlebar_height = text_height * GG_DIALOG_TITLE_FACT; titlebar_height += GG_DIALOG_TITLE_SEP_HEIGHT; dest.x = area.x; dest.y = area.y + area.height - titlebar_height; dest.width = area.width; dest.height = GG_DIALOG_TITLE_SEP_HEIGHT; gg_system_draw_filled_rect(dest.x, dest.y, dest.width, GG_DIALOG_TITLE_SEP_HEIGHT, &col_black); dest.y += GG_DIALOG_TITLE_SEP_HEIGHT; dest.height = titlebar_height - GG_DIALOG_TITLE_SEP_HEIGHT; if (active ) gg_system_draw_gradient_rect(dest.x, dest.y, dest.width, dest.height, &col_blue2, &col_blue, &col_blue2, &col_blue); else gg_system_draw_gradient_rect(dest.x, dest.y, dest.width, dest.height, &col_grey2, &col_grey, &col_grey2, &col_grey); gg_clipping_adjust(&dest); dest.y += text_height * (GG_DIALOG_TITLE_FACT - 1) / 2; gg_system_draw_string(title, dest.x + dest.width / 2, dest.y, &col_white, 0, 0.5); gg_clipping_undo(); } area.x -= size; area.y -= size; area.width += 2 * size; area.height += 2 * size; dest.x = area.x; dest.y = area.y; dest.width = size; dest.height = size; /* Draw four corners.. */ gg_system_draw_image(image[6], source, dest, GG_MODE_SCALE, GG_MODE_SCALE, &col_white); dest.y += area.height - size; gg_system_draw_image(image[0], source, dest, GG_MODE_SCALE, GG_MODE_SCALE, &col_white); dest.x += area.width - size; gg_system_draw_image(image[2], source, dest, GG_MODE_SCALE, GG_MODE_SCALE, &col_white); dest.y -= area.height - size; gg_system_draw_image(image[8], source, dest, GG_MODE_SCALE, GG_MODE_SCALE, &col_white); /* Draw bottom */ dest.x = area.x + size; dest.y = area.y; dest.width = area.width - (2 * size); dest.height = size; gg_system_draw_image(image[7], source, dest, GG_MODE_TILE, GG_MODE_SCALE, &col_white); /* Draw top */ dest.y += area.height - size; gg_system_draw_image(image[1], source, dest, GG_MODE_TILE, GG_MODE_SCALE, &col_white); /* Draw left */ dest.x = area.x; dest.y = area.y + size; dest.width = size; dest.height = area.height - (2 * size); gg_system_draw_image(image[3], source, dest, GG_MODE_SCALE, GG_MODE_TILE, &col_white); /* Draw right */ dest.x += area.width - size; gg_system_draw_image(image[5], source, dest, GG_MODE_SCALE, GG_MODE_TILE, &col_white); /* Draw middle */ dest.x = area.x + size; dest.width = area.width - 2 * size; dest.height -= titlebar_height; gg_system_draw_image(image[4], source, dest, GG_MODE_TILE, GG_MODE_TILE, &col_white); }