mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 09:04:02 +00:00
148 lines
3.8 KiB
C
148 lines
3.8 KiB
C
/* jinete - a GUI library
|
|
* Copyright (C) 2003-2005 by David A. Capello
|
|
*
|
|
* Jinete is gift-ware.
|
|
*/
|
|
|
|
#include <allegro.h>
|
|
#include <stdio.h>
|
|
|
|
#include "jinete.h"
|
|
|
|
static JWidget check, radio[12];
|
|
|
|
static int radio_flags[] = {
|
|
JI_LEFT, JI_CENTER, JI_RIGHT,
|
|
JI_TOP, JI_MIDDLE, JI_BOTTOM
|
|
};
|
|
|
|
static void update_radios (void);
|
|
static bool hooked_check_msg_proc (JWidget widget, JMessage msg);
|
|
|
|
int main (int argc, char *argv[])
|
|
{
|
|
JWidget manager, window, box1, box2, box3, label1, label2;
|
|
int c;
|
|
|
|
allegro_init ();
|
|
if (set_gfx_mode (GFX_AUTODETECT, 320, 200, 0, 0) < 0) {
|
|
allegro_message ("%s\n", allegro_error);
|
|
return 1;
|
|
}
|
|
install_timer ();
|
|
install_keyboard ();
|
|
install_mouse ();
|
|
|
|
manager = jmanager_new ();
|
|
ji_set_standard_theme ();
|
|
|
|
window = jwindow_new ("Example 10");
|
|
box1 = jbox_new (JI_HORIZONTAL);
|
|
box2 = jbox_new (JI_VERTICAL);
|
|
box3 = jbox_new (JI_VERTICAL);
|
|
label1 = jlabel_new ("Text:");
|
|
label2 = jlabel_new ("Icon:");
|
|
check = jcheck_new ("Check Button");
|
|
radio[0] = jradio_new ("Left", 1);
|
|
radio[1] = jradio_new ("Center", 1);
|
|
radio[2] = jradio_new ("Right", 1);
|
|
radio[3] = jradio_new ("Top", 2);
|
|
radio[4] = jradio_new ("Middle", 2);
|
|
radio[5] = jradio_new ("Bottom", 2);
|
|
radio[6] = jradio_new ("Left", 3);
|
|
radio[7] = jradio_new ("Center", 3);
|
|
radio[8] = jradio_new ("Right", 3);
|
|
radio[9] = jradio_new ("Top", 4);
|
|
radio[10] = jradio_new ("Middle", 4);
|
|
radio[11] = jradio_new ("Bottom", 4);
|
|
|
|
for (c=0; c<12; c++)
|
|
jwidget_add_hook (radio[c], JI_WIDGET, hooked_check_msg_proc, NULL);
|
|
|
|
jwidget_add_child (window, box1);
|
|
jwidget_add_child (box1, check);
|
|
jwidget_add_child (box1, box2);
|
|
jwidget_add_child (box1, box3);
|
|
jwidget_add_child (box2, label1);
|
|
jwidget_add_child (box2, radio[0]);
|
|
jwidget_add_child (box2, radio[1]);
|
|
jwidget_add_child (box2, radio[2]);
|
|
jwidget_add_child (box2, radio[3]);
|
|
jwidget_add_child (box2, radio[4]);
|
|
jwidget_add_child (box2, radio[5]);
|
|
jwidget_add_child (box3, label2);
|
|
jwidget_add_child (box3, radio[6]);
|
|
jwidget_add_child (box3, radio[7]);
|
|
jwidget_add_child (box3, radio[8]);
|
|
jwidget_add_child (box3, radio[9]);
|
|
jwidget_add_child (box3, radio[10]);
|
|
jwidget_add_child (box3, radio[11]);
|
|
|
|
jwidget_expansive (check, TRUE);
|
|
update_radios ();
|
|
|
|
jwindow_open_bg (window);
|
|
jmanager_run (manager);
|
|
jmanager_free (manager);
|
|
return 0;
|
|
}
|
|
|
|
END_OF_MAIN ();
|
|
|
|
static void update_radios (void)
|
|
{
|
|
#define SET_STATUS(index, status) \
|
|
if (status) \
|
|
jwidget_select (radio[index]); \
|
|
else \
|
|
jwidget_deselect (radio[index]);
|
|
|
|
int text_align = jwidget_get_align (check);
|
|
int icon_align = ji_generic_button_get_icon_align(check);
|
|
|
|
SET_STATUS (0, text_align & JI_LEFT);
|
|
SET_STATUS (1, text_align & JI_CENTER);
|
|
SET_STATUS (2, text_align & JI_RIGHT);
|
|
SET_STATUS (3, text_align & JI_TOP);
|
|
SET_STATUS (4, text_align & JI_MIDDLE);
|
|
SET_STATUS (5, text_align & JI_BOTTOM);
|
|
|
|
SET_STATUS (6, icon_align & JI_LEFT);
|
|
SET_STATUS (7, icon_align & JI_CENTER);
|
|
SET_STATUS (8, icon_align & JI_RIGHT);
|
|
SET_STATUS (9, icon_align & JI_TOP);
|
|
SET_STATUS (10, icon_align & JI_MIDDLE);
|
|
SET_STATUS (11, icon_align & JI_BOTTOM);
|
|
}
|
|
|
|
static bool hooked_check_msg_proc (JWidget widget, JMessage msg)
|
|
{
|
|
if (msg->type == JM_SIGNAL &&
|
|
msg->signal.num == JI_SIGNAL_RADIO_CHANGE) {
|
|
int text_align = 0;
|
|
int icon_align = 0;
|
|
int c;
|
|
|
|
for (c=0; c<12; c++) {
|
|
if (c < 6) {
|
|
if (jwidget_is_selected(radio[c]))
|
|
text_align |= radio_flags[c];
|
|
}
|
|
else {
|
|
if (jwidget_is_selected(radio[c]))
|
|
icon_align |= radio_flags[c-6];
|
|
}
|
|
}
|
|
|
|
if (text_align != jwidget_get_align(check))
|
|
jwidget_set_align(check, text_align);
|
|
|
|
if (icon_align != ji_generic_button_get_icon_align(check))
|
|
ji_generic_button_set_icon_align(check, icon_align);
|
|
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|