📄 object.c
字号:
/******************************************************************
* SEAL 2.0 *
* Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved. *
* *
* Web site: http://sealsystem.sourceforge.net/ *
* E-mail (current maintainer): orudge@users.sourceforge.net *
******************************************************************/
/*
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <seal.h>
#include <object.h>
#ifndef FIFO_BUFFER_SIZE
#define FIFO_BUFFER_SIZE 512
#endif
void _afree ( void **p )
{
if ( p ) {
if(*p)_free(*p);
*p = NULL;
};
};
// time functions //////////////////////////////////////////////////////////////
/*static*/ l_big atimer = 0;
void aclock ( void )
{
atimer += 20;
};
l_big time_get_mili ( void )
{
return _time_get_mili();
};
l_big time_diff_mili ( l_big mili )
{
return _time_diff_mili(mili);
};
// first in first out //////////////////////////////////////////////////////////
static char global_buf[FIFO_BUFFER_SIZE];
l_ptr fifo_add ( l_ptr list, l_ptr src, l_int size, l_int where )
{
where = max(where, 0);
if ( size <= 0 ) return NULL;
if ( !list ) {
list = _malloc(size);
where = 0;
} else
list = _realloc(list, size*(where+1));
if ( list )
memcpy((l_ptr)((l_long)list+(where*size)), src, size);
return list;
};
l_ptr fifo_get ( l_ptr *list, l_int size, l_int where )
{
if ( !list || (size <= 0) ) return NULL;
where = max(where, 0);
if ( *list ) {
if (size>FIFO_BUFFER_SIZE ){
DEBUG_printf("fifo buffer overflowed\n");
exit(1);
}
memcpy(global_buf, (l_ptr)((l_long)(*list)+(where*size)), size);
if ( where > 0 )
*list = _realloc(*list, size*where);
else {
_free(*list);
*list = NULL;
};
return (l_ptr)(global_buf);
};
return NULL;
};
// object's function ///////////////////////////////////////////////////////////
l_bool is_my_object ( t_object *o, t_object *e )
{
if ( e ) {
if ( e == o ) return true;
else {
p_object l;
o = o->last;
l = o;
if ( o )
do {
if ( is_my_object(o, e) ) return true;
o = o->next;
} while ( o != l );
};
};
return false;
};
l_bool is_active ( t_object *e )
{
if ( e )
while ( e ) {
if ( IS_ACTIVE_PROCESS(e) &&
!e->is_options(e, OB_OF_NOTACTIVATE) ) return true;
e = e->owner;
};
return false;
};
void init_stillprocess ( p_object o, l_int milis )
{
if ( !o ) return;
if ( milis > 0 ) {
o->process_tick = milis;
o->set_options(o, OB_OF_STILLPROCESS, true);
o->put_into_stillprocess(o, o);
} else if ( o->options & OB_OF_STILLPROCESS ) {
o->process_tick = 0;
o->clear_from_stillprocess(o, o);
o->set_options(o, OB_OF_STILLPROCESS, false);
};
};
/* object functions */
l_bool obj_done ( p_object o )
{
if ( obj_exist(o) > 0 ) {
t_object *l = o->last;
t_object *x = l;
done_stillprocess(o); /* get out from list of still-processing objects */
/* it's also in obj_remove, but... */
if ( l ) /* if there is sub object */
do {
t_object *v = l->next;
dispose(o->last);
l = v;
} while ( o->last );
if ( o->owner ) {
p_object owner = o->owner;
owner->remove(owner, o);
owner->reset_prefer(owner);
};
o->tag = TAG_DISPOSE;
return true;
};
return false;
};
l_long obj_index_of ( p_object o, p_object p )
{
p_object t = o->first(o);
p_object f = t;
l_long i = 0;
if ( !t || !p ) return 0;
else
do
{
if ( t == p ) return i;
t = t->next;
i++;
} while ( t != f );
return 0;
};
p_object obj_at ( p_object o, l_long index )
{
p_object t = o->first(o);
p_object f = t;
l_long i = 0;
if ( !t || index < 0 ) return NULL;
else
do
{
if ( i == index ) return t;
i++;
t = t->next;
} while (( t != f ) && ( i <= index ));
return NULL;
};
p_object obj_find_match ( p_object o, l_dword sta, l_dword opt, l_bool forward )
{
p_object s = o;
if ( forward ) { /* forward */
do {
o = o->next;
if ( o->is_options(o, OB_OF_ENABLE) && (!sta || o->is_state(o, sta)) &&
(!opt || o->is_options(o, opt)) )
return o;
} while ( o != s );
} else /* backward */
do {
o = o->prev;
if ( o->is_options(o, OB_OF_ENABLE) && (!sta || o->is_state(o, sta)) &&
(!opt || o->is_options(o, opt)) )
return o;
} while ( o != s );
return NULL;
};
p_object obj_find_match_view ( p_object o, l_dword sta, l_dword opt, l_bool forward )
{
p_object s = o;
if ( forward ) { /* forward */
do {
o = o->next_view(o);
if ( o->is_options(o, OB_OF_ENABLE) && (!sta || o->is_state(o, sta)) &&
(!opt || o->is_options(o, opt)) )
return o;
} while ( o && o != s );
} else /* backward */
do {
o = o->prev_view(o);
if ( o->is_options(o, OB_OF_ENABLE) && (!sta || o->is_state(o, sta)) &&
(!opt || o->is_options(o, opt)) )
return o;
} while ( o && o != s );
return NULL;
};
p_object obj_call_trans_events ( p_object o, l_dword st, l_dword op )
{
};
p_object obj_owner_view ( p_object o )
{
if ( o->owner ) {
if ( o->owner->tag & TAG_VIEW ) return o->owner;
else return o->owner->owner_view(o->owner);
} else return NULL;
};
p_object obj_next_view ( p_object o )
{
t_object *t = o;
do {
t = t->next;
if ( t->tag & TAG_VIEW ) return t;
} while ( t != o );
return NULL;
};
p_object obj_prev_view ( p_object o )
{
t_object *t = o;
do {
t = t->prev;
if ( t->tag & TAG_VIEW ) return t;
} while ( t != o );
return NULL;
};
p_object obj_last_view ( p_object o )
{
if ( !o->last ) return NULL;
if ( o->last->tag & TAG_VIEW ) return o->last;
else {
t_object *p = o->last->next_view(o->last);
if ( p ) /* last view exist */
return p;
else /* sub-last view doesn't exist */
return o->last->last_view(o->last);
};
};
p_object obj_first_view ( p_object o )
{
if ( !o->first(o) ) return NULL;
if ( o->first(o)->tag & TAG_VIEW ) return o->first(o);
else {
t_object *p = o->first(o)->prev_view(o->first(o));
if ( p ) /* first view exist */
return p;
else
return o->first(o)->first_view(o->first(o));
};
};
p_object obj_prev_view_to_first ( p_object o )
{
if ( o->owner )
if ( o != o->owner->first_view(o->owner) ) return o->prev_view(o);
return NULL;
};
p_object obj_next_view_to_last ( p_object o )
{
if ( o->owner )
if ( o != o->owner->last_view(o->owner) ) return o->next_view(o);
return NULL;
};
p_object obj_prev_to_first ( p_object o )
{
if ( o->owner )
if ( o != o->owner->first(o->owner) ) return o->prev;
return NULL;
};
p_object obj_next_to_last ( p_object o )
{
if ( o->owner )
if ( o != o->owner->last ) return o->next;
return NULL;
};
void obj_setup ( p_object o )
{
if ( o->owner ) o->owner->reset_prefer(o->owner);
};
void obj_after_init ( p_object o )
{
};
l_bool obj_select ( p_object o )
{
if ( !o->is_options(o, OB_OF_ENABLE) || !o->is_state(o, OB_SF_VISIBLE) )
return false;
if ( !o->is_options(o, OB_OF_SELECTABLE) )
return false;
if ( o->is_options(o, OB_OF_TOPSELECT) && o->owner )
o->put_in_front_of(o, o->owner->first_view(o->owner));
else if ( o->owner ) o->owner->set_prefer(o->owner, o);
return true;
};
int obj_put_into_stillprocess ( p_object o, p_object s )
{
if ( o->owner ) o = o->owner;
o->put_into_stillprocess(o, s);
};
int obj_clear_from_stillprocess ( p_object o, p_object s )
{
if ( o->owner ) o = o->owner;
o->clear_from_stillprocess(o, s);
};
t_object* obj_insert ( p_object o, p_object sub )
{
if ( sub ) sub->after_init(sub);
if ( o->last && sub && sub->is_options(sub, OB_OF_TOPSELECT) )
o->insert_before(o, sub, o->first(o));
else o->insert_before(o, sub, NULL);
if ( sub ) {
if ( sub->is_options(sub, OB_OF_STILLPROCESS) ) {
init_stillprocess(sub, sub->process_tick);
};
sub->setup(sub);
};
return sub;
};
t_object* obj_insert_before ( p_object o, p_object sub, p_object before )
{
p_object t = before;
if ( !sub ) return NULL;
sub->owner = o;
if ( before )
{
before = before->prev;
sub->next = t;
before->next = sub;
t->prev = sub;
sub->prev = before;
}
else
{
if ( !o->last )
{
sub->next = sub;
sub->prev = sub;
} else
{
t = o->last->next;
sub->prev = o->last;
sub->next = t;
t->prev = sub;
o->last->next = sub;
};
o->last = sub;
};
return sub;
};
void obj_put_in_front_of ( p_object o, p_object before )
{
if ( o->owner ) {
p_object owner = o->owner;
owner->set_prefer(owner, o);
owner->remove(owner, o);
owner->insert_before(owner, o, before);
};
};
t_object* obj_first ( p_object o )
{
if ( o->last ) return o->last->next; else return NULL;
};
void obj_set_state ( p_object o, l_dword st, l_bool set )
{
if ( set ) o->state |= st;
else o->state &= ~st;
if ( st & OB_SF_FOCUSED ) { /* focus flag for sub selected object */
p_object p = o->first(o);
if ( p ) {
p = p->find_match(p, set?OB_SF_SELECTED:OB_SF_FOCUSED, 0, true);
if ( p )
p->set_state(p, OB_SF_FOCUSED, set);
};
};
};
l_bool obj_is_state ( p_object o, l_dword st )
{
return (l_bool)(o->state & st);
};
void obj_set_options ( p_object o, l_dword op, l_bool set )
{
if ( set ) o->options |= op;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -