Removed the IDLE message.

Added a lot of asserts (in the GUI code mainly).
This commit is contained in:
David Capello 2008-01-03 23:22:04 +00:00
parent bbdd7a3f83
commit 8c2ebdfee4
100 changed files with 2067 additions and 1389 deletions

View File

@ -1,3 +1,41 @@
2008-01-03 David A. Capello <dacap@users.sourceforge.net>
* src/jinete/jmenu.c (menubox_msg_proc): Finally works (with keys
and without JM_IDLE message).
2008-01-02 David A. Capello <dacap@users.sourceforge.net>
* src/jinete/jmenu.c: In all these day I was working to make it
working without JM_IDLE. The keyboard is the only thing that
doesn't work right now.
* src/widgets/preview.c: Doesn't use JM_IDLE message anymore.
* src/widgets/statebar.c: Doesn't use JM_IDLE message anymore.
2007-12-26 David A. Capello <dacap@users.sourceforge.net>
* src/jinete/jmanager.c: Added 'enqueue_messages_before_this'.
* src/widgets/tabs.c (tabs_msg_proc): Fixed a problem that allow
to the user select to no-tabs at all.
* src/jinete/jmanager.c (jmanager_poll): Double-click now is
controlled through the 'ji_clock'.
(jmanager_add_msg_filter): Added routines to control filters for
the messages.
* src/jinete/jsystem.c: Removed all the stuff about double-click
in this file.
2007-12-19 David A. Capello <dacap@users.sourceforge.net>
* src/jinete/jentry.c, src/widgets/tabs.c: Modified to use timers.
* src/jinete/jmanager.c (jmanager_add_timer): Added timers and
JM_TIMER (needed to finally remove the JM_IDLE message in the
future).
2007-12-16 David A. Capello <dacap@users.sourceforge.net>
* src/commands/cmd_screen_shot.c (cmd_screen_shot_execute): Now

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005,
* 2007, 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,7 +28,7 @@
#define VERSION "0.6"
#define WEBSITE "http://www.aseprite.org/"
#define BUGREPORT "ase-help@lists.sourceforge.net"
#define COPYRIGHT "Copyright (C) 2001-2005, 2007 David A. Capello"
#define COPYRIGHT "Copyright (C) 2001-2008 David A. Capello"
#define PRINTF verbose_printf

View File

@ -1,4 +1,4 @@
<!-- Copyright (C) 2007 by David A. Capello -->
<!-- Copyright (C) 2007, 2008 by David A. Capello -->
<gui>
<!-- keyboard shortcuts -->
<keyboard>
@ -43,6 +43,11 @@
<key command="new_layer" shortcut="Shift+N" />
<!-- frame -->
<key command="new_frame" shortcut="N" />
<!-- <item command="goto_first_frame" shortcut="Up" /> -->
<!-- <item command="goto_previous_frame" name="Left" /> -->
<!-- <item command="goto_next_frame" name="Right" /> -->
<!-- <item command="goto_last_frame" name="Down" /> -->
<!-- <item command="play_animation" name="Enter" /> -->
<!-- cel -->
<key command="cel_properties" shortcut="Shift+Ctrl+P" />
<key command="new_cel" shortcut="Shift+Ctrl+N" />
@ -153,6 +158,14 @@
<separator />
<item command="new_frame" name="&New" />
<item command="remove_frame" name="&Remove" />
<!-- <separator /> -->
<!-- <menu name="&Go to"> -->
<!-- <item command="goto_first_frame" name="&First" /> -->
<!-- <item command="goto_previous_frame" name="&Previous" /> -->
<!-- <item command="goto_next_frame" name="&Next" /> -->
<!-- <item command="goto_last_frame" name="&Last" /> -->
<!-- </menu> -->
<!-- <item command="play_animation" name="&Play" /> -->
</menu>
<menu name="&Cel" id="cel_popup">
<item command="cel_properties" name="&Properties" />

View File

@ -34,7 +34,7 @@
static void cmd_screen_shot_execute(const char *argument)
{
int old_flag;
int c, old_flag;
char buf[512];
PALETTE pal;
BITMAP *bmp;

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +21,7 @@
#ifndef USE_PRECOMPILED_HEADER
#include <assert.h>
#include <allegro/debug.h>
#include <allegro/unicode.h>
@ -63,7 +65,7 @@ static void cmd_select_file_execute(const char *argument)
if (argument) {
int sprite_id = ustrtol(argument, NULL, 10);
GfxObj *gfxobj = gfxobj_find(sprite_id);
ASSERT(gfxobj != NULL);
assert(gfxobj != NULL);
sprite_show((Sprite *)gfxobj);
}

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -48,37 +49,37 @@ void console_open(void)
/* TODO verify if the ji_screen works */
/* if (!screen || */
if (!ji_screen ||
!is_interactive () ||
!is_interactive() ||
wid_console ||
console_counter > 1)
return;
else {
JWidget window, box1, view, textbox, button;
window = jwindow_new (_("Processing..."));
window = jwindow_new(_("Processing..."));
if (!window)
return;
box1 = jbox_new (JI_VERTICAL);
view = jview_new ();
textbox = jtextbox_new (NULL, JI_WORDWRAP);
button = jbutton_new (_("&Cancel"));
box1 = jbox_new(JI_VERTICAL);
view = jview_new();
textbox = jtextbox_new(NULL, JI_WORDWRAP);
button = jbutton_new(_("&Cancel"));
if (!box1 || !textbox || !button)
return;
jview_attach (view, textbox);
jview_attach(view, textbox);
jwidget_add_child (box1, view);
jwidget_add_child (box1, button);
jwidget_add_child (window, box1);
jwidget_add_child(box1, view);
jwidget_add_child(box1, button);
jwidget_add_child(window, box1);
jwidget_hide (view);
jwidget_magnetic (button, TRUE);
jwidget_expansive (view, TRUE);
jwidget_hide(view);
jwidget_magnetic(button, TRUE);
jwidget_expansive(view, TRUE);
/* force foreground mode */
/* ji_find_widget (window)->in_foreground = TRUE; */
/* ji_find_widget(window)->in_foreground = TRUE; */
wid_console = window;
wid_view = view;
@ -89,17 +90,19 @@ void console_open(void)
}
}
void console_close (void)
void console_close(void)
{
console_counter--;
if ((wid_console) && (console_counter == 0)) {
if (console_locked &&
!want_close_flag &&
jwidget_is_visible (wid_console))
jwindow_open_fg (wid_console);
if (console_locked
&& !want_close_flag
&& jwidget_is_visible(wid_console)) {
/* open in foreground */
jwindow_open_fg(wid_console);
}
jwidget_free (wid_console);
jwidget_free(wid_console);
wid_console = NULL;
want_close_flag = FALSE;
}
@ -110,18 +113,18 @@ void console_printf(const char *format, ...)
char buf[1024];
va_list ap;
va_start (ap, format);
uvsprintf (buf, format, ap);
va_end (ap);
va_start(ap, format);
uvsprintf(buf, format, ap);
va_end(ap);
if (wid_console) {
const char *text;
char *final;
/* open the window */
if (jwidget_is_hidden (wid_console)) {
jwindow_open (wid_console);
jmanager_refresh_screen ();
if (jwidget_is_hidden(wid_console)) {
jwindow_open(wid_console);
jmanager_refresh_screen();
}
/* update the textbox */
@ -136,37 +139,37 @@ void console_printf(const char *format, ...)
jwidget_dirty(wid_console);
}
text = jwidget_get_text (wid_textbox);
text = jwidget_get_text(wid_textbox);
if (!text)
final = jstrdup (buf);
final = jstrdup(buf);
else {
final = jmalloc (ustrlen (text) + ustrlen (buf) + 1);
final = jmalloc(ustrlen(text) + ustrlen(buf) + 1);
ustrcpy (final, empty_string);
ustrcat (final, text);
ustrcat (final, buf);
ustrcpy(final, empty_string);
ustrcat(final, text);
ustrcat(final, buf);
}
jwidget_set_text (wid_textbox, final);
jfree (final);
jwidget_set_text(wid_textbox, final);
jfree(final);
}
else
printf (buf);
printf(buf);
}
void user_printf (const char *format, ...)
void user_printf(const char *format, ...)
{
char buf[1024];
va_list ap;
va_start (ap, format);
uvsprintf (buf, format, ap);
va_end (ap);
va_start(ap, format);
uvsprintf(buf, format, ap);
va_end(ap);
/* if (script_is_running ()) */
/* plugin_printf (buf); */
/* if (script_is_running()) */
/* plugin_printf(buf); */
/* else */
allegro_message (buf);
allegro_message(buf);
}
void do_progress(int progress)

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -266,26 +266,26 @@ bool effect_apply_step(Effect *effect)
}
}
void effect_apply (Effect *effect)
void effect_apply(Effect *effect)
{
add_progress (effect->h);
add_progress(effect->h);
effect_begin (effect);
while (effect_apply_step (effect))
do_progress (effect->row);
effect_begin(effect);
while (effect_apply_step(effect))
do_progress(effect->row);
/* undo stuff */
if (undo_is_enabled (effect->sprite->undo))
undo_image (effect->sprite->undo, effect->src,
effect->x, effect->y, effect->w, effect->h);
if (undo_is_enabled(effect->sprite->undo))
undo_image(effect->sprite->undo, effect->src,
effect->x, effect->y, effect->w, effect->h);
/* copy "dst" to "src" */
image_copy (effect->src, effect->dst, 0, 0);
image_copy(effect->src, effect->dst, 0, 0);
del_progress ();
del_progress();
}
void effect_flush (Effect *effect)
void effect_flush(Effect *effect)
{
if (effect->row >= 0) {
JRegion reg1, reg2;
@ -299,8 +299,8 @@ void effect_flush (Effect *effect)
effect->x+effect->offset_x,
effect->y+effect->offset_y+effect->row-1,
&rect.x1, &rect.y1);
rect.x2 = rect.x1 + (effect->w << editor_data (editor)->zoom);
rect.y2 = rect.y1 + (1 << editor_data (editor)->zoom);
rect.x2 = rect.x1 + (effect->w << editor_data(editor)->zoom);
rect.y2 = rect.y1 + (1 << editor_data(editor)->zoom);
reg2 = jregion_new(&rect, 1);
jregion_union(reg1, reg1, reg2);
@ -315,20 +315,20 @@ void effect_flush (Effect *effect)
}
}
void effect_apply_to_image (Effect *effect, Image *image, int x, int y)
void effect_apply_to_image(Effect *effect, Image *image, int x, int y)
{
if (effect_init (effect, image, x, y))
effect_apply (effect);
if (effect_init(effect, image, x, y))
effect_apply(effect);
}
void effect_apply_to_target (Effect *effect)
void effect_apply_to_target(Effect *effect)
{
int target = get_config_int ("Target", "Images", 0);
int target = get_config_int("Target", "Images", 0);
int n, n2, images = 0;
Stock *stock;
int *x, *y;
stock = sprite_get_images (effect->sprite, target, TRUE, &x, &y);
stock = sprite_get_images(effect->sprite, target, TRUE, &x, &y);
if (!stock)
return;

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,6 +36,11 @@
#include "jinete/jaccel.h"
#include "jinete/jlist.h"
/* #define REPORT_KEYS */
#define PREPROCESS_KEYS
struct jaccel
{
JList key_list;
@ -168,46 +173,46 @@ static void proc_one_word(JAccel accel, char *word)
/* other ones */
else {
/* F1, F2, ..., F11, F12 */
if ((toupper (*tok) == 'F') && (ustrlen (tok) <= 3)) {
int num = ustrtol (tok+1, NULL, 10);
if ((toupper (*tok) == 'F') && (ustrlen(tok) <= 3)) {
int num = ustrtol(tok+1, NULL, 10);
if ((num >= 1) && (num <= 12))
scancode = KEY_F1 + num - 1;
}
else if (ustricmp (tok, "Esc") == 0)
else if (ustricmp(tok, "Esc") == 0)
scancode = KEY_ESC;
else if (ustricmp (tok, "Backspace") == 0)
else if (ustricmp(tok, "Backspace") == 0)
scancode = KEY_BACKSPACE;
else if (ustricmp (tok, "Tab") == 0)
else if (ustricmp(tok, "Tab") == 0)
scancode = KEY_TAB;
else if (ustricmp (tok, "Enter") == 0)
else if (ustricmp(tok, "Enter") == 0)
scancode = KEY_ENTER;
else if (ustricmp (tok, "Space") == 0)
else if (ustricmp(tok, "Space") == 0)
scancode = KEY_SPACE;
else if ((ustricmp (tok, "Insert") == 0) ||
(ustricmp (tok, "Ins") == 0))
else if ((ustricmp(tok, "Insert") == 0) ||
(ustricmp(tok, "Ins") == 0))
scancode = KEY_INSERT;
else if ((ustricmp (tok, "Delete") == 0) ||
(ustricmp (tok, "Del") == 0))
else if ((ustricmp(tok, "Delete") == 0) ||
(ustricmp(tok, "Del") == 0))
scancode = KEY_DEL;
else if (ustricmp (tok, "Home") == 0)
else if (ustricmp(tok, "Home") == 0)
scancode = KEY_HOME;
else if (ustricmp (tok, "End") == 0)
else if (ustricmp(tok, "End") == 0)
scancode = KEY_END;
else if (ustricmp (tok, "PgUp") == 0)
else if (ustricmp(tok, "PgUp") == 0)
scancode = KEY_PGUP;
else if (ustricmp (tok, "PgDn") == 0)
else if (ustricmp(tok, "PgDn") == 0)
scancode = KEY_PGDN;
else if (ustricmp (tok, "Left") == 0)
else if (ustricmp(tok, "Left") == 0)
scancode = KEY_LEFT;
else if (ustricmp (tok, "Right") == 0)
else if (ustricmp(tok, "Right") == 0)
scancode = KEY_RIGHT;
else if (ustricmp (tok, "Up") == 0)
else if (ustricmp(tok, "Up") == 0)
scancode = KEY_UP;
else if (ustricmp (tok, "Down") == 0)
else if (ustricmp(tok, "Down") == 0)
scancode = KEY_DOWN;
/* TODO all "Pad" stuff and "PrtScr" and "Pause" */
else if (ustricmp (tok, "Enter Pad") == 0)
else if (ustricmp(tok, "Enter Pad") == 0)
scancode = KEY_ENTER_PAD;
}
}
@ -385,9 +390,6 @@ void jaccel_to_string(JAccel accel, char *buf)
bool jaccel_check(JAccel accel, int shifts, int ascii, int scancode)
{
/* #define REPORT_KEYS */
#define PREPROCESS_KEYS
KeyCombo *key;
JLink link;
#ifdef REPORT_KEYS

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -156,13 +156,15 @@ enum {
JM_CLOSE, /* windows is closed */
JM_DESTROY, /* widget is destroyed */
JM_DRAW, /* widget needs be repainted */
JM_IDLE, /* is sent when the manager does nothing */
JM_SIGNAL, /* signal from some widget */
JM_TIMER, /* a timer timeout */
JM_REQSIZE, /* request size */
JM_SETPOS, /* set position */
JM_WINMOVE, /* window movement */
JM_DRAWRGN, /* redraw region */
JM_DIRTYCHILDREN, /* dirty children */
JM_QUEUEPROCESSING, /* only sent to manager which indicate
the last message in the queue */
/* keyboard related messages */
JM_CHAR, /* a new character in the buffer */
@ -182,6 +184,9 @@ enum {
/* XXX drag'n'drop operation? */
/* JM_DND_, */
/* other messages */
JM_REGISTERED_MESSAGES
};
/* signals */

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,6 +31,7 @@
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include <winalleg.h>
#include <stdarg.h>
#include <stdio.h>
@ -50,7 +51,7 @@ typedef struct Entry
int cursor;
int scroll;
int select;
int clock;
int timer_id;
bool hidden : 1;
bool state : 1; /* show or not the text cursor */
bool readonly : 1;
@ -58,38 +59,38 @@ typedef struct Entry
bool recent_focused : 1;
} Entry;
static bool entry_msg_proc (JWidget widget, JMessage msg);
static void entry_request_size (JWidget widget, int *w, int *h);
static bool entry_msg_proc(JWidget widget, JMessage msg);
static void entry_request_size(JWidget widget, int *w, int *h);
static int entry_get_cursor_from_mouse (JWidget widget, JMessage msg);
static int entry_get_cursor_from_mouse(JWidget widget, JMessage msg);
static void entry_forward_word (JWidget widget);
static void entry_backward_word (JWidget widget);
static void entry_forward_word(JWidget widget);
static void entry_backward_word(JWidget widget);
JWidget jentry_new (int maxsize, const char *format, ...)
JWidget jentry_new(int maxsize, const char *format, ...)
{
JWidget widget = jwidget_new (JI_ENTRY);
Entry *entry = jnew (Entry, 1);
JWidget widget = jwidget_new(JI_ENTRY);
Entry *entry = jnew(Entry, 1);
char buf[4096];
/* formatted string */
if (format) {
va_list ap;
va_start (ap, format);
vsprintf (buf, format, ap);
va_end (ap);
va_start(ap, format);
vsprintf(buf, format, ap);
va_end(ap);
}
/* empty string */
else {
ustrcpy (buf, empty_string);
ustrcpy(buf, empty_string);
}
jwidget_add_hook (widget, JI_ENTRY, entry_msg_proc, entry);
jwidget_add_hook(widget, JI_ENTRY, entry_msg_proc, entry);
entry->cursor = 0;
entry->scroll = 0;
entry->select = 0;
entry->clock = 0;
entry->timer_id = jmanager_add_timer(widget, 500);
entry->hidden = FALSE;
entry->state = FALSE;
entry->password = FALSE;
@ -99,64 +100,64 @@ JWidget jentry_new (int maxsize, const char *format, ...)
/* TODO support for text alignment and multi-line */
/* widget->align = JI_LEFT | JI_MIDDLE; */
widget->text_size = maxsize+1;
widget->text = jmalloc (widget->text_size);
jwidget_set_text (widget, buf);
widget->text = jmalloc(widget->text_size);
jwidget_set_text(widget, buf);
jwidget_focusrest (widget, TRUE);
jwidget_init_theme (widget);
jwidget_focusrest(widget, TRUE);
jwidget_init_theme(widget);
return widget;
}
void jentry_readonly (JWidget widget, bool state)
void jentry_readonly(JWidget widget, bool state)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
entry->readonly = state;
}
void jentry_password (JWidget widget, bool state)
void jentry_password(JWidget widget, bool state)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
entry->password = state;
}
bool jentry_is_readonly (JWidget widget)
bool jentry_is_readonly(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
return entry->readonly;
}
bool jentry_is_password (JWidget widget)
bool jentry_is_password(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
return entry->password;
}
void jentry_show_cursor (JWidget widget)
void jentry_show_cursor(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
entry->hidden = FALSE;
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jentry_hide_cursor (JWidget widget)
void jentry_hide_cursor(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
entry->hidden = TRUE;
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jentry_set_cursor_pos (JWidget widget, int pos)
void jentry_set_cursor_pos(JWidget widget, int pos)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
const char *text = widget->text;
int x, c;
@ -171,46 +172,46 @@ void jentry_set_cursor_pos (JWidget widget, int pos)
do {
x = widget->rc->x1 + widget->border_width.l;
for (c=++entry->scroll; ; c++) {
x += CHARACTER_LENGTH (widget->text_font,
(c < ustrlen (text))? ugetat (text, c): ' ');
x += CHARACTER_LENGTH(widget->text_font,
(c < ustrlen(text))? ugetat(text, c): ' ');
if (x >= widget->rc->x2-widget->border_width.r)
break;
}
} while (entry->cursor >= c);
entry->clock = ji_clock;
jmanager_start_timer(entry->timer_id);
entry->state = TRUE;
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jentry_select_text (JWidget widget, int from, int to)
void jentry_select_text(JWidget widget, int from, int to)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
int end = ustrlen (widget->text);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
int end = ustrlen(widget->text);
entry->select = from;
jentry_set_cursor_pos (widget, from);
jentry_set_cursor_pos (widget, (to >= 0)? to: end+to+1);
jentry_set_cursor_pos(widget, from);
jentry_set_cursor_pos(widget, (to >= 0)? to: end+to+1);
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jentry_deselect_text (JWidget widget)
void jentry_deselect_text(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
entry->select = -1;
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jtheme_entry_info (JWidget widget,
int *scroll, int *cursor, int *state,
int *selbeg, int *selend)
void jtheme_entry_info(JWidget widget,
int *scroll, int *cursor, int *state,
int *selbeg, int *selend)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
if (scroll) *scroll = entry->scroll;
if (cursor) *cursor = entry->cursor;
@ -218,8 +219,8 @@ void jtheme_entry_info (JWidget widget,
if ((entry->select >= 0) &&
(entry->cursor != entry->select)) {
*selbeg = MIN (entry->cursor, entry->select);
*selend = MAX (entry->cursor, entry->select)-1;
*selbeg = MIN(entry->cursor, entry->select);
*selend = MAX(entry->cursor, entry->select)-1;
}
else {
*selbeg = -1;
@ -227,32 +228,32 @@ void jtheme_entry_info (JWidget widget,
}
}
static bool entry_msg_proc (JWidget widget, JMessage msg)
static bool entry_msg_proc(JWidget widget, JMessage msg)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
switch (msg->type) {
case JM_DESTROY:
jfree (entry);
jmanager_remove_timer(entry->timer_id);
jfree(entry);
break;
case JM_REQSIZE:
entry_request_size (widget, &msg->reqsize.w, &msg->reqsize.h);
return TRUE;
case JM_IDLE:
if (jwidget_has_focus (widget)) {
if (ji_clock-entry->clock > JI_TICKS_PER_SEC/2) {
entry->clock = ji_clock;
entry->state = entry->state ? FALSE: TRUE;
jwidget_dirty (widget);
}
case JM_TIMER:
if (jwidget_has_focus(widget) &&
msg->timer.timer_id == entry->timer_id) {
entry->state = entry->state ? FALSE: TRUE;
jwidget_dirty(widget);
}
break;
case JM_FOCUSENTER:
entry->clock = ji_clock;
jmanager_start_timer(entry->timer_id);
entry->state = TRUE;
jwidget_dirty(widget);
@ -263,6 +264,8 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
case JM_FOCUSLEAVE:
jwidget_dirty(widget);
jmanager_stop_timer(entry->timer_id);
jentry_deselect_text(widget);
entry->recent_focused = FALSE;
break;
@ -380,12 +383,12 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
/* paste text */
for (c=0; c<ustrlen (clipboard); c++)
if (ustrsizez (text) < widget->text_size)
uinsert (text, entry->cursor+c, ugetat (clipboard, c));
if (ustrsizez(text) < widget->text_size)
uinsert(text, entry->cursor+c, ugetat(clipboard, c));
else
break;
jentry_set_cursor_pos (widget, entry->cursor+c);
jentry_set_cursor_pos(widget, entry->cursor+c);
}
}
/* *copy* text */
@ -393,8 +396,8 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
char buf[1024];
ustrcpy (buf, empty_string);
for (c=selbeg; c<=selend; c++)
uinsert (buf, ustrlen (buf), ugetat (text, c));
jclipboard_set_text (buf);
uinsert(buf, ustrlen(buf), ugetat (text, c));
jclipboard_set_text(buf);
}
break;
@ -402,14 +405,14 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
/* delete the entire selection */
if (selbeg >= 0) {
for (c=0; c<selend-selbeg+1; c++)
uremove (text, selbeg);
uremove(text, selbeg);
entry->cursor = selbeg;
}
/* delete the previous character */
else {
if (entry->cursor > 0)
uremove (text, --entry->cursor);
uremove(text, --entry->cursor);
}
entry->select = -1;
@ -420,20 +423,20 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
/* delete the entire selection */
if (selbeg >= 0) {
for (c=0; c<selend-selbeg+1; c++)
uremove (text, selbeg);
uremove(text, selbeg);
entry->cursor = selbeg;
}
/* put the character */
if (ustrsizez (text) < widget->text_size)
uinsert (text, entry->cursor++, msg->key.ascii);
if (ustrsizez(text) < widget->text_size)
uinsert(text, entry->cursor++, msg->key.ascii);
entry->select = -1;
break;
}
else {
jfree (text);
jfree(text);
return FALSE;
}
}
@ -455,7 +458,7 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
jwidget_capture_mouse(widget);
case JM_MOTION:
if (jwidget_has_capture (widget)) {
if (jwidget_has_capture(widget)) {
const char *text = widget->text;
bool move, dirty;
int c, x;
@ -515,7 +518,7 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
/* show the cursor */
if (dirty) {
entry->clock = ji_clock;
jmanager_start_timer(entry->timer_id);
entry->state = TRUE;
}
@ -524,8 +527,8 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
break;
case JM_BUTTONRELEASED:
if (jwidget_has_capture (widget))
jwidget_release_mouse (widget);
if (jwidget_has_capture(widget))
jwidget_release_mouse(widget);
return TRUE;
case JM_DOUBLECLICK:
@ -546,34 +549,34 @@ static bool entry_msg_proc (JWidget widget, JMessage msg)
return FALSE;
}
static void entry_request_size (JWidget widget, int *w, int *h)
static void entry_request_size(JWidget widget, int *w, int *h)
{
*w =
+ widget->border_width.l
+ ji_font_char_len (widget->text_font, 'w') * MIN (widget->text_size, 6)
+ ji_font_char_len(widget->text_font, 'w') * MIN(widget->text_size, 6)
+ 2 + widget->border_width.r;
*w = MIN (*w, 128);
*w = MIN(*w, 128);
*h =
+ widget->border_width.t
+ text_height (widget->text_font)
+ text_height(widget->text_font)
+ widget->border_width.b;
}
static int entry_get_cursor_from_mouse (JWidget widget, JMessage msg)
static int entry_get_cursor_from_mouse(JWidget widget, JMessage msg)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
int c, x, w, mx, cursor = entry->cursor;
mx = msg->mouse.x;
mx = MID (widget->rc->x1+widget->border_width.l,
mx,
widget->rc->x2-widget->border_width.r-1);
mx = MID(widget->rc->x1+widget->border_width.l,
mx,
widget->rc->x2-widget->border_width.r-1);
x = widget->rc->x1 + widget->border_width.l;
for (c=entry->scroll; ugetat (widget->text, c); c++) {
w = CHARACTER_LENGTH (widget->text_font, ugetat (widget->text, c));
w = CHARACTER_LENGTH(widget->text_font, ugetat (widget->text, c));
if (x+w >= widget->rc->x2-widget->border_width.r)
break;
if ((mx >= x) && (mx < x+w)) {
@ -592,43 +595,43 @@ static int entry_get_cursor_from_mouse (JWidget widget, JMessage msg)
}
#define IS_WORD_CHAR(ch) \
(!((!ch) || (uisspace (ch)) || \
(!((!ch) || (uisspace(ch)) || \
((ch) == '/') || ((ch) == OTHER_PATH_SEPARATOR)))
static void entry_forward_word (JWidget widget)
static void entry_forward_word(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
int ch;
for (; entry->cursor<ustrlen (widget->text); entry->cursor++) {
ch = ugetat (widget->text, entry->cursor);
ch = ugetat(widget->text, entry->cursor);
if (IS_WORD_CHAR (ch))
break;
}
for (; entry->cursor<ustrlen (widget->text); entry->cursor++) {
ch = ugetat (widget->text, entry->cursor);
if (!IS_WORD_CHAR (ch)) {
for (; entry->cursor<ustrlen(widget->text); entry->cursor++) {
ch = ugetat(widget->text, entry->cursor);
if (!IS_WORD_CHAR(ch)) {
entry->cursor++;
break;
}
}
}
static void entry_backward_word (JWidget widget)
static void entry_backward_word(JWidget widget)
{
Entry *entry = jwidget_get_data (widget, JI_ENTRY);
Entry *entry = jwidget_get_data(widget, JI_ENTRY);
int ch;
for (entry->cursor--; entry->cursor >= 0; entry->cursor--) {
ch = ugetat (widget->text, entry->cursor);
if (IS_WORD_CHAR (ch))
ch = ugetat(widget->text, entry->cursor);
if (IS_WORD_CHAR(ch))
break;
}
for (; entry->cursor >= 0; entry->cursor--) {
ch = ugetat (widget->text, entry->cursor);
if (!IS_WORD_CHAR (ch)) {
ch = ugetat(widget->text, entry->cursor);
if (!IS_WORD_CHAR(ch)) {
entry->cursor++;
break;
}

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,20 +37,20 @@
static JID nwidgets = 0;
static JWidget *widgets = NULL;
JWidget _ji_get_widget_by_id (JID widget_id)
JWidget _ji_get_widget_by_id(JID widget_id)
{
/* ji_assert ((widget_id >= 0) && (widget_id < nwidgets)); */
return widgets[widget_id];
}
JWidget *_ji_get_widget_array (int *n)
JWidget *_ji_get_widget_array(int *n)
{
*n = nwidgets;
return widgets;
}
JWidget _ji_get_new_widget (void)
JWidget _ji_get_new_widget(void)
{
JID widget_id;
@ -90,12 +90,12 @@ JWidget _ji_get_new_widget (void)
return widgets[widget_id];
}
void _ji_free_widget (JWidget widget)
void _ji_free_widget(JWidget widget)
{
widgets[widget->id]->id = 0;
}
void _ji_free_all_widgets (void)
void _ji_free_all_widgets(void)
{
int c;
@ -109,7 +109,7 @@ void _ji_free_all_widgets (void)
}
}
bool _ji_is_valid_widget (JWidget widget)
bool _ji_is_valid_widget(JWidget widget)
{
return (widget &&
widget->id >= 0 &&

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@
#include <stdio.h>
#endif
#include <assert.h>
#include <allegro.h>
#include "jinete/jinete.h"
@ -49,6 +50,14 @@
JI_HIDDEN | \
JI_DECORATIVE)) == JI_FOCUSREST)
#define DOUBLE_CLICK_TIMEOUT_MSECS 400
enum {
DOUBLE_CLICK_NONE,
DOUBLE_CLICK_DOWN,
DOUBLE_CLICK_UP
};
enum {
STAGE_NORMAL,
STAGE_WANT_CLOSE,
@ -56,16 +65,37 @@ enum {
STAGE_CLOSE_ALL,
};
typedef struct Timer {
JWidget widget;
int interval;
int last_time;
} Timer;
#define NFILTERS (JM_REGISTERED_MESSAGES+1)
typedef struct Filter {
int message;
JWidget widget;
} Filter;
static int double_click_level;
static int double_click_buttons;
static int double_click_ticks;
static int want_close_stage; /* variable to handle the external
close button in some Windows
enviroments */
static JWidget default_manager = NULL;
static Timer **timers; /* registered timers */
static int n_timers; /* number of timers */
static JList new_windows; /* windows that we should show */
static JList old_windows; /* windows that we should destroy */
static JList proc_windows_list; /* current window's list in process */
static JList msg_queue; /* messages queue */
static JList msg_filters[NFILTERS]; /* filters for every enqueued message */
static JWidget focus_widget; /* the widget with the focus */
static JWidget mouse_widget; /* the widget with the mouse */
@ -77,12 +107,17 @@ static bool first_time_poll; /* TRUE when we don't enter in poll yet */
static char old_readed_key[KEY_MAX]; /* keyboard status of previous
poll */
/* all messages are enqueue before this 'link' (or in the end of the
queue if it's NULL) */
static JLink enqueue_messages_before_this = NULL;
/* manager widget */
static bool manager_msg_proc(JWidget widget, JMessage msg);
static void manager_request_size(JWidget widget, int *w, int *h);
static void manager_set_position(JWidget widget, JRect rect);
static void manager_redraw_region(JWidget widget, JRegion region);
static void dispatch_msgs(void);
/* auxiliary */
static void destroy_window(JWidget window);
static void remove_msgs_for(JWidget widget, JMessage msg);
static void generate_proc_windows_list(void);
@ -92,6 +127,9 @@ static JWidget find_magnetic_widget(JWidget widget);
static JMessage new_mouse_msg(int type);
static JMessage new_key_msg(int type, int readkey_value);
static void broadcast_key_msg(JWidget manager, JMessage msg);
static Filter *filter_new(int message, JWidget widget);
static void filter_free(Filter *filter);
/* keyboard focus movement stuff */
static bool move_focus(JWidget manager, JMessage msg);
static int count_widgets_accept_focus(JWidget widget);
@ -135,16 +173,25 @@ JWidget jmanager_new(void)
old_windows = jlist_new();
proc_windows_list = jlist_new();
for (c=0; c<NFILTERS; ++c)
msg_filters[c] = jlist_new();
/* reset variables */
focus_widget = NULL;
mouse_widget = NULL;
capture_widget = NULL;
first_time_poll = TRUE;
double_click_level = DOUBLE_CLICK_NONE;
double_click_ticks = 0;
/* reset keyboard */
for (c=0; c<KEY_MAX; c++)
old_readed_key[c] = 0;
/* timers */
timers = NULL;
n_timers = 0;
}
widget = jwidget_new(JI_MANAGER);
@ -163,6 +210,11 @@ JWidget jmanager_new(void)
void jmanager_free(JWidget widget)
{
JLink link;
int c;
assert_valid_widget(widget);
/* there are some messages in queue? */
jmanager_dispatch_messages();
@ -175,6 +227,22 @@ void jmanager_free(JWidget widget)
jlist_free(new_windows);
jlist_free(old_windows);
/* destroy filters */
for (c=0; c<NFILTERS; ++c) {
JI_LIST_FOR_EACH(msg_filters[c], link) {
filter_free(link->data);
}
jlist_free(msg_filters[c]);
msg_filters[c] = NULL;
}
/* destroy timers */
for (c=0; c<n_timers; ++c)
if (timers[c])
jfree(timers[c]);
jfree(timers);
n_timers = 0;
/* finish theme */
ji_set_theme(NULL);
@ -207,7 +275,7 @@ void jmanager_run(JWidget widget)
bool jmanager_poll(JWidget manager, bool all_windows)
{
/* JList old_proc_windows_list; */
/* JList old_proc_windows_list; */
JWidget widget;
JWidget window;
bool ret = TRUE;
@ -219,19 +287,21 @@ bool jmanager_poll(JWidget manager, bool all_windows)
/* poll keyboard */
poll_keyboard();
/* TODO check for STAGE */
if (first_time_poll) {
first_time_poll = FALSE;
jmanager_refresh_screen();
jmouse_set_cursor(JI_CURSOR_NORMAL);
}
/* first check */
/* first check: there are windows to manage? */
if (jlist_empty(manager->children))
return FALSE;
/* TODO check for STAGE */
/* if (want_close_stage == STAGE_WANT_CLOSE) */
/* return FALSE; */
/* new windows to show? */
if (!jlist_empty(new_windows)) {
JI_LIST_FOR_EACH(new_windows, link) {
@ -264,47 +334,45 @@ bool jmanager_poll(JWidget manager, bool all_windows)
/* update mouse status */
mousemove = jmouse_poll();
if (mousemove || !mouse_widget) {
/* get the widget under the mouse */
widget = NULL;
/* get the widget under the mouse */
widget = NULL;
JI_LIST_FOR_EACH(proc_windows_list, link) {
window = link->data;
widget = jwidget_pick(window, jmouse_x(0), jmouse_y(0));
if (widget)
break;
}
JI_LIST_FOR_EACH(proc_windows_list, link) {
window = link->data;
widget = jwidget_pick(window, jmouse_x(0), jmouse_y(0));
if (widget)
break;
}
/* fixup "mouse" flag */
if (widget != mouse_widget) {
if (!widget)
jmanager_free_mouse();
else
jmanager_set_mouse(widget);
}
/* fixup "mouse" flag */
if (widget != mouse_widget) {
if (!widget)
jmanager_free_mouse();
else
jmanager_set_mouse(widget);
}
/* mouse movement */
if (mousemove) {
msg = new_mouse_msg(JM_MOTION);
/* mouse movement */
if (mousemove) {
msg = new_mouse_msg(JM_MOTION);
/* TODO rigid marshal */
/* reset double click status */
double_click_level = DOUBLE_CLICK_NONE;
/* reset double click status */
jmouse_set_click_level(JI_CLICK_NOT);
/* send the mouse movement message */
if (capture_widget)
jmessage_broadcast_to_parents(msg, capture_widget);
else if (mouse_widget)
jmessage_broadcast_to_parents(msg, mouse_widget);
/* send the mouse movement message */
if (capture_widget)
jmessage_broadcast_to_parents(msg, capture_widget);
else if (mouse_widget)
jmessage_broadcast_to_parents(msg, mouse_widget);
jmanager_enqueue_message(msg);
jmessage_free(msg);
jmanager_enqueue_message(msg);
}
}
/* mouse wheel */
if (jmouse_z(0) != jmouse_z(1)) {
msg = new_mouse_msg(JM_WHEEL);
/* TODO rigid marshal */
/* send the mouse wheel message */
if (capture_widget)
@ -313,23 +381,69 @@ bool jmanager_poll(JWidget manager, bool all_windows)
jmessage_broadcast_to_parents(msg, mouse_widget);
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
/* mouse clicks */
if ((jmouse_b(0) != jmouse_b(1)) &&
((!jmouse_b(0)) || (!jmouse_b(1)))) {
int current_ticks = ji_clock;
/* press and release button messages */
msg = new_mouse_msg((!jmouse_b(1))? JM_BUTTONPRESSED:
JM_BUTTONRELEASED);
/* TODO rigid marshal */
if (msg->type == JM_BUTTONPRESSED)
if (jmouse_get_click_level() == JI_CLICK_NOT)
jmouse_set_click_level(JI_CLICK_START);
/**********************************************************************/
/* Double Click */
if (msg->type == JM_BUTTONPRESSED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
}
else if (double_click_buttons == msg->mouse.flags) {
if (double_click_level == DOUBLE_CLICK_UP) {
msg->type = JM_DOUBLECLICK;
}
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
/* press other button, back to NONE */
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
/* this could be the beginning of the state */
if (double_click_level == DOUBLE_CLICK_NONE) {
double_click_level = DOUBLE_CLICK_DOWN;
double_click_buttons = msg->mouse.flags;
double_click_ticks = current_ticks;
}
}
else if (msg->type == JM_BUTTONRELEASED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
}
else if (double_click_buttons == msg->mouse.flags) {
if (double_click_level == DOUBLE_CLICK_DOWN) {
double_click_level = DOUBLE_CLICK_UP;
double_click_ticks = current_ticks;
}
}
/* press other button, back to NONE */
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
}
/* add receivers of the message */
if (capture_widget)
jmessage_broadcast_to_parents (msg, capture_widget);
jmessage_broadcast_to_parents(msg, capture_widget);
else if (mouse_widget) {
/* Z-Order:
Send the window to top (only when you click in a window
@ -366,38 +480,8 @@ bool jmanager_poll(JWidget manager, bool all_windows)
jmessage_broadcast_to_parents(msg, mouse_widget);
}
else {
jmouse_set_click_level(JI_CLICK_NOT);
/* maybe someone want catch this lost click (menus use this to
down to parents) */
msg->type = JM_IDLE;
JI_LIST_FOR_EACH(proc_windows_list, link) {
window = link->data;
jmessage_broadcast_to_children(msg, window);
}
}
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
/* double clicks */
if (jmouse_get_click_level() == JI_CLICK_AGAIN) {
msg = new_mouse_msg(JM_DOUBLECLICK);
/* TODO rigid marshal */
jmouse_set_click_level(JI_CLICK_NOT);
if (capture_widget)
jmessage_broadcast_to_parents(msg, capture_widget);
if (mouse_widget)
jmessage_broadcast_to_parents(msg, mouse_widget);
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
/* generate JM_CHAR/JM_KEYPRESSED messages */
@ -423,40 +507,63 @@ bool jmanager_poll(JWidget manager, bool all_windows)
}
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
/* generate JM_KEYRELEASED messages */
for (c=0; c<KEY_MAX; c++) {
if (old_readed_key[c] != key[c] && old_readed_key[c]) {
/* press/release key interface */
msg = new_key_msg (JM_KEYRELEASED, (c << 8) | scancode_to_ascii (c));
msg = new_key_msg (JM_KEYRELEASED, (c << 8) | scancode_to_ascii(c));
old_readed_key[c] = key[c];
broadcast_key_msg (manager, msg);
broadcast_key_msg(manager, msg);
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
}
/* broadcast the IDLE message */
msg = new_mouse_msg(JM_IDLE);
JI_LIST_FOR_EACH(proc_windows_list, link) {
window = link->data;
jmessage_broadcast_to_children (msg, window);
/* timers */
if (n_timers > 0) {
int t = ji_clock;
for (c=0; c<n_timers; ++c) {
if (timers[c] && timers[c]->last_time >= 0) {
while (t - timers[c]->last_time > timers[c]->interval) {
timers[c]->last_time += timers[c]->interval;
msg = jmessage_new(JM_TIMER);
msg->timer.timer_id = c;
jmessage_add_dest(msg, timers[c]->widget);
jmanager_enqueue_message(msg);
/* we spend too much time here */
if (ji_clock - t > timers[c]->interval) {
timers[c]->last_time = ji_clock;
break;
}
}
}
}
}
jmessage_add_dest(msg, manager);
jmanager_enqueue_message(msg);
jmessage_free(msg);
/* process messages queue */
jmanager_dispatch_messages();
if (!jlist_empty(msg_queue)) {
/* clean the queue of messages */
jmanager_dispatch_messages();
/* redraw dirty widgets */
jwidget_flush_redraw(manager);
jmanager_dispatch_messages();
/* redraw dirty widgets */
jwidget_flush_redraw(manager);
jmanager_dispatch_messages();
/* add the "Queue Processing" message for the manager */
msg = new_mouse_msg(JM_QUEUEPROCESSING);
jmessage_add_dest(msg, manager);
jmanager_enqueue_message(msg);
jmanager_dispatch_messages();
}
/* make some OSes happy */
yield_timeslice();
rest(1);
/* old windows to close? */
if (!jlist_empty(old_windows)) {
@ -489,14 +596,238 @@ bool jmanager_poll(JWidget manager, bool all_windows)
return ret;
}
void jmanager_enqueue_message(const JMessage msg)
/**
* Adds a timer event for the specified widget.
*
* @return A timer ID that can be used with @ref jmanager_remove_timer
*/
int jmanager_add_timer(JWidget widget, int interval)
{
jlist_append(msg_queue, jmessage_new_copy(msg));
Timer *timer;
int c, new_id = -1;
assert_valid_widget(widget);
for (c=0; c<n_timers; ++c) {
/* there are an empty slot */
if (timers[c] == NULL) {
new_id = c;
break;
}
}
if (new_id < 0) {
new_id = n_timers++;
timers = jrenew(Timer *, timers, n_timers);
}
timer = jnew(Timer, 1);
timer->widget = widget;
timer->interval = interval;
timer->last_time = -1;
timers[new_id] = timer;
return new_id;
}
void jmanager_remove_timer(int timer_id)
{
assert(timer_id >= 0 && timer_id < n_timers);
assert(timers[timer_id] != NULL);
jfree(timers[timer_id]);
timers[timer_id] = NULL;
}
void jmanager_start_timer(int timer_id)
{
assert(timer_id >= 0 && timer_id < n_timers);
assert(timers[timer_id] != NULL);
timers[timer_id]->last_time = ji_clock;
}
void jmanager_stop_timer(int timer_id)
{
assert(timer_id >= 0 && timer_id < n_timers);
assert(timers[timer_id] != NULL);
timers[timer_id]->last_time = -1;
}
/**
* @param msg You can't use the this message after calling this
* routine. The message will be automatically freed through
* @ref jmessage_free
*/
void jmanager_enqueue_message(JMessage msg)
{
int c;
assert(msg_queue != NULL);
assert(msg != NULL);
/* check if this message must be filtered by some widget before */
c = msg->type;
if (c >= JM_REGISTERED_MESSAGES)
c = JM_REGISTERED_MESSAGES;
if (!jlist_empty(msg_filters[c])) { /* ok, so are filters to add ... */
JLink link;
/* add all the filters in the destination list of the message */
JI_LIST_FOR_EACH_BACK(msg_filters[c], link) {
Filter *filter = link->data;
if (msg->type == filter->message)
jmessage_add_pre_dest(msg, filter->widget);
}
}
/* jlist_insert_before(msg_queue, */
/* enqueue_messages_before_this, msg); */
jlist_append(msg_queue, msg);
}
void jmanager_dispatch_messages(void)
{
dispatch_msgs();
JMessage msg, first_msg;
JLink link, link2, next;
JWidget widget;
bool done;
#ifdef LIMIT_DISPATCH_TIME
int t = ji_clock;
#endif
assert(msg_queue != NULL);
link = jlist_first(msg_queue);
while (link != msg_queue->end) {
msg = link->data;
#ifdef LIMIT_DISPATCH_TIME
if (ji_clock-t > 250)
break;
#endif
/* go to next message */
if (msg->any.used) {
link = link->next;
continue;
}
enqueue_messages_before_this = link->next;
/* this message is in use */
msg->any.used = TRUE;
first_msg = msg;
done = FALSE;
do {
JI_LIST_FOR_EACH(msg->any.widgets, link2) {
widget = link2->data;
#ifdef REPORT_EVENTS
{
static char *msg_name[] = {
"Open",
"Close",
"Destroy",
"Draw",
"Idle",
"Signal",
"Timer",
"ReqSize",
"SetPos",
"WinMove",
"DrawRgn",
"DirtyChildren",
"QueueProcessing",
"Char",
"KeyPressed",
"KeyReleased",
"FocusEnter",
"FocusLeave",
"ButtonPressed",
"ButtonReleased",
"DoubleClick",
"LostClick",
"MouseEnter",
"MouseLeave",
"Motion",
"Wheel",
};
const char *string =
(msg->type >= JM_OPEN &&
msg->type <= JM_WHEEL) ? msg_name[msg->type]:
"Unknown";
printf("Event: %s (%d)\n", string, widget->id);
fflush(stdout);
}
#endif
/* draw message? */
if (msg->type == JM_DRAW) {
/* hidden? */
if (widget->flags & JI_HIDDEN)
continue;
jmouse_hide();
acquire_bitmap(ji_screen);
/* set clip */
set_clip(ji_screen,
msg->draw.rect.x1, msg->draw.rect.y1,
msg->draw.rect.x2-1, msg->draw.rect.y2-1);
#ifdef REPORT_EVENTS
printf("set_clip(%d, %d, %d, %d)\n",
msg->draw.rect.x1, msg->draw.rect.y1,
msg->draw.rect.x2-1, msg->draw.rect.y2-1);
fflush(stdout);
#endif
/* rectfill(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1, makecol(255, 0, 0)); */
/* vsync(); vsync(); vsync(); vsync(); */
}
/* call message handler */
done = jwidget_send_message(widget, msg);
/* restore clip */
if (msg->type == JM_DRAW) {
set_clip(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1);
/* dirty rectangles */
if (ji_dirty_region)
ji_add_dirty_rect(&msg->draw.rect);
release_bitmap(ji_screen);
jmouse_show();
}
if (done)
break;
}
/* done? */
if (done)
/* don't go to sub-msg */
msg = NULL;
else
/* use sub-msg */
msg = msg->any.sub_msg;
} while (msg);
/* remove the message from the msg_queue */
next = link->next;
jlist_delete_link(msg_queue, link);
link = next;
/* destroy the message */
jmessage_free(first_msg);
}
enqueue_messages_before_this = NULL;
}
JWidget jmanager_get_focus(void)
@ -521,7 +852,7 @@ void jmanager_set_focus(JWidget widget)
|| (!(widget->flags & JI_DISABLED)
&& !(widget->flags & JI_HIDDEN)
&& !(widget->flags & JI_DECORATIVE)
&& some_parent_is_focusrest (widget)))) {
&& some_parent_is_focusrest(widget)))) {
JList widget_parents = NULL;
JWidget common_parent = NULL;
JLink link, link2;
@ -535,8 +866,8 @@ void jmanager_set_focus(JWidget widget)
/* fetch the focus */
if (focus_widget) {
JList focus_parents = jwidget_get_parents (focus_widget, TRUE);
msg = jmessage_new (JM_FOCUSLEAVE);
JList focus_parents = jwidget_get_parents(focus_widget, TRUE);
msg = jmessage_new(JM_FOCUSLEAVE);
JI_LIST_FOR_EACH(focus_parents, link) {
if (widget) {
@ -557,7 +888,6 @@ void jmanager_set_focus(JWidget widget)
}
jmanager_enqueue_message(msg);
jmessage_free(msg);
jlist_free(focus_parents);
}
@ -584,7 +914,6 @@ void jmanager_set_focus(JWidget widget)
}
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
jlist_free(widget_parents);
@ -630,7 +959,6 @@ void jmanager_set_mouse(JWidget widget)
}
jmanager_enqueue_message(msg);
jmessage_free(msg);
jlist_free(mouse_parents);
}
@ -652,7 +980,6 @@ void jmanager_set_mouse(JWidget widget)
}
jmanager_enqueue_message(msg);
jmessage_free(msg);
}
jlist_free(widget_parents);
@ -737,6 +1064,29 @@ void jmanager_refresh_screen(void)
jwidget_invalidate(default_manager);
}
void jmanager_add_msg_filter(int message, JWidget widget)
{
int c = message;
if (c >= JM_REGISTERED_MESSAGES)
c = JM_REGISTERED_MESSAGES;
jlist_append(msg_filters[c], filter_new(message, widget));
}
void jmanager_remove_msg_filter(int message, JWidget widget)
{
JLink link, next;
int c = message;
if (c >= JM_REGISTERED_MESSAGES)
c = JM_REGISTERED_MESSAGES;
JI_LIST_FOR_EACH_SAFE(msg_filters[c], link, next) {
Filter *filter = link->data;
if (filter->widget == widget)
jlist_delete_link(msg_filters[c], link);
}
}
/* configures the window for begin the loop */
void _jmanager_open_window(JWidget manager, JWidget window)
{
@ -758,7 +1108,6 @@ void _jmanager_open_window(JWidget manager, JWidget window)
msg = jmessage_new(JM_OPEN);
jmessage_broadcast_to_children(msg, window);
jmanager_enqueue_message(msg);
jmessage_free(msg);
/* update the new windows list to show */
jlist_append(new_windows, window);
@ -815,9 +1164,9 @@ void _jmanager_close_window(JWidget manager, JWidget window,
msg = jmessage_new(JM_CLOSE);
jmessage_broadcast_to_children(msg, window);
jmanager_enqueue_message(msg);
jmessage_free(msg);
jmanager_dispatch_messages(); /* TODO WARNING!!! */
/* TODO this was uncommented */
/* jmanager_dispatch_messages(); /\* TODO WARNING!!! *\/ */
/* update manager list stuff */
jlist_remove(manager->children, window);
@ -840,7 +1189,6 @@ void _jmanager_close_window(JWidget manager, JWidget window,
}
}
/**********************************************************************
Manager
**********************************************************************/
@ -977,149 +1325,17 @@ static void manager_redraw_region(JWidget widget, JRegion region)
jregion_free(reg2);
}
/**********************************************************************
Internal routines
**********************************************************************/
static void dispatch_msgs(void)
{
JMessage msg, first_msg;
JLink link, link2, next;
JWidget widget;
bool done;
#ifdef LIMIT_DISPATCH_TIME
int t = ji_clock;
#endif
link = jlist_first(msg_queue);
while (link != msg_queue->end) {
msg = link->data;
#ifdef LIMIT_DISPATCH_TIME
if (ji_clock-t > JI_TICKS_PER_SEC/4)
break;
#endif
/* go to next message */
if (msg->any.used) {
link = link->next;
continue;
}
/* this message is in use */
msg->any.used = TRUE;
first_msg = msg;
done = FALSE;
do {
JI_LIST_FOR_EACH(msg->any.widgets, link2) {
widget = link2->data;
#ifdef REPORT_EVENTS
if (msg->type != JM_IDLE) { /* don't report IDLE message */
static char *msg_name[] = {
"Open",
"Close",
"Destroy",
"Draw",
"Idle",
"Signal",
"ReqSize",
"SetPos",
"WinMove",
"DrawRgn",
"DirtyChildren",
"Char",
"KeyPressed",
"KeyReleased",
"FocusEnter",
"FocusLeave",
"ButtonPressed",
"ButtonReleased",
"DoubleClick",
"MouseEnter",
"MouseLeave",
"Motion",
"Wheel",
};
const char *string =
(msg->type >= JM_OPEN &&
msg->type <= JM_WHEEL) ? msg_name[msg->type]:
"Unknown";
printf("Event: %s (%d)\n", string, widget->id);
}
#endif
/* draw message? */
if (msg->type == JM_DRAW) {
/* hidden? */
if (widget->flags & JI_HIDDEN)
continue;
jmouse_hide();
acquire_bitmap(ji_screen);
/* set clip */
set_clip(ji_screen,
msg->draw.rect.x1, msg->draw.rect.y1,
msg->draw.rect.x2-1, msg->draw.rect.y2-1);
#ifdef REPORT_EVENTS
printf("set_clip (%d, %d, %d, %d)\n",
msg->draw.rect.x1, msg->draw.rect.y1,
msg->draw.rect.x2-1, msg->draw.rect.y2-1);
#endif
/* rectfill (ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1, makecol (255, 0, 0)); */
/* vsync (); vsync (); vsync (); vsync (); */
}
/* call message handler */
done = jwidget_send_message(widget, msg);
/* restore clip */
if (msg->type == JM_DRAW) {
set_clip(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1);
/* dirty rectangles */
if (ji_dirty_region)
ji_add_dirty_rect(&msg->draw.rect);
release_bitmap(ji_screen);
jmouse_show();
}
if (done) /* TODO use marshal? */
break;
}
/* done? */
if (done) /* TODO use marshal? */
/* don't go to sub-msg */
msg = NULL;
else
/* use sub-msg */
msg = msg->any.sub_msg;
} while (msg);
/* remove the message from the msg_queue */
next = link->next;
jlist_delete_link(msg_queue, link);
link = next;
/* destroy the message */
jmessage_free(first_msg);
}
}
static void destroy_window (JWidget window)
static void destroy_window(JWidget window)
{
/* printf (" %d DESTROYED BY MANAGER\n", window->id); */
/* delete the window */
if (jwidget_is_autodestroy (window))
jwidget_free (window);
if (jwidget_is_autodestroy(window))
jwidget_free(window);
}
static void remove_msgs_for(JWidget widget, JMessage msg)
@ -1159,7 +1375,7 @@ static void generate_proc_windows_list2(JWidget widget)
generate_proc_windows_list2(link->data);
}
static int some_parent_is_focusrest (JWidget widget)
static int some_parent_is_focusrest(JWidget widget)
{
if (jwidget_is_focusrest(widget))
return TRUE;
@ -1194,7 +1410,6 @@ static JMessage new_mouse_msg(int type)
msg->mouse.x = jmouse_x(0);
msg->mouse.y = jmouse_y(0);
msg->mouse.flags =
type == JM_DOUBLECLICK ? jmouse_get_click_button():
type == JM_BUTTONRELEASED ? jmouse_b(1):
jmouse_b(0);
msg->mouse.left = msg->mouse.flags & 1 ? TRUE: FALSE;
@ -1252,7 +1467,23 @@ static void broadcast_key_msg(JWidget manager, JMessage msg)
}
}
static Filter *filter_new(int message, JWidget widget)
{
Filter *filter = jnew(Filter, 1);
if (!filter)
return NULL;
filter->message = message;
filter->widget = widget;
return filter;
}
static void filter_free(Filter *filter)
{
jfree(filter);
}
/***********************************************************************
Focus Movement
***********************************************************************/

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -44,9 +44,16 @@ void jmanager_free(JWidget manager);
void jmanager_run(JWidget manager);
bool jmanager_poll(JWidget manager, bool all_windows);
/* timers */
int jmanager_add_timer(JWidget widget, int interval);
void jmanager_remove_timer(int timer_id);
void jmanager_start_timer(int timer_id);
void jmanager_stop_timer(int timer_id);
/* routines that uses the ji_get_default_manager() */
void jmanager_enqueue_message(const JMessage msg);
void jmanager_enqueue_message(JMessage msg);
void jmanager_dispatch_messages(void);
JWidget jmanager_get_focus(void);
@ -66,6 +73,9 @@ void jmanager_remove_message(JMessage msg);
void jmanager_remove_messages_for(JWidget widget);
void jmanager_refresh_screen(void);
void jmanager_add_msg_filter(int message, JWidget widget);
void jmanager_remove_msg_filter(int message, JWidget widget);
JI_END_DECLS
#endif /* JINETE_MANAGER_H */

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,6 +31,7 @@
#include <allegro/keyboard.h>
#include <string.h>
#include <assert.h>
#include "jinete/jlist.h"
#include "jinete/jmanager.h"
@ -38,6 +39,13 @@
#include "jinete/jrect.h"
#include "jinete/jwidget.h"
static int registered_messages = JM_REGISTERED_MESSAGES;
int ji_register_message_type(void)
{
return registered_messages++;
}
JMessage jmessage_new(int type)
{
JMessage msg;
@ -66,6 +74,8 @@ JMessage jmessage_new_copy(const JMessage msg)
{
JMessage copy;
assert(msg != NULL);
copy = jnew(union jmessage, 1);
if (!copy)
return NULL;
@ -82,6 +92,8 @@ JMessage jmessage_new_copy(const JMessage msg)
void jmessage_free(JMessage msg)
{
assert(msg != NULL);
if (msg->any.sub_msg)
jmessage_free(msg->any.sub_msg);
@ -91,13 +103,27 @@ void jmessage_free(JMessage msg)
void jmessage_add_dest(JMessage msg, JWidget widget)
{
assert(msg != NULL);
assert_valid_widget(widget);
jlist_append(msg->any.widgets, widget);
}
void jmessage_add_pre_dest(JMessage msg, JWidget widget)
{
assert(msg != NULL);
assert_valid_widget(widget);
jlist_prepend(msg->any.widgets, widget);
}
void jmessage_broadcast_to_children(JMessage msg, JWidget widget)
{
JLink link;
assert(msg != NULL);
assert_valid_widget(widget);
JI_LIST_FOR_EACH(widget->children, link)
jmessage_broadcast_to_children(msg, link->data);
@ -106,6 +132,9 @@ void jmessage_broadcast_to_children(JMessage msg, JWidget widget)
void jmessage_broadcast_to_parents(JMessage msg, JWidget widget)
{
assert(msg != NULL);
assert_valid_widget(widget);
if (widget && widget->type != JI_MANAGER) {
jmessage_add_dest(msg, widget);
jmessage_broadcast_to_parents(msg, jwidget_get_parent(widget));
@ -114,6 +143,8 @@ void jmessage_broadcast_to_parents(JMessage msg, JWidget widget)
void jmessage_set_sub_msg(JMessage msg, JMessage sub_msg)
{
assert(msg != NULL);
if (msg->any.sub_msg)
jmessage_free(msg->any.sub_msg);

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,6 +37,16 @@
JI_BEGIN_DECLS
/* TODO add mutexes */
#define JM_MESSAGE(name) \
static int _jm_##name = 0; \
static int jm_##name() \
{ \
if (!_jm_##name) \
_jm_##name = ji_register_message_type(); \
return _jm_##name; \
} \
struct jmessage_any
{
int type; /* type of message */
@ -77,6 +87,12 @@ struct jmessage_signal
JWidget from; /* signal generator */
};
struct jmessage_timer
{
struct jmessage_any any;
int timer_id; /* number of timer */
};
struct jmessage_setpos
{
struct jmessage_any any;
@ -95,6 +111,13 @@ struct jmessage_drawrgn
JRegion region; /* region to redraw */
};
struct jmessage_user
{
struct jmessage_any any;
int a, b, c;
void *dp;
};
union jmessage
{
int type;
@ -103,16 +126,21 @@ union jmessage
struct jmessage_draw draw;
struct jmessage_mouse mouse;
struct jmessage_signal signal;
struct jmessage_timer timer;
struct jmessage_setpos setpos;
struct jmessage_reqsize reqsize;
struct jmessage_drawrgn drawrgn;
struct jmessage_user user;
};
int ji_register_message_type(void);
JMessage jmessage_new(int type);
JMessage jmessage_new_copy(const JMessage msg);
void jmessage_free(JMessage msg);
void jmessage_add_dest(JMessage msg, JWidget widget);
void jmessage_add_pre_dest(JMessage msg, JWidget widget);
void jmessage_broadcast_to_children(JMessage msg, JWidget widget);
void jmessage_broadcast_to_parents(JMessage msg, JWidget widget);

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2007 David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2007 David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -63,6 +63,10 @@ static BITMAP *sprite_cursor = NULL;
static int focus_x;
static int focus_y;
static BITMAP *covered_area = NULL;
static int covered_area_x;
static int covered_area_y;
/* Mouse information (button and position). */
static volatile int m_b[2];
@ -73,19 +77,15 @@ static int m_z[2];
static bool moved;
static int mouse_scares = 0;
/* For double click management. */
static volatile int click_clock = 0;
static volatile int click_level = JI_CLICK_NOT;
static volatile int click_mouse_b = 0;
/* Local routines. */
static void set_cursor(BITMAP *bmp, int x, int y);
static void clock_inc(void);
static void check_click(void);
static void update_mouse_position(void);
static void capture_covered_area(void);
static void restore_covered_area(void);
static void clock_inc(void)
{
ji_clock++;
@ -93,55 +93,6 @@ static void clock_inc(void)
END_OF_STATIC_FUNCTION(clock_inc);
/* Based on "dclick_check" from allegro/src/gui.c. */
static void check_click(void)
{
/* Waiting mouse released... */
if (click_level == JI_CLICK_START) {
/* The button was released. */
if (!m_b[0]) {
click_clock = 0;
click_level = JI_CLICK_RELEASE;
}
/* The button continue pressed. */
else {
/* Does mouse button change? */
if (click_mouse_b != m_b[0]) {
/* Start again with this new button. */
click_clock = 0;
click_level = JI_CLICK_START;
click_mouse_b = m_b[0];
}
else
click_clock++;
}
}
/* Waiting second mouse click... */
else if (click_level == JI_CLICK_RELEASE) {
/* The button is pressed again. */
if (m_b[0]) {
/* Is the same button? */
if (m_b[0] == click_mouse_b) {
click_level = JI_CLICK_AGAIN;
}
/* If it's other button, start again with this one. */
else {
click_clock = 0;
click_level = JI_CLICK_START;
click_mouse_b = m_b[0];
}
}
else
click_clock++;
}
if (click_clock > 10)
click_level = JI_CLICK_NOT;
}
END_OF_STATIC_FUNCTION(check_click);
static void set_cursor(BITMAP *bmp, int x, int y)
{
sprite_cursor = bmp;
@ -160,14 +111,9 @@ int _ji_system_init(void)
/* Install timer related stuff. */
LOCK_VARIABLE(ji_clock);
LOCK_VARIABLE(m_b);
LOCK_VARIABLE(click_clock);
LOCK_VARIABLE(click_level);
LOCK_VARIABLE(click_mouse_b);
LOCK_FUNCTION(clock_inc);
LOCK_FUNCTION(check_click);
if ((install_int_ex(clock_inc, BPS_TO_TIMER(JI_TICKS_PER_SEC)) < 0) ||
(install_int(check_click, 20) < 0))
if (install_int_ex(clock_inc, BPS_TO_TIMER(1000)) < 0)
return -1;
jmouse_poll();
@ -182,7 +128,6 @@ void _ji_system_exit(void)
{
ji_set_screen(NULL);
remove_int(check_click);
remove_int(clock_inc);
}
@ -276,7 +221,7 @@ void ji_flip_rect(JRect rect)
}
}
void ji_set_translation_hook(const char *(*gettext) (const char *msgid))
void ji_set_translation_hook(const char *(*gettext)(const char *msgid))
{
strings_hook = gettext;
}
@ -284,7 +229,7 @@ void ji_set_translation_hook(const char *(*gettext) (const char *msgid))
const char *ji_translate_string(const char *msgid)
{
if (strings_hook)
return (*strings_hook) (msgid);
return (*strings_hook)(msgid);
else
return msgid;
}
@ -329,6 +274,7 @@ int jmouse_set_cursor(int type)
*/
void jmouse_draw_cursor()
{
#if 0
if (sprite_cursor != NULL && mouse_scares == 0) {
int x = m_x[0]-focus_x;
int y = m_y[0]-focus_y;
@ -345,33 +291,57 @@ void jmouse_draw_cursor()
jrect_free(rect);
}
#endif
if (sprite_cursor != NULL && mouse_scares == 0) {
int x = m_x[0]-focus_x;
int y = m_y[0]-focus_y;
restore_covered_area();
capture_covered_area();
draw_sprite(ji_screen, sprite_cursor, x, y);
if (ji_dirty_region) {
JRect rect = jrect_new(x, y,
x+sprite_cursor->w,
y+sprite_cursor->h);
ji_add_dirty_rect(rect);
jrect_free(rect);
}
}
}
void jmouse_hide()
{
ASSERT(mouse_scares >= 0);
assert(mouse_scares >= 0);
if (ji_screen == screen)
scare_mouse();
else if (mouse_scares == 0)
restore_covered_area();
mouse_scares++;
}
void jmouse_show()
{
ASSERT(mouse_scares > 0);
assert(mouse_scares > 0);
mouse_scares--;
if (ji_screen == screen)
unscare_mouse();
}
bool jmouse_is_hidden()
{
ASSERT(mouse_scares >= 0);
assert(mouse_scares >= 0);
return mouse_scares > 0;
}
bool jmouse_is_shown()
{
ASSERT(mouse_scares >= 0);
assert(mouse_scares >= 0);
return mouse_scares == 0;
}
@ -458,25 +428,6 @@ bool jmouse_control_infinite_scroll(JRect rect)
return FALSE;
}
int jmouse_get_click_button(void)
{
return click_mouse_b;
}
int jmouse_get_click_level(void)
{
return click_level;
}
void jmouse_set_click_level(int level)
{
click_level = level;
if (level == JI_CLICK_START) {
click_clock = 0;
click_mouse_b = m_b[0];
}
}
static void update_mouse_position(void)
{
if (ji_screen == screen) {
@ -528,3 +479,29 @@ static void update_mouse_position(void)
#endif
}
static void capture_covered_area(void)
{
if (sprite_cursor != NULL && mouse_scares == 0) {
assert(covered_area == NULL);
covered_area = create_bitmap(sprite_cursor->w, sprite_cursor->h);
covered_area_x = m_x[0]-focus_x;
covered_area_y = m_y[0]-focus_y;
blit(ji_screen, covered_area,
covered_area_x, covered_area_y, 0, 0,
covered_area->w, covered_area->h);
}
}
static void restore_covered_area(void)
{
if (covered_area != NULL) {
blit(covered_area, ji_screen,
0, 0, covered_area_x, covered_area_y,
covered_area->w, covered_area->h);
destroy_bitmap(covered_area);
covered_area = NULL;
}
}

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -63,20 +63,11 @@ const char *ji_translate_string(const char *msgid);
/***********************************************************************/
/* timer related */
#define JI_TICKS_PER_SEC 1024
extern int volatile ji_clock;
extern int volatile ji_clock; /* in milliseconds */
/***********************************************************************/
/* mouse related */
enum {
JI_CLICK_NOT,
JI_CLICK_START,
JI_CLICK_RELEASE,
JI_CLICK_AGAIN,
};
enum {
JI_CURSOR_NULL,
JI_CURSOR_NORMAL,
@ -114,10 +105,6 @@ int jmouse_z(int antique);
bool jmouse_control_infinite_scroll(JRect rect);
int jmouse_get_click_button(void);
int jmouse_get_click_level(void);
void jmouse_set_click_level(int level);
JI_END_DECLS
#endif /* JINETE_SYSTEM_H */

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,6 +31,7 @@
/* #define REPORT_SIGNALS */
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
@ -46,9 +47,9 @@
#include "jinete/jinete.h"
#include "jinete/jintern.h"
static bool widget_msg_proc (JWidget widget, JMessage msg);
int ji_register_widget_type (void)
static bool widget_msg_proc(JWidget widget, JMessage msg);
int ji_register_widget_type(void)
{
static int type = JI_USER_WIDGET;
return type++;
@ -101,7 +102,7 @@ JWidget jwidget_new(int type)
widget->user_data[2] = NULL;
widget->user_data[3] = NULL;
jwidget_add_hook (widget, JI_WIDGET, widget_msg_proc, NULL);
jwidget_add_hook(widget, JI_WIDGET, widget_msg_proc, NULL);
return widget;
}
@ -111,6 +112,8 @@ void jwidget_free(JWidget widget)
JLink link, next;
JMessage msg;
assert_valid_widget(widget);
/* send destroy message */
msg = jmessage_new(JM_DESTROY);
jwidget_send_message(widget, msg);
@ -122,7 +125,7 @@ void jwidget_free(JWidget widget)
/* remove from parent */
if (widget->parent)
jwidget_remove_child (widget->parent, widget);
jwidget_remove_child(widget->parent, widget);
/* remove children */
JI_LIST_FOR_EACH_SAFE(widget->children, link, next) {
@ -159,6 +162,8 @@ void jwidget_free(JWidget widget)
void jwidget_init_theme(JWidget widget)
{
assert_valid_widget(widget);
if (widget->theme) {
if (!widget->draw_method)
widget->draw_method = jtheme_get_method(widget->theme, widget->draw_type);
@ -173,7 +178,7 @@ void jwidget_init_theme(JWidget widget)
}
}
}
/**********************************************************************/
/* HOOKS */
@ -185,8 +190,11 @@ void jwidget_init_theme(JWidget widget)
void jwidget_add_hook(JWidget widget, int type,
JMessageFunc msg_proc, void *data)
{
JHook hook = jhook_new();
JHook hook;
assert_valid_widget(widget);
hook = jhook_new();
hook->type = type;
hook->msg_proc = msg_proc;
hook->data = data;
@ -200,6 +208,8 @@ void jwidget_add_hook(JWidget widget, int type,
JHook jwidget_get_hook(JWidget widget, int type)
{
JLink link;
assert_valid_widget(widget);
JI_LIST_FOR_EACH(widget->hooks, link) {
if (((JHook)link->data)->type == type)
return ((JHook)link->data);
@ -213,55 +223,73 @@ JHook jwidget_get_hook(JWidget widget, int type)
void *jwidget_get_data(JWidget widget, int type)
{
JLink link;
assert_valid_widget(widget);
JI_LIST_FOR_EACH(widget->hooks, link) {
if (((JHook)link->data)->type == type)
return ((JHook)link->data)->data;
}
return NULL;
}
void _jwidget_add_hook(JWidget widget, JHook hook)
{
assert_valid_widget(widget);
jlist_prepend(widget->hooks, hook);
}
void _jwidget_remove_hook(JWidget widget, JHook hook)
{
assert_valid_widget(widget);
jlist_remove(widget->hooks, hook);
}
/**********************************************************************/
/* main properties */
int jwidget_get_type(JWidget widget)
{
assert_valid_widget(widget);
return widget->type;
}
const char *jwidget_get_name(JWidget widget)
{
assert_valid_widget(widget);
return widget->name;
}
const char *jwidget_get_text(JWidget widget)
{
assert_valid_widget(widget);
jwidget_emit_signal(widget, JI_SIGNAL_GET_TEXT);
return widget->text;
}
int jwidget_get_align(JWidget widget)
{
assert_valid_widget(widget);
return widget->align;
}
FONT *jwidget_get_font(JWidget widget)
{
assert_valid_widget(widget);
return widget->text_font;
}
void jwidget_set_name(JWidget widget, const char *name)
{
assert_valid_widget(widget);
if (widget->name)
jfree (widget->name);
@ -270,6 +298,8 @@ void jwidget_set_name(JWidget widget, const char *name)
void jwidget_set_text(JWidget widget, const char *text)
{
assert_valid_widget(widget);
if (text) {
/* more space needed */
if (!widget->text || widget->text_size < strlen (text)+1) {
@ -297,6 +327,8 @@ void jwidget_set_text(JWidget widget, const char *text)
void jwidget_set_align(JWidget widget, int align)
{
assert_valid_widget(widget);
widget->align = align;
jwidget_dirty (widget);
@ -304,6 +336,8 @@ void jwidget_set_align(JWidget widget, int align)
void jwidget_set_font(JWidget widget, FONT *font)
{
assert_valid_widget(widget);
widget->text_font = font;
if (widget->text && widget->text_font)
@ -315,12 +349,13 @@ void jwidget_set_font(JWidget widget, FONT *font)
jwidget_dirty (widget);
}
/**********************************************************************/
/* behavior properties */
void jwidget_magnetic(JWidget widget, bool state)
{
assert_valid_widget(widget);
if (state)
widget->flags |= JI_MAGNETIC;
else
@ -329,6 +364,8 @@ void jwidget_magnetic(JWidget widget, bool state)
void jwidget_expansive(JWidget widget, bool state)
{
assert_valid_widget(widget);
if (state)
widget->flags |= JI_EXPANSIVE;
else
@ -337,6 +374,8 @@ void jwidget_expansive(JWidget widget, bool state)
void jwidget_decorative(JWidget widget, bool state)
{
assert_valid_widget(widget);
if (state)
widget->flags |= JI_DECORATIVE;
else
@ -347,6 +386,8 @@ void jwidget_autodestroy(JWidget widget, bool state)
{
JLink link;
assert_valid_widget(widget);
if (state)
widget->flags |= JI_AUTODESTROY;
else
@ -358,6 +399,8 @@ void jwidget_autodestroy(JWidget widget, bool state)
void jwidget_focusrest(JWidget widget, bool state)
{
assert_valid_widget(widget);
if (state)
widget->flags |= JI_FOCUSREST;
else
@ -366,34 +409,46 @@ void jwidget_focusrest(JWidget widget, bool state)
bool jwidget_is_magnetic(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_MAGNETIC) ? TRUE: FALSE;
}
bool jwidget_is_expansive(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_EXPANSIVE) ? TRUE: FALSE;
}
bool jwidget_is_decorative(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_DECORATIVE) ? TRUE: FALSE;
}
bool jwidget_is_autodestroy(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_AUTODESTROY) ? TRUE: FALSE;
}
bool jwidget_is_focusrest(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_FOCUSREST) ? TRUE: FALSE;
}
/**********************************************************************/
/* status properties */
void jwidget_dirty(JWidget widget)
{
assert_valid_widget(widget);
#if 0
/* is visible? */
if (jwidget_is_visible (widget)) {
@ -410,12 +465,14 @@ void jwidget_dirty(JWidget widget)
jwidget_emit_signal (widget, JI_SIGNAL_DIRTY);
}
#else
jwidget_invalidate (widget);
jwidget_invalidate(widget);
#endif
}
void jwidget_show(JWidget widget)
{
assert_valid_widget(widget);
if (widget->flags & JI_HIDDEN) {
widget->flags &= ~JI_HIDDEN;
@ -426,6 +483,8 @@ void jwidget_show(JWidget widget)
void jwidget_hide(JWidget widget)
{
assert_valid_widget(widget);
if (!(widget->flags & JI_HIDDEN)) {
jmanager_free_widget (widget); /* free from mananger */
@ -436,6 +495,8 @@ void jwidget_hide(JWidget widget)
void jwidget_enable(JWidget widget)
{
assert_valid_widget(widget);
if (widget->flags & JI_DISABLED) {
widget->flags &= ~JI_DISABLED;
jwidget_dirty (widget);
@ -446,6 +507,8 @@ void jwidget_enable(JWidget widget)
void jwidget_disable(JWidget widget)
{
assert_valid_widget(widget);
if (!(widget->flags & JI_DISABLED)) {
jmanager_free_widget (widget); /* free from the manager */
@ -458,6 +521,8 @@ void jwidget_disable(JWidget widget)
void jwidget_select(JWidget widget)
{
assert_valid_widget(widget);
if (!(widget->flags & JI_SELECTED)) {
widget->flags |= JI_SELECTED;
jwidget_dirty (widget);
@ -468,6 +533,8 @@ void jwidget_select(JWidget widget)
void jwidget_deselect(JWidget widget)
{
assert_valid_widget(widget);
if (widget->flags & JI_SELECTED) {
widget->flags &= ~JI_SELECTED;
jwidget_dirty (widget);
@ -478,11 +545,15 @@ void jwidget_deselect(JWidget widget)
bool jwidget_is_visible(JWidget widget)
{
assert_valid_widget(widget);
return !(jwidget_is_hidden(widget));
}
bool jwidget_is_hidden(JWidget widget)
{
assert_valid_widget(widget);
do {
if (widget->flags & JI_HIDDEN)
return TRUE;
@ -495,11 +566,15 @@ bool jwidget_is_hidden(JWidget widget)
bool jwidget_is_enabled(JWidget widget)
{
assert_valid_widget(widget);
return !(jwidget_is_disabled(widget));
}
bool jwidget_is_disabled(JWidget widget)
{
assert_valid_widget(widget);
do {
if (widget->flags & JI_DISABLED)
return TRUE;
@ -512,37 +587,50 @@ bool jwidget_is_disabled(JWidget widget)
bool jwidget_is_selected(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_SELECTED) ? TRUE: FALSE;
}
bool jwidget_is_deselected(JWidget widget)
{
return !(jwidget_is_selected (widget));
assert_valid_widget(widget);
return !(jwidget_is_selected(widget));
}
/**********************************************************************/
/* properties with manager */
bool jwidget_has_focus(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_HASFOCUS) ? TRUE: FALSE;
}
bool jwidget_has_mouse(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_HASMOUSE) ? TRUE: FALSE;
}
bool jwidget_has_capture(JWidget widget)
{
assert_valid_widget(widget);
return (widget->flags & JI_HASCAPTURE) ? TRUE: FALSE;
}
/**********************************************************************/
/* children handle */
void jwidget_add_child(JWidget widget, JWidget child)
{
assert_valid_widget(widget);
assert_valid_widget(child);
jlist_append(widget->children, child);
child->parent = widget;
@ -555,6 +643,8 @@ void jwidget_add_childs(JWidget widget, ...)
JWidget child;
va_list ap;
assert_valid_widget(widget);
va_start(ap, widget);
while ((child = va_arg(ap, JWidget)))
@ -565,6 +655,9 @@ void jwidget_add_childs(JWidget widget, ...)
void jwidget_remove_child(JWidget widget, JWidget child)
{
assert_valid_widget(widget);
assert_valid_widget(child);
jlist_remove(widget->children, child);
child->parent = NULL;
@ -576,6 +669,10 @@ void jwidget_replace_child(JWidget widget, JWidget old_child, JWidget new_child)
{
JLink before;
assert_valid_widget(widget);
assert_valid_widget(old_child);
assert_valid_widget(new_child);
before = jlist_find(widget->children, old_child);
if (!before)
return;
@ -589,19 +686,23 @@ void jwidget_replace_child(JWidget widget, JWidget old_child, JWidget new_child)
jwidget_emit_signal(new_child, JI_SIGNAL_NEW_PARENT);
jwidget_emit_signal(widget, JI_SIGNAL_ADD_CHILD);
}
/**********************************************************************/
/* parents and children */
/* gets the widget parent */
JWidget jwidget_get_parent(JWidget widget)
{
assert_valid_widget(widget);
return widget->parent;
}
/* get the parent window */
JWidget jwidget_get_window(JWidget widget)
{
assert_valid_widget(widget);
while (widget) {
if (widget->type == JI_WINDOW)
return widget;
@ -614,6 +715,8 @@ JWidget jwidget_get_window(JWidget widget)
JWidget jwidget_get_manager(JWidget widget)
{
assert_valid_widget(widget);
while (widget) {
if (widget->type == JI_MANAGER)
return widget;
@ -631,6 +734,8 @@ JList jwidget_get_parents(JWidget widget, bool ascendant)
{
JList list = jlist_new();
assert_valid_widget(widget);
for (; widget; widget=widget->parent) {
/* append parents in tail */
if (ascendant)
@ -646,6 +751,8 @@ JList jwidget_get_parents(JWidget widget, bool ascendant)
/* returns a list of children (you must free the list) */
JList jwidget_get_children(JWidget widget)
{
assert_valid_widget(widget);
return jlist_copy(widget->children);
}
@ -654,6 +761,8 @@ JWidget jwidget_pick(JWidget widget, int x, int y)
JWidget inside, picked = NULL;
JLink link;
assert_valid_widget(widget);
if (!(widget->flags & JI_HIDDEN) && /* is visible */
jrect_point_in(widget->rc, x, y)) { /* the point is inside the bounds */
picked = widget;
@ -672,15 +781,22 @@ JWidget jwidget_pick(JWidget widget, int x, int y)
bool jwidget_has_child(JWidget widget, JWidget child)
{
assert_valid_widget(widget);
assert_valid_widget(child);
return jlist_find(widget->children, child) != widget->children->end ? TRUE: FALSE;
}
/**********************************************************************/
/* position and geometry */
void jwidget_request_size(JWidget widget, int *w, int *h)
{
JMessage msg = jmessage_new(JM_REQSIZE);
JMessage msg;
assert_valid_widget(widget);
msg = jmessage_new(JM_REQSIZE);
jwidget_send_message(widget, msg);
*w = MID(widget->min_w, msg->reqsize.w, widget->max_w);
*h = MID(widget->min_h, msg->reqsize.h, widget->max_h);
@ -690,12 +806,16 @@ void jwidget_request_size(JWidget widget, int *w, int *h)
/* gets the position of the widget */
JRect jwidget_get_rect(JWidget widget)
{
assert_valid_widget(widget);
return jrect_new_copy(widget->rc);
}
/* gets the position for children of the widget */
JRect jwidget_get_child_rect(JWidget widget)
{
assert_valid_widget(widget);
return jrect_new(widget->rc->x1 + widget->border_width.l,
widget->rc->y1 + widget->border_width.t,
widget->rc->x2 - widget->border_width.r,
@ -706,6 +826,8 @@ JRegion jwidget_get_region(JWidget widget)
{
JRegion region;
assert_valid_widget(widget);
if ((widget->type == JI_WINDOW) && (widget->theme->get_window_mask))
region = (*widget->theme->get_window_mask)(widget);
else
@ -717,13 +839,16 @@ JRegion jwidget_get_region(JWidget widget)
/* gets the region to be able to draw in */
JRegion jwidget_get_drawable_region(JWidget widget, int flags)
{
JRegion region = jwidget_get_region (widget);
JRegion region, reg1, reg2, reg3;
JWidget window, manager, view;
JRegion reg1, reg2, reg3;
JList windows_list;
JLink link;
JRect cpos;
assert_valid_widget(widget);
region = jwidget_get_region(widget);
/* cut the top windows areas */
if (flags & JI_GDR_CUTTOPWINDOWS) {
window = jwidget_get_window(widget);
@ -830,6 +955,8 @@ JRegion jwidget_get_drawable_region(JWidget widget, int flags)
int jwidget_get_bg_color(JWidget widget)
{
assert_valid_widget(widget);
if (widget->bg_color < 0 && widget->parent)
return jwidget_get_bg_color (widget->parent);
else
@ -838,6 +965,8 @@ int jwidget_get_bg_color(JWidget widget)
JTheme jwidget_get_theme(JWidget widget)
{
assert_valid_widget(widget);
return widget->theme;
}
@ -852,7 +981,9 @@ int jwidget_get_text_length(JWidget widget)
int jwidget_get_text_height(JWidget widget)
{
return text_height (widget->text_font);
assert_valid_widget(widget);
return text_height(widget->text_font);
}
void jwidget_get_texticon_info(JWidget widget,
@ -870,6 +1001,8 @@ void jwidget_get_texticon_info(JWidget widget,
int box_x, box_y, box_w, box_h, icon_x, icon_y;
int text_x, text_y, text_w, text_h;
assert_valid_widget(widget);
text_x = text_y = 0;
/* size of the text */
@ -951,9 +1084,9 @@ void jwidget_get_texticon_info(JWidget widget,
icon_y = box_y;
}
SETRECT (box);
SETRECT (text);
SETRECT (icon);
SETRECT(box);
SETRECT(text);
SETRECT(icon);
}
void jwidget_noborders(JWidget widget)
@ -964,51 +1097,65 @@ void jwidget_noborders(JWidget widget)
widget->border_width.b = 0;
widget->child_spacing = 0;
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jwidget_set_border(JWidget widget, int l, int t, int r, int b)
{
assert_valid_widget(widget);
widget->border_width.l = l;
widget->border_width.t = t;
widget->border_width.r = r;
widget->border_width.b = b;
jwidget_dirty (widget);
jwidget_dirty(widget);
}
void jwidget_set_rect(JWidget widget, JRect rect)
{
JMessage msg = jmessage_new (JM_SETPOS);
jrect_copy (&msg->setpos.rect, rect);
jwidget_send_message (widget, msg);
jmessage_free (msg);
JMessage msg;
assert_valid_widget(widget);
msg = jmessage_new(JM_SETPOS);
jrect_copy(&msg->setpos.rect, rect);
jwidget_send_message(widget, msg);
jmessage_free(msg);
}
void jwidget_set_min_size(JWidget widget, int w, int h)
{
assert_valid_widget(widget);
widget->min_w = w;
widget->min_h = h;
}
void jwidget_set_max_size(JWidget widget, int w, int h)
{
assert_valid_widget(widget);
widget->max_w = w;
widget->max_h = h;
}
void jwidget_set_bg_color(JWidget widget, int color)
{
assert_valid_widget(widget);
widget->bg_color = color;
}
void jwidget_set_theme(JWidget widget, JTheme theme)
{
assert_valid_widget(widget);
widget->theme = theme;
/* TODO mmhhh... maybe some JStyle in JWidget should be great */
widget->text_font = widget->theme ? widget->theme->default_font: NULL;
}
/**********************************************************************/
/* drawing methods */
@ -1019,7 +1166,9 @@ void jwidget_flush_redraw(JWidget widget)
JLink link;
JRect rc;
nrects = JI_REGION_NUM_RECTS (widget->update_region);
assert_valid_widget(widget);
nrects = JI_REGION_NUM_RECTS(widget->update_region);
if (nrects > 0) {
/* get areas to draw */
JRegion region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS);
@ -1029,22 +1178,20 @@ void jwidget_flush_redraw(JWidget widget)
nrects = JI_REGION_NUM_RECTS(widget->update_region);
/* create the draw message */
msg = jmessage_new(JM_DRAW);
msg->draw.count = nrects;
jmessage_add_dest(msg, widget);
/* draw the widget */
for (c=0, rc=JI_REGION_RECTS(widget->update_region);
c<nrects;
c++, rc++) {
/* send the draw message */
msg->draw.count--;
/* create the draw message */
msg = jmessage_new(JM_DRAW);
msg->draw.count = nrects-1 - c;
msg->draw.rect = *rc;
jmessage_add_dest(msg, widget);
/* enqueue the draw message */
jmanager_enqueue_message(msg);
}
jmessage_free(msg);
jregion_empty(widget->update_region);
}
@ -1054,6 +1201,8 @@ void jwidget_flush_redraw(JWidget widget)
void jwidget_redraw_region(JWidget widget, const JRegion region)
{
assert_valid_widget(widget);
if (jwidget_is_visible(widget)) {
#if 1
JMessage msg = jmessage_new(JM_DRAWRGN);
@ -1068,6 +1217,8 @@ void jwidget_redraw_region(JWidget widget, const JRegion region)
void jwidget_invalidate(JWidget widget)
{
assert_valid_widget(widget);
if (jwidget_is_visible(widget)) {
JRegion reg1 = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS);
JLink link;
@ -1082,6 +1233,8 @@ void jwidget_invalidate(JWidget widget)
void jwidget_invalidate_rect(JWidget widget, const JRect rect)
{
assert_valid_widget(widget);
if (jwidget_is_visible(widget)) {
JRegion reg1 = jregion_new(rect, 1);
jwidget_invalidate_region(widget, reg1);
@ -1091,6 +1244,8 @@ void jwidget_invalidate_rect(JWidget widget, const JRect rect)
void jwidget_invalidate_region(JWidget widget, const JRegion region)
{
assert_valid_widget(widget);
if (jwidget_is_visible(widget) &&
jregion_rect_in(region, widget->rc) != JI_RGNOUT) {
JRegion reg1 = jregion_new(NULL, 0);
@ -1114,11 +1269,15 @@ void jwidget_invalidate_region(JWidget widget, const JRegion region)
void jwidget_scroll(JWidget widget, int dx, int dy, const JRect rect,
JRegion update_region)
{
JRegion reg1 = jwidget_get_drawable_region(widget,
JI_GDR_CUTTOPWINDOWS |
JI_GDR_USECHILDAREA);
JRegion reg2 = jregion_new(rect, 0);
JRegion reg1, reg2;
assert_valid_widget(widget);
reg1 = jwidget_get_drawable_region(widget,
JI_GDR_CUTTOPWINDOWS |
JI_GDR_USECHILDAREA);
reg2 = jregion_new(rect, 0);
jregion_intersect(reg1, reg1, reg2);
jregion_copy(reg2, reg1);
@ -1149,22 +1308,27 @@ void jwidget_scroll(JWidget widget, int dx, int dy, const JRect rect,
jregion_free(reg2);
}
/**********************************************************************/
/* signal handle */
void jwidget_signal_on(JWidget widget)
{
assert_valid_widget(widget);
widget->emit_signals--;
}
void jwidget_signal_off(JWidget widget)
{
assert_valid_widget(widget);
widget->emit_signals++;
}
int jwidget_emit_signal(JWidget widget, int signal_num)
{
assert_valid_widget(widget);
if (!widget->emit_signals) {
JMessage msg;
int ret;
@ -1192,7 +1356,7 @@ int jwidget_emit_signal(JWidget widget, int signal_num)
else
return 0;
}
/**********************************************************************/
/* manager handler */
@ -1209,6 +1373,9 @@ bool jwidget_send_message(JWidget widget, JMessage msg)
JHook hook;
JLink link;
assert_valid_widget(widget);
assert(msg != NULL);
JI_LIST_FOR_EACH(widget->hooks, link) {
hook = link->data;
SENDMSG();
@ -1224,6 +1391,9 @@ bool jwidget_send_message_after_type(JWidget widget, JMessage msg, int type)
JHook hook;
JLink link;
assert_valid_widget(widget);
assert(msg != NULL);
JI_LIST_FOR_EACH(widget->hooks, link) {
hook = link->data;
@ -1242,13 +1412,19 @@ bool jwidget_send_message_after_type(JWidget widget, JMessage msg, int type)
void jwidget_close_window(JWidget widget)
{
JWidget window = jwidget_get_window(widget);
JWidget window;
assert_valid_widget(widget);
window = jwidget_get_window(widget);
if (window)
jwindow_close(window, widget);
}
void jwidget_capture_mouse(JWidget widget)
{
assert_valid_widget(widget);
if (!jmanager_get_capture()) {
jmanager_set_capture(widget);
@ -1259,6 +1435,8 @@ void jwidget_capture_mouse(JWidget widget)
void jwidget_hard_capture_mouse(JWidget widget)
{
assert_valid_widget(widget);
if (!jmanager_get_capture()) {
jmanager_set_capture(widget);
#ifdef ALLEGRO_WINDOWS
@ -1272,6 +1450,8 @@ void jwidget_hard_capture_mouse(JWidget widget)
void jwidget_release_mouse(JWidget widget)
{
assert_valid_widget(widget);
if (jmanager_get_capture() == widget) {
jmanager_free_capture();
#ifdef ALLEGRO_WINDOWS
@ -1281,7 +1461,7 @@ void jwidget_release_mouse(JWidget widget)
widget->flags &= ~JI_HARDCAPTURE;
}
}
/**********************************************************************/
/* miscellaneous */
@ -1290,6 +1470,8 @@ JWidget jwidget_find_name(JWidget widget, const char *name)
JWidget child;
JLink link;
assert_valid_widget(widget);
JI_LIST_FOR_EACH(widget->children, link) {
child = (JWidget)link->data;
if (child->name && strcmp(child->name, name) == 0)
@ -1308,6 +1490,8 @@ bool jwidget_check_underscored(JWidget widget, int scancode)
{
int c, ascii;
assert_valid_widget(widget);
ascii = 0;
if (scancode >= KEY_0 && scancode <= KEY_9)
ascii = '0' + (scancode - KEY_0);
@ -1325,12 +1509,14 @@ bool jwidget_check_underscored(JWidget widget, int scancode)
return FALSE;
}
/**********************************************************************/
/* widget message procedure */
static bool widget_msg_proc (JWidget widget, JMessage msg)
static bool widget_msg_proc(JWidget widget, JMessage msg)
{
assert_valid_widget(widget);
switch (msg->type) {
case JM_DRAW:
@ -1368,6 +1554,7 @@ static bool widget_msg_proc (JWidget widget, JMessage msg)
JMessage msg2;
JRect rect;
JLink link;
int count;
for (it=msg->drawrgn.region->rects; it; it=it->next) {
rect = it->data;
@ -1385,20 +1572,20 @@ static bool widget_msg_proc (JWidget widget, JMessage msg)
region2 = jwidget_get_drawable_region (widget, 0);
jregion_intersect2 (region2, msg->drawrgn.region);
/* create the draw message */
msg2 = jmessage_new (JM_DRAW);
msg2->draw.count = jlist_length (region2->rects);
jmessage_add_dest (msg2, widget);
/* draw the widget */
count = jlist_length(region2->rects);
for (it=region2->rects; it; it=it->next) {
msg2->draw.count--;
/* create the draw message */
msg2 = jmessage_new(JM_DRAW);
msg2->draw.count = --count;
jrect_copy(&msg2->draw.rect, (JRect)it->data);
jmessage_add_dest(msg2, widget);
/* enqueue message */
jmanager_enqueue_message(msg2);
}
jmessage_free (msg2);
jregion_free (region2);
jregion_free(region2);
/* send message to children */
JI_LIST_FOR_EACH(widget->children, link)

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -34,6 +34,14 @@
#include "jinete/jbase.h"
#ifndef NDEBUG
#include "jinete/jintern.h"
#define assert_valid_widget(widget) assert((widget) != NULL && \
_ji_is_valid_widget((widget)))
#else
#define assert_valid_widget(widget) ((void)0)
#endif
JI_BEGIN_DECLS
struct FONT;

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -181,9 +181,9 @@ void jwindow_open(JWidget widget)
Window *window = jwidget_get_data (widget, JI_WINDOW);
if (window->is_autoremap)
jwindow_center (widget);
jwindow_center(widget);
_jmanager_open_window (ji_get_default_manager (), widget);
_jmanager_open_window(ji_get_default_manager(), widget);
}
}
@ -623,7 +623,6 @@ static void move_window(JWidget widget, JRect rect, bool use_blit)
msg = jmessage_new(JM_WINMOVE);
jmessage_broadcast_to_children(msg, widget);
jmanager_enqueue_message(msg);
jmessage_free(msg);
old_reg = jwidget_get_region (widget);
old_drawable_region = jwidget_get_drawable_region (widget, FLAGS);

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2007 David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2007 David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -753,7 +753,7 @@ static void theme_draw_listitem(JWidget widget)
bg = COLOR_FACE;
fg = COLOR_DISABLED;
}
else if (jwidget_is_selected (widget)) {
else if (jwidget_is_selected(widget)) {
bg = COLOR_SELECTED;
fg = COLOR_BACKGROUND;
}
@ -786,7 +786,7 @@ static void theme_draw_listitem(JWidget widget)
static void theme_draw_menu(JWidget widget)
{
jdraw_rectfill (widget->rc, BGCOLOR);
jdraw_rectfill(widget->rc, BGCOLOR);
}
static void theme_draw_menuitem(JWidget widget)
@ -828,7 +828,7 @@ static void theme_draw_menuitem(JWidget widget)
y2 = widget->rc->y2-1;
/* background */
rectfill (ji_screen, x1, y1, x2, y2, bg);
rectfill(ji_screen, x1, y1, x2, y2, bg);
/* draw an indicator for selected items */
if (jwidget_is_selected (widget)) {
@ -850,53 +850,53 @@ static void theme_draw_menuitem(JWidget widget)
else
widget->align = JI_LEFT | JI_MIDDLE;
pos = jwidget_get_rect (widget);
pos = jwidget_get_rect(widget);
if (!bar)
jrect_displace (pos, widget->child_spacing/2, 0);
draw_textstring (NULL, fg, bg, FALSE, widget, pos, 0);
jrect_free (pos);
jrect_displace(pos, widget->child_spacing/2, 0);
draw_textstring(NULL, fg, bg, FALSE, widget, pos, 0);
jrect_free(pos);
/* for menu-box */
if (!bar) {
/* draw the arrown (to indicate which this menu has a sub-menu) */
if (jmenuitem_get_submenu (widget)) {
if (jmenuitem_get_submenu(widget)) {
/* enabled */
if (jwidget_is_enabled (widget)) {
if (jwidget_is_enabled(widget)) {
for (c=0; c<3; c++)
vline (ji_screen,
widget->rc->x2-3-c,
(widget->rc->y1+widget->rc->y2)/2-c,
(widget->rc->y1+widget->rc->y2)/2+c, fg);
vline(ji_screen,
widget->rc->x2-3-c,
(widget->rc->y1+widget->rc->y2)/2-c,
(widget->rc->y1+widget->rc->y2)/2+c, fg);
}
/* disabled */
else {
for (c=0; c<3; c++)
vline (ji_screen,
widget->rc->x2-3-c+1,
(widget->rc->y1+widget->rc->y2)/2-c+1,
(widget->rc->y1+widget->rc->y2)/2+c+1, COLOR_BACKGROUND);
vline(ji_screen,
widget->rc->x2-3-c+1,
(widget->rc->y1+widget->rc->y2)/2-c+1,
(widget->rc->y1+widget->rc->y2)/2+c+1, COLOR_BACKGROUND);
for (c=0; c<3; c++)
vline (ji_screen,
widget->rc->x2-3-c,
(widget->rc->y1+widget->rc->y2)/2-c,
(widget->rc->y1+widget->rc->y2)/2+c, COLOR_DISABLED);
vline(ji_screen,
widget->rc->x2-3-c,
(widget->rc->y1+widget->rc->y2)/2-c,
(widget->rc->y1+widget->rc->y2)/2+c, COLOR_DISABLED);
}
}
/* draw the keyboard shortcut */
else if (jmenuitem_get_accel (widget)) {
else if (jmenuitem_get_accel(widget)) {
int old_align = widget->align;
char buf[256];
pos = jwidget_get_rect (widget);
pos = jwidget_get_rect(widget);
pos->x2 -= widget->child_spacing/4;
jaccel_to_string (jmenuitem_get_accel (widget), buf);
widget->align = JI_RIGHT | JI_MIDDLE;
draw_textstring (buf, fg, bg, FALSE, widget, pos, 0);
draw_textstring(buf, fg, bg, FALSE, widget, pos, 0);
widget->align = old_align;
jrect_free (pos);
jrect_free(pos);
}
}
}

View File

@ -1,5 +1,6 @@
/* ji - a GUI library
* Copyright (C) 2003 by David A. Capello
/* Jinete - a GUI library
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Read "LICENSE.txt" for more information.
*/

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -773,10 +774,8 @@ static bool manager_msg_proc(JWidget widget, JMessage msg)
{
switch (msg->type) {
case JM_IDLE:
case JM_QUEUEPROCESSING:
gui_feedback();
/* don't eat CPU... rest some time */
rest(0); rest(1);
break;
case JM_CHAR: {
@ -817,35 +816,7 @@ static bool manager_msg_proc(JWidget widget, JMessage msg)
}
break;
}
/* TODO remove this */
/* if (check_for_accel(ACCEL_FOR_SCREENSHOT, msg)) { */
/* screen_shot(); */
/* return TRUE; */
/* } */
/* else if (check_for_accel(ACCEL_FOR_FILMEDITOR, msg)) { */
/* if (current_sprite) { */
/* JWidget child; */
/* JLink link; */
/* bool dofilm = FALSE; */
/* JI_LIST_FOR_EACH(widget->children, link) { */
/* child = link->data; */
/* if (jwindow_is_foreground(child)) { */
/* break; */
/* } */
/* else if (jwindow_is_desktop(child) && child == app_get_top_window()) { */
/* dofilm = TRUE; */
/* break; */
/* } */
/* } */
/* if (dofilm) { */
/* switch_between_film_and_sprite_editor(); */
/* return TRUE; */
/* } */
/* } */
/* } */
}
return FALSE;

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +21,7 @@
#ifndef USE_PRECOMPILED_HEADER
#include <assert.h>
#include <allegro.h>
#include <limits.h>
#include <math.h>
@ -173,7 +175,7 @@ void refresh_tools_names(void)
void select_tool(Tool *tool)
{
ASSERT(tool != NULL);
assert(tool != NULL);
current_tool = tool;
@ -1089,7 +1091,7 @@ void control_tool(JWidget widget, Tool *tool, const char *_color)
/* spray updating process */
if (current_tool == &ase_tool_spray) {
if (ji_clock-spray_time > (JI_TICKS_PER_SEC/20)*(100-air_speed)/100) {
if (ji_clock-spray_time > (1000/20)*(100-air_speed)/100) {
spray_time = ji_clock;
forced_update = TRUE;
}

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,9 +24,9 @@
struct Image;
typedef struct Mask Mask;
struct Mask
typedef struct Mask Mask;
struct Mask
{
GfxObj gfxobj;
char *name; /* mask name */

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -63,11 +63,11 @@ int main(int argc, char *argv[])
slider5 = jslider_new(0, 255, 1);
button1 = jbutton_new("&Close");
jwidget_set_static_size(slider1, 128, 0);
jwidget_set_static_size(slider2, 128, 0);
jwidget_set_static_size(slider3, 128, 0);
jwidget_set_static_size(slider4, 128, 0);
jwidget_set_static_size(slider5, 128, 0);
jwidget_set_min_size(slider1, 128, 0);
jwidget_set_min_size(slider2, 128, 0);
jwidget_set_min_size(slider3, 128, 0);
jwidget_set_min_size(slider4, 128, 0);
jwidget_set_min_size(slider5, 128, 0);
jwidget_expansive(slider1, TRUE);
jwidget_expansive(slider2, TRUE);

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (c) 2003, 2004, 2005, 2007, 2008 David A. Capello
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -33,7 +33,7 @@
#include "jinete/jinete.h"
void do_text (const char *title, int align)
void do_text(const char *title, int align)
{
const char *LGPL_text =
"This library is free software; you can redistribute it and/or\n"
@ -53,67 +53,67 @@ void do_text (const char *title, int align)
JWidget window, box1, box2, box3, box4, label1, label2;
JWidget view1, view2, text_box1, text_box2, button;
window = jwindow_new (title);
box1 = jbox_new (JI_VERTICAL);
box2 = jbox_new (JI_HORIZONTAL | JI_HOMOGENEOUS);
box3 = jbox_new (JI_VERTICAL);
box4 = jbox_new (JI_VERTICAL);
label1 = jlabel_new ("With word-wrap");
label2 = jlabel_new ("Without word-wrap");
view1 = jview_new ();
view2 = jview_new ();
text_box1 = jtextbox_new (LGPL_text, align | JI_WORDWRAP);
text_box2 = jtextbox_new (LGPL_text, align | 0);
button = jbutton_new ("&Close");
window = jwindow_new(title);
box1 = jbox_new(JI_VERTICAL);
box2 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
box3 = jbox_new(JI_VERTICAL);
box4 = jbox_new(JI_VERTICAL);
label1 = jlabel_new("With word-wrap");
label2 = jlabel_new("Without word-wrap");
view1 = jview_new();
view2 = jview_new();
text_box1 = jtextbox_new(LGPL_text, align | JI_WORDWRAP);
text_box2 = jtextbox_new(LGPL_text, align | 0);
button = jbutton_new("&Close");
jview_attach (view1, text_box1);
jview_attach (view2, text_box2);
jview_attach(view1, text_box1);
jview_attach(view2, text_box2);
jwidget_expansive (view1, TRUE);
jwidget_expansive (view2, TRUE);
jwidget_expansive (box2, TRUE);
jwidget_expansive(view1, TRUE);
jwidget_expansive(view2, TRUE);
jwidget_expansive(box2, TRUE);
jwidget_set_static_size (view1, 64, 64);
jwidget_set_static_size (view2, 64, 64);
jwidget_set_min_size(view1, 64, 64);
jwidget_set_min_size(view2, 64, 64);
jwidget_add_child (box3, label1);
jwidget_add_child (box3, view1);
jwidget_add_child (box4, label2);
jwidget_add_child (box4, view2);
jwidget_add_child (box2, box3);
jwidget_add_child (box2, box4);
jwidget_add_child (box1, box2);
jwidget_add_child (box1, button);
jwidget_add_child (window, box1);
jwidget_add_child(box3, label1);
jwidget_add_child(box3, view1);
jwidget_add_child(box4, label2);
jwidget_add_child(box4, view2);
jwidget_add_child(box2, box3);
jwidget_add_child(box2, box4);
jwidget_add_child(box1, box2);
jwidget_add_child(box1, button);
jwidget_add_child(window, box1);
jwindow_open_bg (window);
jwindow_open_bg(window);
}
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
JWidget manager;
allegro_init ();
allegro_init();
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 200, 0, 0) < 0) {
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 ();
install_timer();
install_keyboard();
install_mouse();
manager = jmanager_new ();
ji_set_standard_theme ();
manager = jmanager_new();
ji_set_standard_theme();
do_text ("Right", JI_RIGHT);
do_text ("Center", JI_CENTER);
do_text ("Left", JI_LEFT);
do_text("Right", JI_RIGHT);
do_text("Center", JI_CENTER);
do_text("Left", JI_LEFT);
jmanager_run (manager);
jmanager_free (manager);
jmanager_run(manager);
jmanager_free(manager);
return 0;
}
END_OF_MAIN ();
END_OF_MAIN();

View File

@ -1,5 +1,5 @@
/* Jinete - a GUI library
* Copyright (c) 2003, 2004, 2005, 2007, David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 David A. Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -61,8 +61,8 @@ int main (int argc, char *argv[])
button1 = jbutton_new("&OK");
button2 = jbutton_new("&Cancel");
jwidget_add_tip(button1, "This is a tip for \"OK\" button");
jwidget_add_tip(button2, "This is a tip for the \"Cancel\" button");
jwidget_add_tip(button1, "This is the \"OK\" button");
jwidget_add_tip(button2, "This is the \"Cancel\" button");
jwidget_add_child(window, box);
jwidget_add_child(box, check1);
@ -78,7 +78,7 @@ int main (int argc, char *argv[])
}
END_OF_MAIN();
/**********************************************************************/
/* tip */
@ -91,48 +91,56 @@ static bool tip_window_hook(JWidget widget, JMessage msg);
typedef struct TipData {
int time;
char *text;
int timer_id;
} TipData;
void jwidget_add_tip(JWidget widget, const char *text)
{
TipData *tip = jnew (TipData, 1);
TipData *tip = jnew(TipData, 1);
tip->time = -1;
tip->text = jstrdup (text);
tip->text = jstrdup(text);
tip->timer_id = -1;
jwidget_add_hook (widget, tip_type (), tip_hook, tip);
jwidget_add_hook(widget, tip_type(), tip_hook, tip);
}
static int tip_type(void)
{
static int type = 0;
if (!type)
type = ji_register_widget_type ();
type = ji_register_widget_type();
return type;
}
static bool tip_hook(JWidget widget, JMessage msg)
{
TipData *tip = jwidget_get_data (widget, tip_type ());
TipData *tip = jwidget_get_data(widget, tip_type());
switch (msg->type) {
case JM_DESTROY:
jfree (tip->text);
jfree (tip);
if (tip->timer_id >= 0)
jmanager_remove_timer(tip->timer_id);
jfree(tip->text);
jfree(tip);
break;
case JM_MOUSEENTER:
tip->time = ji_clock;
if (tip->timer_id < 0)
tip->timer_id = jmanager_add_timer(widget, 1000);
jmanager_start_timer(tip->timer_id);
break;
case JM_MOUSELEAVE:
tip->time = -1;
jmanager_stop_timer(tip->timer_id);
break;
case JM_IDLE:
if (tip->time >= 0 && ji_clock-tip->time > JI_TICKS_PER_SEC) {
JWidget window = tip_window_new (tip->text);
case JM_TIMER:
if (msg->timer.timer_id == tip->timer_id) {
JWidget window = tip_window_new(tip->text);
int w = jrect_w(window->rc);
int h = jrect_h(window->rc);
jwindow_remap(window);
@ -141,9 +149,10 @@ static bool tip_hook(JWidget widget, JMessage msg)
MID(0, jmouse_y(0)-h/2, JI_SCREEN_H-h));
jwindow_open(window);
tip->time = -1;
jmanager_stop_timer(tip->timer_id);
}
break;
}
return FALSE;
}
@ -176,7 +185,7 @@ static bool tip_window_hook(JWidget widget, JMessage msg)
case JM_SIGNAL:
if (msg->signal.num == JI_SIGNAL_INIT_THEME) {
widget->border_width.l = 3;
widget->border_width.t = 3+jwidget_get_text_height (widget);
widget->border_width.t = 3+jwidget_get_text_height(widget);
widget->border_width.r = 3;
widget->border_width.b = 3;
return TRUE;
@ -189,15 +198,15 @@ static bool tip_window_hook(JWidget widget, JMessage msg)
break;
case JM_DRAW: {
JRect pos = jwidget_get_rect (widget);
JRect pos = jwidget_get_rect(widget);
jdraw_rect(pos, makecol (0, 0, 0));
jdraw_rect(pos, makecol(0, 0, 0));
jrect_shrink (pos, 1);
jdraw_rectfill (pos, makecol (255, 255, 140));
jrect_shrink(pos, 1);
jdraw_rectfill(pos, makecol(255, 255, 140));
jdraw_widget_text (widget, makecol (0, 0, 0),
makecol (255, 255, 140), FALSE);
jdraw_widget_text(widget, makecol(0, 0, 0),
makecol(255, 255, 140), FALSE);
return TRUE;
}
}

View File

@ -1,5 +1,5 @@
/* jinete - a GUI library
* Copyright (C) 2003-2005, 2007 by David A. Capello
* Copyright (C) 2003, 2004, 2005, 2007, 2008 by David A. Capello
*
* Jinete is gift-ware.
*/
@ -53,8 +53,8 @@ int main(int argc, char *argv[])
jwidget_expansive(hbox, TRUE);
jwidget_expansive(textsrc, TRUE);
jwidget_expansive(textdst, TRUE);
jwidget_set_static_size(textsrc, 600, 200);
jwidget_set_static_size(textdst, 600, 200);
jwidget_set_min_size(textsrc, 600, 200);
jwidget_set_min_size(textdst, 600, 200);
jwidget_add_child(hbox, textsrc);
jwidget_add_child(hbox, textdst);

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro.h>
#include "raster/raster.h"

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro.h>
#include "raster/image.h"

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro.h>
#include <math.h>

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro.h>
#include <math.h>
#include <stdio.h>

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +21,7 @@
#ifndef USE_PRECOMPILED_HEADER
#include <assert.h>
#include <allegro.h>
#include <stdio.h>
#include <string.h>
@ -59,7 +61,7 @@ void rec_screen_on(void)
/* || (rec_file)) */
/* return; */
ASSERT(rec_file == NULL);
assert(rec_file == NULL);
/* get a file name for the record */
for (c=0; c<10000; c++) {
@ -129,7 +131,7 @@ void rec_screen_poll(void)
{
if (!is_interactive() || !rec_file)
return;
else if (ji_clock-rec_clock > JI_TICKS_PER_SEC/FRAMES_PER_SECOND) {
else if (ji_clock-rec_clock > 1000/FRAMES_PER_SECOND) {
BITMAP *t;
int old_flag;
int c, i;

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -517,7 +518,7 @@ void editor_draw_mask_safe(JWidget widget)
if ((editor->sprite) && (editor->sprite->bound.seg)) {
int thick = editor->cursor_thick;
if (ji_clock-editor->last_clock > JI_TICKS_PER_SEC/16) {
if (ji_clock-editor->last_clock > 1000/16) {
JRegion region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS);
int c, nrects = JI_REGION_NUM_RECTS(region);
JRect rc;
@ -1033,6 +1034,7 @@ static bool editor_msg_proc (JWidget widget, JMessage msg)
}
return TRUE;
#if 0
case JM_IDLE:
if (editor->sprite)
editor_draw_mask_safe(widget);
@ -1062,6 +1064,7 @@ static bool editor_msg_proc (JWidget widget, JMessage msg)
/* if (editor->refresh_region) */
/* editor_refresh_region (widget); */
break;
#endif
case JM_MOUSEENTER:
if (jmanager_get_capture() &&

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -95,7 +96,7 @@ int editor_keys_toset_zoom(JWidget widget, int scancode)
int editor_keys_toset_frame(JWidget widget, int scancode)
{
Editor *editor = editor_data (widget);
Editor *editor = editor_data(widget);
if ((editor->sprite) &&
/* (jwidget_has_mouse (widget)) && */

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +21,9 @@
#ifndef USE_PRECOMPILED_HEADER
#include <assert.h>
#include "jinete/jmanager.h"
#include "jinete/jmessage.h"
#include "jinete/jwidget.h"
@ -33,6 +37,7 @@
typedef struct Preview
{
Effect *effect;
int timer_id;
} Preview;
static bool preview_msg_proc(JWidget widget, JMessage msg);
@ -43,6 +48,7 @@ JWidget preview_new(Effect *effect)
Preview *preview = jnew(Preview, 1);
preview->effect = effect;
preview->timer_id = -1;
jwidget_add_hook(widget, preview_type(), preview_msg_proc, preview);
jwidget_hide(widget);
@ -60,24 +66,41 @@ int preview_type(void)
void preview_restart(JWidget widget)
{
effect_begin_for_preview(preview_get_effect(widget));
Preview *preview;
assert_valid_widget(widget);
preview = jwidget_get_data(widget, preview_type());
effect_begin_for_preview(preview->effect);
if (preview->timer_id < 0)
preview->timer_id = jmanager_add_timer(widget, 1);
jmanager_start_timer(preview->timer_id);
}
Effect *preview_get_effect(JWidget widget)
{
return ((Preview *)jwidget_get_data(widget, preview_type()))->effect;
Preview *preview;
assert_valid_widget(widget);
preview = jwidget_get_data(widget, preview_type());
return preview->effect;
}
static bool preview_msg_proc(JWidget widget, JMessage msg)
{
Preview *preview = jwidget_get_data(widget, preview_type());
Effect *effect = preview_get_effect(widget);
switch (msg->type) {
case JM_DESTROY:
jfree(jwidget_get_data(widget, preview_type()));
jmanager_remove_timer(preview->timer_id);
jfree(preview);
break;
case JM_OPEN:
set_preview_image(effect->sprite->layer, effect->dst);
break;
@ -86,10 +109,12 @@ static bool preview_msg_proc(JWidget widget, JMessage msg)
set_preview_image(NULL, NULL);
break;
case JM_IDLE:
case JM_TIMER:
if (effect) {
if (effect_apply_step(effect))
effect_flush(effect);
else
jmanager_stop_timer(preview->timer_id);
}
break;
}

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -84,7 +85,6 @@ JWidget status_bar_new(void)
status_bar->widget = widget;
status_bar->timeout = 0;
status_bar->restore = FALSE;
status_bar->nprogress = 0;
/* construct the commands box */
@ -149,7 +149,7 @@ void status_bar_set_text(JWidget widget, int msecs, const char *format, ...)
jfree (widget->text);
widget->text = buf ? jstrdup (buf) : NULL;
status_bar->timeout = ji_clock + JI_TICKS_PER_SEC*msecs/1000;
status_bar->timeout = ji_clock + msecs;
jwidget_dirty(widget);
}
}
@ -325,24 +325,18 @@ static bool status_bar_msg_proc(JWidget widget, JMessage msg)
break;
case JM_MOUSELEAVE:
if (jwidget_has_child(widget, status_bar->commands_box))
status_bar->restore = TRUE;
break;
if (jwidget_has_child(widget, status_bar->commands_box)) {
/* if we want restore the state-bar and the slider doesn't have
the capture... */
if (jmanager_get_capture() != status_bar->slider) {
/* exit from command mode */
jmanager_free_focus();
case JM_IDLE: {
/* if we want restore the state-bar and the slider doesn't have
the capture... */
if (status_bar->restore &&
jmanager_get_capture() != status_bar->slider) {
/* exit from command mode */
status_bar->restore = FALSE;
jmanager_free_focus();
jwidget_remove_child(widget, status_bar->commands_box);
jwidget_dirty(widget);
jwidget_remove_child(widget, status_bar->commands_box);
jwidget_dirty(widget);
}
}
break;
}
}
return FALSE;
@ -442,7 +436,7 @@ static void update_from_layer(StatusBar *status_bar)
jwidget_disable(status_bar->slider);
}
}
/***********************************************************************
Animation Playing stuff
***********************************************************************/

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,7 +26,6 @@ typedef struct StatusBar
{
JWidget widget;
int timeout;
unsigned restore : 1; /* return from commands mode */
/* progress bar */
int nprogress;
@ -45,17 +45,17 @@ typedef struct StatusBar
JWidget b_last; /* go to last frame */
} StatusBar;
JWidget status_bar_new (void);
int status_bar_type (void);
JWidget status_bar_new(void);
int status_bar_type(void);
StatusBar *status_bar_data (JWidget status_bar);
StatusBar *status_bar_data(JWidget status_bar);
void status_bar_set_text (JWidget status_bar, int msecs, const char *format, ...);
void status_bar_set_text(JWidget status_bar, int msecs, const char *format, ...);
void status_bar_do_progress (JWidget status_bar, int progress);
void status_bar_add_progress (JWidget status_bar, int max);
void status_bar_del_progress (JWidget status_bar);
void status_bar_do_progress(JWidget status_bar, int progress);
void status_bar_add_progress(JWidget status_bar, int max);
void status_bar_del_progress(JWidget status_bar);
void status_bar_update (JWidget status_bar);
void status_bar_update(JWidget status_bar);
#endif /* WIDGETS_STATEBAR_H */

View File

@ -51,6 +51,7 @@ typedef struct Tabs
Tab *hot;
Tab *selected;
void (*select_callback)(void *data);
int timer_id;
int scroll_x;
/* int hot_arrow; */
JWidget button_left;
@ -84,6 +85,7 @@ JWidget tabs_new(void (*select_callback)(void *data))
tabs->hot = NULL;
tabs->selected = NULL;
tabs->select_callback = select_callback;
tabs->timer_id = jmanager_add_timer(widget, 1000/60);
tabs->scroll_x = 0;
/* tabs->hot_arrow = 0; */
@ -194,6 +196,8 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
jwidget_free(tabs->button_right);
jlist_free(tabs->list_of_tabs);
jmanager_remove_timer(tabs->timer_id);
jfree(tabs);
break;
}
@ -291,7 +295,7 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
return TRUE;
case JM_BUTTONPRESSED:
if (tabs->selected != tabs->hot) {
if (tabs->selected != tabs->hot && tabs->hot != NULL) {
tabs->selected = tabs->hot;
jwidget_dirty(widget);
@ -306,6 +310,15 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
return TRUE;
}
case JM_TIMER: {
/* JWidget parent = jwidget_get_parent(widget); */
/* Tabs *tabs = jwidget_get_data(parent, tabs_type()); */
/* int dir = (int)jwidget_get_data(widget, tabs_type()); */
int dir = jmanager_get_capture() == tabs->button_left ? -1: 1;
set_scroll_x(widget, tabs->scroll_x + dir*8);
break;
}
}
return FALSE;
@ -313,25 +326,34 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
static bool tabs_button_msg_proc(JWidget widget, JMessage msg)
{
JWidget parent;
Tabs *tabs;
parent = jwidget_get_parent(widget);
if (parent)
tabs = jwidget_get_data(parent, tabs_type());
switch (msg->type) {
case JM_SIGNAL:
if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT)
if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT) {
return TRUE;
}
else if (msg->signal.num == JI_SIGNAL_DISABLE) {
if (jwidget_is_selected(widget))
if (jwidget_is_selected(widget)) {
jmanager_stop_timer(tabs->timer_id);
jwidget_deselect(widget);
}
return TRUE;
}
break;
case JM_IDLE:
if (jwidget_has_capture(widget)) {
JWidget parent = jwidget_get_parent(widget);
Tabs *tabs = jwidget_get_data(parent, tabs_type());
int dir = (int) jwidget_get_data(widget, tabs_type());
set_scroll_x(parent, tabs->scroll_x + dir*8);
}
case JM_BUTTONPRESSED:
jmanager_start_timer(tabs->timer_id);
break;
case JM_BUTTONRELEASED:
jmanager_stop_timer(tabs->timer_id);
break;
}