📄 window.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 <window.h>
p_window (*win_init) ( p_window o, t_rect r, l_text caption, l_int flags ) = &_win_init;
/*
this function is used as an equivalent for "l_bool t_object.done(t_object *)" see object.h.
win_init set the t_object.done to this form : OBJECT(win)->done = &win_done;
Calls view_done function and free memory of the t_window.caption.
*/
l_bool win_done ( p_object o )
{
if ( !view_done(o) ) return false;
/* free memory of caption string and set the pointer to ZERO */
afree(&(WINDOW(o)->caption));
return true;
};
/*
an equivalent for "void t_object.set_state(t_object *, l_dword, l_dword )" see object.h.
Calls view_set_state function and redraw caption when window is selected or deselected.
*/
void win_set_state ( p_object o, l_dword st, l_bool set )
{
view_set_state(o, st, set);
if ( st & OB_SF_SELECTED ) {
/* draw title if windows is selected/deselected.
also test sub-views in the title. ! not redrawn them !
*/
TEST_SUB_VIEWS(o, WINDOW(o)->draw_title(WINDOW(o)));
view_draw_on_rect(VIEW(o),rect_assign(2, 2, rect_sizex(VIEW(o)->bounds)-2,/*FONT_GETHEIGHT(VIEW(o)->font)*/16+3));
};
};
/*
an equivalent for "t_rect t_view.size_limits(t_view * )" see view.h.
Only return area for subviews. NOTE: if variable t_view.options is set to flag
VW_OF_INGORELIM, this area is not accepted. For X button, for example.
*/
t_rect win_size_limits ( p_view o )
{
/* r = { 0, 0, width of object, height of object }*/
t_rect r = o->get_local_extent(o);
r.a.x += 2;
r.a.y += 16+4/*FONT_GETHEIGHT(VIEW(o)->font)+4*/; /* place for title */
r.b.x -= 2;
r.b.y -= 2;
return r;
};
/*
an equivalent for "t_rect t_view.size_minimum(t_view * )" see view.h.
return minimal sizes for the t_window. Default values are 220, 50. Of-course
you can change it by your own function for the object :
static t_point my_size_minumum ( p_view o ) { return point_assign(400, 300); };
VIEW(win)->size_minumum = &my_size_minimum;
*/
t_point win_size_minimum ( p_view o )
{
return point_assign(220, 50);
};
/*
an equivalent for "void t_view.draw(t_view * )" see view.h.
main drawing function of the window. The standard form of this function will find
in file view.h.
*/
void win_draw ( p_view o )
{
/* r = { 0, 0, width of object, height of object }*/
t_rect r = o->get_local_extent(o);
t_point p;
/* start to draw in rect (r) and return delta (p.x,p.y) from 0,0 of the screen
return output for the drawing ( default : t_view.draw_buffer - virtual_screen ).
When last end_of_paint is called, it's drawn to t_view.draw_out ( screen )
*/
BITMAP *out = o->begin_paint(o, &p, r);
if ( out ) {
o->background(o, out, rect_move(r, p.x, p.y));
button3d(o,out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y,0);
if ( o->drag_mode & DM_DRAGGROW ) {
l_uchar border = ( o->brush.state & BRUSH_LARGE3D ) ? 2 : 1;
line(out, p.x+r.b.x-border-2, p.y+r.b.y-border-1, p.x+r.b.x-border-1, p.y+r.b.y-border-2, color_3d_light);
line(out, p.x+r.b.x-border-3, p.y+r.b.y-border-1, p.x+r.b.x-border-1, p.y+r.b.y-border-3, color_3d_shadow);
line(out, p.x+r.b.x-border-6, p.y+r.b.y-border-1, p.x+r.b.x-border-1, p.y+r.b.y-border-6, color_3d_light);
line(out, p.x+r.b.x-border-7, p.y+r.b.y-border-1, p.x+r.b.x-border-1, p.y+r.b.y-border-7, color_3d_shadow);
line(out, p.x+r.b.x-border-10, p.y+r.b.y-border-1, p.x+r.b.x-border-1, p.y+r.b.y-border-10, color_3d_light);
line(out, p.x+r.b.x-border-11, p.y+r.b.y-border-1, p.x+r.b.x-border-1, p.y+r.b.y-border-11, color_3d_shadow);
};
/* draw title of the window */
WINDOW(o)->draw_title(WINDOW(o));
};
/* end of drawing. if this is the last call of end_of_paint, it draws context to
t_view.draw_out, from (out)... by default t_view.draw_buffer.
*/
o->end_of_paint(o, r);
};
/*
an equivalent for "void t_view.set_mouse_cursor ( t_view * )" see view.h.
If mouse cursor is placed in the left,bottom corner and the t_view.drag_mode is
set to flag DM_DRAGGROW, this set mouse cursor to CUR_GROW.
*/
void win_set_mouse_cursor ( p_view o )
{
/* make mouse->where to local bounds */
t_point m = VIEW(o)->get_local_point ( VIEW(o), mouse->where );
/* r = { 0, 0, width of the view, height of the view } */
t_rect r = VIEW(o)->get_local_extent ( VIEW(o) );
/* possible to grow, and mouse is on the left,bottom corner */
if ( o->drag_mode & DM_DRAGGROW && m.x > r.b.x - 10 && m.x < r.b.x &&
m.y > r.b.y - 10 && m.y < r.b.y )
/* set mouse cursor to CUR_GROW */
mouse_set_sys_cursor(CUR_GROW);
else
/* set mouse cursor to t_view.cursor - CUR_ARROW */
view_set_mouse_cursor(o);
};
/*
an equivalent for "void t_object.translate_event ( t_object *, t_event *)" see object.h.
this function is called, whenever some event occurs. It calls function
view_translate_event, and then are controled events for moving, closing, or
switching between views.
*/
void win_translate_event ( p_object o, t_event *event )
{
/* return back, if window is not visible or mouse is not in the object and
event comes from the mouse
*/
RETVIEW(o, event);
/* event comes from mouse - see mouse.h */
if ( event->type & EV_MOUSE ) { /* mouse event */
/* left mouse button was pressed */
if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) { /* select */
/* select window */
o->select(o); /* if it was selected before, make nothing */
};
/* left mouse button was pressed */
if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) { /* growing */
t_point m = VIEW(o)->get_local_point ( VIEW(o), mouse->where );
t_rect r = VIEW(o)->get_local_extent ( VIEW(o) );
/* check if mouse is in left, bottom corrner */
if ( m.x > r.b.x - 10 && m.x < r.b.x && m.y > r.b.y - 10 && m.y < r.b.y )
/* and if isn't maximized (if FLAG 0x08 is set then window is maximized) */
if ( !(WINDOW(o)->flags & 0x08) && VIEW(o)->drag_mode & DM_DRAGGROW ) {
l_word dm = (VIEW(o)->is_top_view(VIEW(o)) && VIEW(o)->drag_mode & DM_DRAGCONTEXT)?DM_DRAGCONTEXT:0;
/* ok, grow object */
VIEW(o)->drag_view(VIEW(o), DM_DRAGGROW+dm, event);
/* clear event, now event->type is EV_NOTHING, etc... */
clear_event(event);
};
};
};
/* calls other objects placed in the window */
view_translate_event(o, event); /* old translate_event function */
if (( event->type & EV_MOUSE) && (!(WINDOW(o)->flags & 0x08))) { /* 0x08 is WF_MAXSIZE */
/* left mouse button was pressed */
if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) { /* dragging */
t_point m = VIEW(o)->get_local_point ( VIEW(o), mouse->where );
t_rect r = VIEW(o)->get_local_extent ( VIEW(o) );
t_rect s = VIEW(o)->size_limits(VIEW(o));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -