📄 view.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.
*/
/* Revision History (03/04/2002):
*
* 03/04/2002: Fixed transparency problem with tips caused by making
* stattexts transparent (orudge)
*/
#include <seal.h>
#include <alltogrx.h>
#include <view.h>
#include <screen.h>
p_view (*view_init) ( p_view o, t_rect r ) = &_view_init;
/* info board */
l_int info_board_key = 0;
/* info board font = helv15 */
l_font *info_board_font = NULL;
/* able to drag all context of object */
l_bool drag_context_ok = 1;
/* enable accelaration of moving */
l_bool accel_moving_ok = 1;
l_int move_step = 0; // Unactivated
/* size of standard item (menu, listbox, ... )*/
l_int system_item_size = 16;
l_bool draw_to_2nd_buffer = false;
/* init info board from main ini file */
void info_board_init ( void )
{
info_board_key = 68;//(l_int)getininum_fromfile( INI_MAINFILE, "speed_keys", "info_board");
info_board_font = font_system;
};
void button3d ( p_view o, BITMAP *bmp, int x1, int y1, int x2, int y2, int down ) {
if (!down) {
if ( o ? o->brush.state & BRUSH_LARGE3D : 1 ) {
hline(bmp, x1, y1, x2, color_3d_light);
vline(bmp, x1, y1, y2, color_3d_light);
vline(bmp, x2-1, y1+1, y2-1, color_3d_shadow);
hline(bmp, x1+1, y2-1, x2-1, color_3d_shadow);
vline(bmp, x2, y1, y2, color_3d_dark);
hline(bmp, x1, y2, x2, color_3d_dark);
} else if ( o->brush.state & BRUSH_LIGHT3D ) {
button(bmp,x1,y1,x2,y2,color_3d_light,color_3d_shadow);
} else if ( o->brush.state & BRUSH_FLAT ) {
rect(bmp,x1,y1,x2,y2,color_flat_border);
};
} else {
if ( o ? o->brush.state & BRUSH_LARGE3D : 1 ) {
hline(bmp, x1, y1, x2, color_3d_dark);
vline(bmp, x1, y1, y2, color_3d_dark);
hline(bmp, x1+1, y1+1, x2-1, color_3d_shadow);
vline(bmp, x1+1, y1+1, y2-1, color_3d_shadow);
vline(bmp, x2-1, y1+1, y2-1, color_3d_face);
hline(bmp, x1+1, y2-1, x2-1, color_3d_face);
vline(bmp, x2, y1, y2, color_3d_light);
hline(bmp, x1, y2, x2, color_3d_light);
} else if ( o->brush.state & BRUSH_LIGHT3D ) {
button(bmp,x1,y1,x2,y2,color_3d_shadow,color_3d_light);
} else if ( o->brush.state & BRUSH_FLAT ) {
rect(bmp,x1,y1,x2,y2,color_flat_border);
};
}
}
/* init views from main ini file */
void view_ini ( void )
{
info_board_init();
//drag_context_ok = get_key_integer("current/seal/optical/move_window_context");
//accel_moving_ok = get_key_integer("current/seal/optical/enable_move_acceleration");
};
void view_reset_prefer ( p_object o )
{
p_object p = o->last_view(o);
p_object x = NULL;
if ( p ) {
x = p->find_match_view(p, OB_SF_VISIBLE, OB_OF_SELECTABLE, true);
if ( x ) o->set_prefer(o, x);
};
if ( !x ) obj_reset_prefer(o);
};
l_bool view_done ( p_object o )
{
if ( obj_exist(o) <= 0 ) return false;
VIEW(o)->hide(VIEW(o));
/* background releasing */
if ( VIEW(o)->brush.background && VIEW(o)->brush.state & BRUSH_SELFIMG ) {
destroy_bitmap(VIEW(o)->brush.background);
VIEW(o)->brush.background = NULL;
VIEW(o)->brush.state &= ~BRUSH_SELFIMG;
};
/* each object has own palette
#ifdef __EACH_OWN_PALETTE__
if ( o->palette ) afree((void**)(&o->palette));
#endif */
afree((void**)(&(VIEW(o)->info_text)));
return obj_done(o);
};
#include<stattext.h>
/*
show info board with text (text)
*/
void _show_info_board ( p_view from, l_text text ) {
p_view o;
t_point where;
t_point s;
p_stattext st;
t_rect r;
t_point p;
if ( !text || !is_top_view_under_mouse_in_me(from) ) return;
o = from->top_view(from);
where = mouse->where;
r = rect_assign(where.x, where.y, where.x, where.y);
p = o->get_global_point(o, r.a);
get_size_of_ftext(text, info_board_font, (int*)(&r.b.x), (int*)(&r.b.y));
r.a.y = r.a.y - r.b.y - 4;
r.b.x += r.a.x+4;
r.b.y += r.a.y+4;
s = point_assign(rect_sizex(r), rect_sizey(r));
if ( r.b.x > SCREEN_W ) {
r.b.x = SCREEN_W;
r.a.x = SCREEN_W-s.x;
};
if ( r.a.x < 0 ) {
r.a.x = 0;
r.b.x = s.x;
};
if ( r.b.y > SCREEN_H ) {
r.b.y = SCREEN_H;
r.a.y = SCREEN_H-s.y;
};
if ( r.a.y < 0 ) {
r.a.y = 0;
r.b.y = s.y;
};
st = stattext_init(_malloc(sizeof(t_stattext)),r,TX_ALIGN_CENTER,"%s",text);
VIEW(st)->brush.state &= ~BRUSH_LARGE3D;
VIEW(st)->brush.state |= BRUSH_DRAWBORDER|BRUSH_FLAT;
VIEW(st)->brush.color = color_flat_face;
VIEW(st)->transparent = false; // Never make this transparent
OBJECT(st)->options |= OB_OF_TOPSELECT;
st->color_text = color_flat_text;
OBJECT(desktop)->insert(OBJECT(desktop),OBJECT(st));
while ( KEYCTRL(KB_F1) || !event_main.type ) {
OBJECT(from)->get_event(OBJECT(from), &event_main);
};
dispose(OBJECT(st));
};
void view_show_info_board ( p_view from )
{
if ( from->info_text ) _show_info_board(from, from->info_text);
};
p_view view_top_view ( p_view o )
{
while ( OBJECT(o)->owner_view(OBJECT(o)) )
o = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
return o;
};
void view_set_mouse_cursor ( p_view o )
{
if ( o->cursor >= 0 ) mouse_set_cursor_focus_id(o->cursor);
};
l_bool view_is_mouse_in_view ( p_view o )
{
t_point p = o->get_local_point(o, mouse->where);
if ( p.x < 0 || p.x > rect_sizex(o->bounds) ||
p.y < 0 || p.y > rect_sizey(o->bounds) ) return false;
return true;
};
p_view view_get_view_under_mouse ( p_view o )
{
p_view x = VIEW(OBJECT(o)->first_view(OBJECT(o)));
p_view f = x;
t_point where = o->get_local_point(o, mouse->where);
if ( x )
do {
if ( OBJECT(x)->is_state(OBJECT(x), OB_SF_VISIBLE) ) /* is visible ? */
if ( rect_contains(x->bounds, where) )
return x;
x = VIEW(OBJECT(x)->next_view(OBJECT(x)));
} while ( x != f );
return NULL;
};
p_view view_get_top_view_under_mouse ( p_view o )
{
p_view x = VIEW(OBJECT(o)->first_view(OBJECT(o)));
p_view f = x;
t_point where = o->get_local_point(o, mouse->where);
if ( x )
do {
if ( OBJECT(x)->is_state(OBJECT(x), OB_SF_VISIBLE) ) /* is visible ? */
if ( rect_contains(x->bounds, where) ) {
return x->get_top_view_under_mouse(x);
};
x = VIEW(OBJECT(x)->next_view(OBJECT(x)));
} while ( x != f );
if ( rect_contains(o->get_local_extent(o), where) ) return o;
return NULL;
};
l_bool is_top_view_under_mouse_in_me ( p_view o )
{
p_view tv = VIEW(o)->top_view(VIEW(o));
p_view t = tv->get_top_view_under_mouse(tv);
return is_my_object(OBJECT(o), OBJECT(t));
};
void view_play_process ( p_object o, t_event *event )
{
if ( !o ) return;
if ( !IS_ACTIVE_PROCESS(o) || o->is_options(o, OB_OF_NOTACTIVATE) ||
EV_IGNORE_ACTIVE_PROCESS(event->type)
) {
if ( !o->is_options(o, OB_OF_STILLPROCESS) &&
event->type & EV_MOUSE &&
!is_top_view_under_mouse_in_me(VIEW(o)) ) return;
ACTIVE_PROCESS(o);
event_stop = o;
o->translate_event(o, event);
PASSIVE_PROCESS(o);
};
};
void view_translate_event ( p_object o, t_event *event )
{
if ( event->type & EV_MOUSE ) {
p_view v = VIEW(o)->get_view_under_mouse(VIEW(o));
p_view t = VIEW(o)->get_top_view_under_mouse(VIEW(o));
if ( t )
t->set_mouse_cursor(t);
if ( v && IS_OKTOSUBPROCESS(v) ) {
if ( !t ) t = v;
/* drag & drop data controls... */
if ( OBJECT(mouse)->state & MO_SF_MOUSEDRAG ) { /* drag data */
t->drag_data(t);
clear_event(event);
};
/* ...end of drag & drop data controls */
PLAY_PROCESS(OBJECT(v), event);
};
} else
obj_translate_event(o, event);
/*if ( OBJECT(keyb)->state & KB_SF_KEYDOWN && KEYCTRL(KB_F1) )
VIEW(o)->show_info_board(VIEW(o));*/
};
void view_setup ( p_object o )
{
VIEW(o)->reset_align(VIEW(o));
VIEW(o)->show(VIEW(o));
};
void view_after_init ( p_object o )
{
};
void view_put_in_front_of ( p_object o, p_object before )
{
if ( o->owner ) {
p_object owner = o->owner;
owner->set_prefer(owner, o);
if ( o != before ) {
VIEW(o)->draw_overlays(VIEW(o));
owner->remove(owner, o);
owner->insert_before(owner, o, before);
owner->reset_prefer(owner);
};
};
};
void view_set_state ( p_object o, l_dword st, l_bool set )
{
p_view own = VIEW(o->owner_view(o));
if ( !(st & OB_SF_VISIBLE) || !set || o->is_options(o, VW_OF_VISIBILITY) )
obj_set_state(o, st, set); /* object function */
/* OB_SF_VISIBLE */
if ( st & OB_SF_VISIBLE &&
(!own || OBJECT(own)->is_state(OBJECT(own), OB_SF_VISIBLE)) )
{
if ( o->owner && o->is_options(o, OB_OF_SELECTABLE) )
if ( set ) {
if ( !o->owner->prefer || o->is_options(o, OB_OF_TOPSELECT) )
o->owner->reset_prefer(o->owner);
} else if ( o->is_state(o, OB_SF_SELECTED) ) o->owner->reset_prefer(o->owner);
if ( set ) {
l_bool old = VIEW(o)->is_draw_mode(VIEW(o),DWM_DONTDRAWBACK);
VIEW(o)->set_draw_mode(VIEW(o),DWM_DONTDRAWBACK,true);
VIEW(o)->draw_view(VIEW(o));
VIEW(o)->set_draw_mode(VIEW(o),DWM_DONTDRAWBACK,old);
} else
VIEW(o)->draw_under_view(VIEW(o));
};
if ( st & OB_SF_VISIBLE )
VIEW(o)->for_each_sub_view_set_state(VIEW(o), OB_SF_VISIBLE, set);
};
void view_reset_align ( p_view o )
{
t_rect r = o->bounds;
p_view ov = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
if ( ov ) {
t_rect s = ov->get_limits(ov);
if ( o->align & TX_ALIGN_CENTERX )
r.a.x = s.a.x+(rect_sizex(s)-rect_sizex(r))/2;
if ( o->align & TX_ALIGN_CENTERY )
r.a.y = s.a.y+(rect_sizey(s)-rect_sizey(r))/2;
if ( o->align & TX_ALIGN_LEFT )
r.a.x = s.a.x;
if ( o->align & TX_ALIGN_TOP )
r.a.y = s.a.y;
r.b.x = r.a.x+rect_sizex(o->bounds);
r.b.y = r.a.y+rect_sizey(o->bounds);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -