engine.c
来自「SEAL是DOS 下的32位保护模式的GUI程序」· C语言 代码 · 共 979 行 · 第 1/2 页
C
979 行
save_image(file,scr,NULL);
_free(file);
scr_shots++;
};
destroy_bitmap(scr);
};
};
l_bool fast_system = true;
////////////////////////////////////////////////////////////////////////////////
p_list get_loaded_xdl ( void ) {
p_list p = list_init(_malloc(sizeof(t_list)), &free_listbox_item, 0);
if ( p ) {
if ( listapp && listapp->last ) {
p_item x = listapp->first(listapp);
p_item f = x;
if ( f )
do {
p_app o = ((p_app)(x->rec));
p->insert(p, new_listbox_item(set_format_text(NULL,"%s (%s)",o->appname,o->filename), NULL, 0, NULL));
x = x->next;
} while ( x != f );
};
};
return p;
};
#define MSG_END_OF_TASK 9999 // ;) no possible bugs : 9/9/99 is passed !!!
p_listbox XDL_LISTBOX = NULL;
////////////////////////////////////////////////////////////////////////////////
void xdl_man_trans_ev ( p_object o, p_event event ) {
if ( event->type & EV_MESSAGE ) {
l_dword msg = event->message;
if ( msg == MSG_END_OF_TASK ) {
l_int nb = XDL_LISTBOX->current;
p_item it;
p_app xo;
hdlx_t id;
it = listapp->at_item(listapp,nb);
xo = ((p_app)(it->rec));
memcpy(&id,&xo->id,sizeof(hdlx_t));
DLXUnload(id);
clear_event(event);
set_event(event, EV_MESSAGE, MSG_CLOSE, o);
o->put_event(o, event);
clear_event(event);
};
};
};
////////////////////////////////////////////////////////////////////////////////
void fast_trans_ev ( p_object o, p_event event ) {
if ( event->type == EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN && KEYCTRL(KB_F8) ) {
fast_scr_shot ( );
clear_event(event);
};
if ( event->type == EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN && KEYCTRL(KEY_F12) ) {
p_appwin win;
p_listbox lst;
p_button b;
p_stattext txt;
t_rect r = rect_assign(0,0,320,270);
clear_event(event);
win = appwin_init( _malloc(sizeof(t_appwin)),
r,
"XDL Task Manager",
WF_MINIMIZE,
NULL,
&xdl_man_trans_ev);
if ( !win ) return;
VIEW(win)->align |= TX_ALIGN_CENTER;
lst = listbox_init( _malloc(sizeof(t_listbox)),rect_assign(5,20,r.b.x-20,r.b.y-50),
get_loaded_xdl(),1,LF_SELFLIST);
XDL_LISTBOX = lst;
OBJECT(win)->insert(OBJECT(win),OBJECT(lst));
txt = stattext_init( _malloc(sizeof(t_stattext)),rect_assign(5,r.b.y-45,r.b.x-5,r.b.y-30),
TX_ALIGN_CENTER, "Warning: Some programs are needed by others!");
OBJECT(win)->insert(OBJECT(win), OBJECT(txt));
b = button_init(_malloc(sizeof(t_button)),
rect_assign(5,r.b.y-25,(r.b.x/2)-5,r.b.y-5),
"End Task",
MSG_END_OF_TASK,
BF_DEFAULT);
OBJECT(win)->insert(OBJECT(win), OBJECT(b));
b = button_init(_malloc(sizeof(t_button)),
rect_assign((r.b.x/2)+5,r.b.y-25,r.b.x-5,r.b.y-5),
"(x) Close",
MSG_CLOSE,
BF_DEFAULT);
OBJECT(win)->insert(OBJECT(win), OBJECT(b));
OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(win));
};
};
////////////////////////////////////////////////////////////////////////////////
/* main translate event function */
void program_translate_event ( t_object *o, t_event *event )
{
/* save the last time of calling */
event_timer = time_get_mili();
/* event type is message */
if ( event->type == EV_MESSAGE ) {
/* event message is MSG_QUIT */
if ( event->message == MSG_QUIT ) {
clear_event(event);
/* set end_state of program to MSG_QUIT
this is used in function obj_execute
*/
o->end_state = MSG_QUIT;
};
if ( event->message == MSG_FST_SCR_SHOT ) {
clear_event(event);
fast_scr_shot ( );
};
};
/* call each object in program hierarchy */
obj_translate_event(o, event);
if ( event->type == EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN
&& KEYPRESSED( KB_PRTSCR ) ) {
fast_scr_shot ( );
clear_event(event);
};
/* if keyboard was pressed and the keycode of the key is ALT+X */
if ( event->type == EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN
&& KEYPRESSED(TO_ALT(KB_TAB)) ) {
clear_event(event);
/* set event by these arguments */
set_event(event, EV_MESSAGE, MSG_QUIT, o);
/* put event to a queue */
o->put_event(o, event);
clear_event(event);
};
/* if keyboard was pressed and the keycode of the key is ALT+D */
if ( event->type == EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN
&& KEYPRESSED(TO_ALT(KB_D)) ) {
p_object v = NULL;
/* find the selected object in the desktop */
if ( OBJECT(desktop)->prefer )
/* search for the next visible, selectable, enable object in the desktop */
v = OBJECT(desktop)->prefer->find_match_view(OBJECT(desktop)->prefer, OB_SF_VISIBLE, OB_OF_SELECTABLE+OB_OF_ENABLE, false);
clear_event(event);
/* if found some, select it */
if ( v ) v->select(v);
};
};
////////////////////////////////////////////////////////////////////////////////
/*
done program
return true, if succesfull, otherwise false
*/
l_bool program_done ( p_object o ) {
DEBUG_printf("Done program...\n");
if ( !obj_done(o) ) return false;
DEBUG_printf("Done stillprocess...\n");
stillprocess_list.done(&stillprocess_list);
drv_done(); /* done drives */
DEBUG_printf("Done filter...\n");
filter_remove_all(); /* remove all filters from the array */
registry_done();
DEBUG_printf("Done program : FINISHED\n");
return true;
};
////////////////////////////////////////////////////////////////////////////////
void desktop_draw ( p_view o ) {
t_rect r = o->get_local_extent(o);
t_point p;
BITMAP *out = o->begin_paint(o, &p, r);
if ( out ) {
// l_text capt = set_format_text(NULL,"%s %s - Testing purposes only", SealApi,SealApiTxtVersion);
o->background(o, out, rect_move(r, p.x, p.y));
/* draw_double_text(out, o->font, capt, -1,
r.a.x+p.x, r.a.y+p.y, r.b.x+p.x-120, r.b.y+p.y-50,
TX_ALIGN_RIGHT|TX_ALIGN_BOTTOM,
color_desktop_text, color_flat_face, 0);
_free(capt);*/
};
o->end_of_paint(o, r);
};
////////////////////////////////////////////////////////////////////////////////
t_object *program_init ( p_object o ) {
char *OS = "????";
if ( !o ) return NULL;
seal_error = &txt_seal_error;
DEBUG_printf(" - Initializing %s %s\n",SealApi,SealApiTxtVersion);
DEBUG_printf("\n");
obj_init(o);
DEBUG_printf("\n - Start registry.\n");
registry_init();
DEBUG_printf("\n - Install Allegro.\n");
install_allegro( SYSTEM_AUTODETECT, NULL, NULL );
set_uformat(U_ASCII);
check_cpu();
DEBUG_printf(" System informations :\n");
DEBUG_printf(" CPU\n");
DEBUG_printf(" vendor : %s\n",&cpu_vendor);
DEBUG_printf(" family : %d Model : %d\n",cpu_family,cpu_model);
DEBUG_printf(" fpu : %d mmx : %d 3dnow :%d\n",cpu_fpu,cpu_mmx,cpu_3dnow);
OS[0] = os_type>>24;
OS[1] = os_type>>16;
OS[2] = os_type>>8;
OS[3] = os_type;
DEBUG_printf(" OS\n");
DEBUG_printf(" name : %s\n",OS);
DEBUG_printf(" version : %d revision : %d\n",os_version,os_revision);
DEBUG_printf("\n - Initialise drivers.\n");
drv_init();
if ( get_depth(screen) < 16 )
translucide = 0;
else
translucide = get_key_integer("current/seal/optical/translucide");
view_ini();
clear_event(&event_panding);
list_init(&stillprocess_list, NULL, 0);
o->get_event = &program_get_event;
o->put_event = &program_put_event;
o->done = &program_done;
o->translate_event = &program_translate_event;
o->put_into_stillprocess = &program_put_into_stillprocess;
o->clear_from_stillprocess = &program_clear_from_stillprocess;
o->set_state(o, OB_SF_FOCUSED, true);
o->set_options(o, OB_OF_TOPSELECT+OB_OF_NOTACTIVATE, true);
if ( !desktop ) {/* install desktop */
desktop = view_init(_malloc(sizeof(t_view)), rect_assign(0, 0, screen_width-1, screen_height-1));
desktop->draw = &desktop_draw;
};
standard_menuitem_font = get_font_in_size("Arial", 8, 8);
appsys_init();
iodlg_init ();
if ( fast_system ) {
p_object fast = obj_init(_malloc(sizeof(t_object)));
fast->translate_event = &fast_trans_ev;
OBJECT(drivers)->insert(OBJECT(drivers), fast);
};
if ( screen_double_buffer )
draw_to_2nd_buffer=1;
if ( desktop ) {
l_text fname = get_key("current/desktop/wallpaper");
l_int style = get_key_integer("current/desktop/placement");
desktop->brush.color = color_desktop_face;
if ( fname ) {
desktop->brush.background = load_image(GetFile(fname));
if ( desktop->brush.background ) {
desktop->brush.state |= BRUSH_SELFIMG;
if ( style == 1 )
desktop->brush.state |= BRUSH_STRETCH;
else
if ( style == 2 )
desktop->brush.state |= BRUSH_CENTER;
};
_free(fname);
};
o->insert(o, OBJECT(desktop));
};
tips_system_init(); // By Pablo Borobia !
OBJECT(desktop)->insert(OBJECT(desktop), screensaver_init(_malloc(sizeof(t_object))) );
RunAllRegistryEntries("system/startup/load",NULL);
if ( screen_double_buffer && draw_to_2nd_buffer ) {
draw_to_2nd_buffer = 0;
set_clip(screen,0,0,screen_width,screen_height);
if ( translucide > 0 ) {
BITMAP *buffer = create_bitmap(screen_width,screen_height);
l_int i = 0;
blit(screen, buffer, 0, 0, 0, 0, screen_width, screen_height);
for (i=0; i<160; i+=10) {
set_trans_blender(0, 0, 0, i);
draw_trans_sprite(buffer, screen_double_buffer, 0, 0);
blit(buffer, screen, 0, 0, 0, 0, screen_width, screen_height);
};
destroy_bitmap(buffer);
solid_mode();
};
blit(screen_double_buffer, screen, 0, 0, 0, 0, screen_width, screen_height);
};
DEBUG_printf(" - Initialisation finished.\n");
mouse->show(mouse);
return o;
};
////////////////////////////////////////////////////////////////////////////////
/*
call each object's func_callback, that is placed in stillprocess list.
*/
void program_call_each_stillprocess ( p_list o ) {
if ( o ) {
p_item v = o->first(o); /* find first object */
p_item f = v;
if ( v )
do {
if ( v->rec &&
/* difference between last calling and current is GE to process_tick of object */
time_diff_mili(OBJECT(v->rec)->process_time) >= OBJECT(v->rec)->process_tick ) {
/* set current time */
OBJECT(v->rec)->process_time = time_get_mili();
/* call function of the object */
OBJECT(v->rec)->func_callback(OBJECT(v->rec));
};
v = v->next;
} while ( v != f );
};
};
////////////////////////////////////////////////////////////////////////////////
static void aclock2 ( void ) {
if ( !mouse->is_block(mouse) )
if ( _time_diff_mili(event_oldtimer) >= 500 )
mouse_set_sys_cursor(CUR_CLOCK);
else if ( mouse->get_cursor(mouse) == system_cursors[CUR_CLOCK] )
mouse_set_sys_cursor(CUR_ARROW);
};
////////////////////////////////////////////////////////////////////////////////
int program_int ( void ) {
/* if not pause in multitasking */
if ( go_process ) {
/* difference is greater then task_tick */
if ( _time_diff_mili(event_timer) >= task_tick ) {
/* get current time */
event_timer = time_get_mili();
/* get events */
program.get_event(&program, &event_main);
program.translate_event(&program, &event_main);
};
};
return 1;
};
////////////////////////////////////////////////////////////////////////////////
main ( int argc, char **argv ) {
printf("%s %s Starting ...\n\n\n",SealApi,SealApiTxtVersion);
if ( argc > 1 && argv[1] && !stricmp(argv[1], "-safe") ) // If arg '-safe' is set
safe_mode = 1; // Set Safe Mode
seal_debug_file = _fopen("seal.dbg", "wt"); // Open debug file
ini_vfile ( ) ; // Start Virtual File System
program_init(&program); // Init program
program.execute(&program); // Execute program
program.done(&program); // Close program
fclose(seal_debug_file); // Close Debug File
return 0; // Errorlevel 0 : no error
};
////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?