⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:
  /* get old clip */
  t = fifo_get_rect(&(o->safe_clip), o->draw_lock);

  if ( t ) {

      o->clip = *t;

      o->set_clips(o, o->clip);

  };

  if ( !o->draw_lock ) /* */

      o->reset_clips(o); /* it's not important to use, but may-be...*/

};


void    view_set_clips ( p_view o, t_rect r ) {
  r = o->get_global_bounds(o, rect_cliped(r, o->get_cliped_extent(o)));

  if ( o->draw_buffer )
    set_clip(o->draw_buffer, r.a.x, r.a.y, r.b.x, r.b.y);

  if ( OUTBUFFER(o->draw_out) )
    set_clip(OUTBUFFER(o->draw_out), r.a.x, r.a.y, r.b.x, r.b.y);

};

void    view_reset_clips ( p_view o ) {
  if ( o->draw_buffer )
    set_clip(o->draw_buffer, rect_empty.a.x, rect_empty.a.y, rect_empty.b.x, rect_empty.b.y);

  if ( OUTBUFFER(o->draw_out) )
    set_clip(OUTBUFFER(o->draw_out), rect_empty.a.x, rect_empty.a.y, rect_empty.b.x, rect_empty.b.y);
};


t_rect  view_get_local_extent ( p_view o )
{
  t_rect r = rect_assign(0, 0, rect_sizex(o->bounds), rect_sizey(o->bounds));

  return r;
};


t_rect  view_get_global_bounds ( p_view o, t_rect r )
{
  while ( o ) {

    r = rect_move(r, o->bounds.a.x, o->bounds.a.y);

    o = (p_view)(((p_object)o)->owner_view((p_object)o));

  };
  return r;
};


t_rect  view_get_local_bounds ( p_view o, t_rect r )
{
  t_rect dest = o->get_local_extent(o);
  dest = o->get_global_bounds(o, dest);

  dest.a.x = r.a.x - dest.a.x;
  dest.a.y = r.a.y - dest.a.y;
  dest.b.x = dest.a.x + rect_sizex(r);
  dest.b.y = dest.a.y + rect_sizey(r);

  return dest;
};


t_point view_get_global_point ( p_view o, t_point p )
{
  t_rect  r = o->get_global_bounds(o, rect_assign(p.x, p.y, p.x, p.y));
  return r.a;
};


t_point view_get_local_point ( p_view o, t_point p )
{
  t_rect r = o->get_local_bounds(o, rect_assign(p.x, p.y, p.x, p.y));
  return r.a;
};


t_rect* view_get_not_overlays ( p_view o, t_rect rlocal, t_rect rgroup,
                                p_view p, p_view target, l_long *rnum,
                                t_rect **rout, l_bool sub, l_bool ws )
{
  t_rect box = rect_empty;
  l_bool b = false;
  l_bool s = false;
  t_rect start_box;
  t_rect safe;

  __1:

  if ( p ) p = VIEW(OBJECT(p)->prev_view_to_first(OBJECT(p)));

  __2:

  start_box = rgroup;
  safe = rgroup;

  while ( p ) {

    t_rect  r = p->bounds;

    l_dword state = OBJECT(p)->state;

    /* if p is subview & not ignore owner's limits */

    if ( ws && !OBJECT(p)->is_options(OBJECT(p), VW_OF_IGNORELIM) )

         r = rect_cliped(o->size_limits(o), r);

    if ( !(state & OB_SF_VISIBLE) ||/* !(state & OB_SF_EXPOSED) ||*/
         rgroup.b.x < r.a.x || rgroup.b.y < r.a.y ||
         rgroup.a.x > r.b.x || rgroup.a.y > r.b.y )

         p = VIEW(OBJECT(p)->prev_view_to_first(OBJECT(p)));

    else {

      box.a.x = max(r.a.x, rgroup.a.x);
      box.a.y = max(r.a.y, rgroup.a.y);
      box.b.x = min(r.b.x, rgroup.b.x);
      box.b.y = min(r.b.y, rgroup.b.y);

      break;

    };
  };

  if ( !rect_check_empty(box) ) {

    if ( box.a.y > rgroup.a.y && box.a.y <= rgroup.b.y ) {

      rgroup.b.y = box.a.y-1; safe.a.y = box.a.y;
      (*rout) = o->get_not_overlays(o, rgroup, rgroup, p, target, rnum, rout, sub, ws);
      rgroup = start_box;

    };

    if ( box.b.y < rgroup.b.y && box.b.y >= rgroup.a.y ) {

      rgroup.a.y = box.b.y+1; safe.b.y = box.b.y;
      (*rout) = o->get_not_overlays(o, rgroup, rgroup, p, target, rnum, rout, sub, ws);
      rgroup = start_box;

    };

    if ( box.a.x > rgroup.a.x && box.a.x <= rgroup.b.x ) {

      rgroup.a.y = safe.a.y; rgroup.b.y = safe.b.y;
      rgroup.b.x = box.a.x-1;
      (*rout) = o->get_not_overlays(o, rgroup, rgroup, p, target, rnum, rout, sub, ws);
      rgroup = start_box;

    };

    if ( box.b.x < rgroup.b.x && box.b.x >= rgroup.a.x ) {

      rgroup.a.x = box.b.x+1;
      rgroup.a.y = safe.a.y; rgroup.b.y = safe.b.y;
      (*rout) = o->get_not_overlays(o, rgroup, rgroup, p, target, rnum, rout, sub, ws);
      rgroup = start_box;

    };

  } else {

    if ( target ) {

      target = VIEW(OBJECT(target)->owner_view(OBJECT(target)));
      p = target;

      if ( p )
        rgroup = rect_move(rgroup, p->bounds.a.x, p->bounds.a.y);

      goto __1;

    } else if ( !sub  ) {

        (*rnum)++;

        if ( rout ) {

          (*rout) = (t_rect*)_realloc((*rout), (*rnum)*sizeof(t_rect));
          if (*rout) {

            (*rout)[(*rnum)-2] = ws?rgroup:o->get_local_bounds(o, rgroup);
            (*rout)[(*rnum)-1] = rect_empty;

          };

          return (*rout);

        } else return NULL;

      } else {

        p = VIEW(OBJECT(o)->last_view(OBJECT(o)));

        rgroup = o->get_local_bounds(o, rgroup);

        ws = true; /* to be able to know that p(s) are subviews */
        sub = false;

        goto __2; /* can't move p to prev position */

      };
  };

  return (*rout);
};


void    view_set_draw_mode ( p_view o, l_int dm, l_bool set )
{
  if ( set )
    o->draw_mode |= dm;
  else
    o->draw_mode &= ~dm;
};


l_bool  view_is_draw_mode ( p_view o, l_int dm ) {
  return (l_bool)(o->draw_mode & dm);
};

void    view_show ( p_view o ) {
  if ( !OBJECT(o)->is_state(OBJECT(o), OB_SF_VISIBLE) )

    OBJECT(o)->set_state(OBJECT(o), OB_SF_VISIBLE, true);
};

void    view_hide ( p_view o ) {
  if ( OBJECT(o)->is_state(OBJECT(o), OB_SF_VISIBLE) )

    OBJECT(o)->set_state(OBJECT(o), OB_SF_VISIBLE, false);
};

t_rect  view_get_cliped_extent ( p_view o ) {
  t_rect r = o->clip;
  p_view s = o;
  p_view x = NULL;

  while ( o ) {

    r = rect_cliped(r, o->get_local_extent(o));

    if ( !rect_check_empty(r) ) r = rect_cliped(r, o->clip);

    else return rect_empty;

    if ( !rect_check_empty(r) ) {

      r = rect_move(r, o->bounds.a.x, o->bounds.a.y);

      r = rect_cliped(r, o->get_limits(o));

    } else return rect_empty;

    if ( rect_check_empty(r) ) return rect_empty;

    o = VIEW(OBJECT(o)->owner_view(OBJECT(o)));

  };

  return s->get_local_bounds(s, r);
};

t_rect  view_size_limits ( p_view o ) {
  return o->get_local_extent(o);
};

void    view_set_bounds ( p_view o, t_rect r ) {
  t_point s = o->size_minimum(o);

  o->bounds = rect_assign(r.a.x, r.a.y, lmax(r.b.x, r.a.x+s.x), lmax(r.b.y, r.a.y+s.y));

  o->clip = o->get_local_extent(o);

};

void    view_change_bounds ( p_view o, t_rect nr ) {
  t_rect oldb = o->bounds;

  /* maybe mimimum size is yet and we make also mimimum, so try it */
  o->set_bounds(o, nr);
  nr = o->bounds;
  o->set_bounds(o, oldb);

  if ( !rect_equals(o->bounds, nr) ) {  /* old rect and new one are not same */

    if ( rect_sizex(nr) == rect_sizex(o->bounds) &&
         rect_sizey(nr) == rect_sizey(o->bounds) ) {

      o->move_view(o, nr);

    } else {

      o->grow_view(o, nr);

    };

  };
};

void    view_set_clip ( p_view o, BITMAP *out, t_rect r ) {

  r = o->get_global_bounds(o, rect_cliped(r, o->get_cliped_extent(o)));

  if ( out )

    set_clip(out, r.a.x, r.a.y, r.b.x, r.b.y);

};

void button3d ( p_view o, BITMAP *bmp, int x1, int y1, int x2, int y2, int down );

void    view_background ( p_view o, BITMAP *out, t_rect r ) {
  if ( o->transparent ) return;

  if ( o->brush.background ) {

    if ( o->brush.state & BRUSH_STRETCH )

      stretch_sprite(out, o->brush.background, r.a.x, r.a.y, rect_sizex(r)+1, rect_sizey(r)+1);

    else

    if ( o->brush.state & BRUSH_CENTER ) {

      l_rect dx = (rect_sizex(r)-IMAGE_WIDTH(o->brush.background))/2;
      l_rect dy = (rect_sizey(r)-IMAGE_HEIGHT(o->brush.background))/2;

      rectfill(out, r.a.x, r.a.y, r.b.x, r.b.y, o->brush.color);

      draw_sprite(out, o->brush.background, r.a.x+dx, r.a.y+dy);

    }
    else

      blit_ex(o->brush.background, out, 0, 0, r.a.x, r.a.y,
              IMAGE_WIDTH(o->brush.background), IMAGE_HEIGHT(o->brush.background),
              rect_sizex(r)+1, rect_sizey(r)+1);

  } else {

    if (  o->brush.color == o->brush.color2 ||
        !(o->brush.state & BRUSH_GRADIENT) )

       rectfill(out, r.a.x, r.a.y, r.b.x, r.b.y, o->brush.color);

    else

       if ( o->brush.state & BRUSH_GRADIENT_HOR )

          fade_rect(out, r.a.x, r.a.y, r.b.x, r.b.y, o->brush.color, o->brush.color2, FR_HOR);

       else

          fade_rect(out, r.a.x, r.a.y, r.b.x, r.b.y, o->brush.color, o->brush.color2, FR_VER);

  };

  if ( o->brush.state & BRUSH_DRAWBORDER ) {
	if ( rect_equals(r, o->get_global_bounds( o, o->get_local_extent(o))) )
      button3d( o, out, r.a.x, r.a.y, r.b.x, r.b.y, o->brush.state & BRUSH_DOWNBORDER );
  };

};



p_view  _view_init ( p_view o, t_rect r )
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_view));

  obj_init(&o->obclass);


  /* object's functions */

  OBJECT(o)->reset_prefer = &view_reset_prefer;
  OBJECT(o)->setup = &view_setup;
  OBJECT(o)->after_init = &view_after_init;
  OBJECT(o)->set_state = &view_set_state;
  OBJECT(o)->put_in_front_of = &view_put_in_front_of;
  OBJECT(o)->done = &view_done;
  OBJECT(o)->translate_event = &view_translate_event;

  OBJECT(o)->play_process = &view_play_process;


  /* view's functions */

  o->draw_out = &screen;
  o->draw_buffer = screen_virtual;
  o->font = font_system;
  o->cursor = CUR_ARROW;
  o->palette = NULL;
  o->draw_mode |= DWM_CANTACCELMOVE;

  o->reset_align = &view_reset_align;

  o->execute_view = &view_execute_view;
  o->get_top_view_under_mouse = &view_get_top_view_under_mouse;
  o->top_view = &view_top_view;
  o->show_info_board = &view_show_info_board;
  o->set_mouse_cursor = &view_set_mouse_cursor;
  o->is_mouse_in_view = &view_is_mouse_in_view;

  o->drag_data = &view_drag_data;
  o->drag_where = &view_drag_where;
  o->drop_data = &view_drop_data;

  o->drag_view = &view_drag_view;
  o->drag = &view_drag;
  o->size_minimum = &view_size_minimum;
  o->get_limits = &view_get_limits;

  o->draw = &view_draw;
  o->draw_me = &view_draw_me;
  o->draw_view = &view_draw_view;
  o->draw_sub_views = &view_draw_sub_views;

  o->get_color = &view_get_color;
  o->set_palette = &view_set_palette;

  o->is_top_view = &view_is_top_view;
  o->move_accel = &view_move_accel;
  o->move_view = &view_move_view;
  o->grow_view = &view_grow_view;

  o->get_view_under_mouse = &view_get_view_under_mouse;
  o->lock_drawing = &view_lock_drawing;
  o->unlock_drawing = &view_unlock_drawing;
  o->is_draw_lock = &view_is_draw_lock;

  o->begin_paint = &view_begin_paint;
  o->end_of_paint = &view_end_of_paint;

  o->draw_overlays = &view_draw_overlays;
  o->draw_mini_box = &view_draw_mini_box;

  o->draw_under_view = &view_draw_under_view;
  o->draw_under_rect = &view_draw_under_rect;
  o->draw_in_rect = &view_draw_in_rect;

  o->get_local_extent = &view_get_local_extent;

  o->get_global_bounds = &view_get_global_bounds;
  o->get_local_bounds = &view_get_local_bounds;
  o->get_global_point = &view_get_global_point;
  o->get_local_point = &view_get_local_point;

  o->get_not_overlays = &view_get_not_overlays;

  o->show = &view_show;
  o->hide = &view_hide;

  o->for_each_sub_view_set_state = &view_for_each_sub_view_set_state;
  o->set_draw_mode = &view_set_draw_mode;
  o->is_draw_mode = &view_is_draw_mode;

  o->size_limits = &view_size_limits;
  o->get_cliped_extent = &view_get_cliped_extent;

  o->set_bounds = &view_set_bounds;

  o->change_bounds = &view_change_bounds;

  o->set_clip = &view_set_clip;
  o->background = &view_background;

  o->set_clips = &view_set_clips;
  o->reset_clips = &view_reset_clips;
  o->icon_size = system_item_size;

  o->transparent = false;
  o->trans_effect = 255; // 255 = SOLID
  /* functions running & variable's declarations */

  OBJECT(o)->set_options(OBJECT(o), VW_OF_VISIBILITY+OB_OF_SELECTABLE, true);

  o->set_bounds(o, r);
  o->clip = o->get_local_extent(o);
  o->brush.color = COLOR(CO_BLACK);
  o->brush.skin = NULL;

  o->brush.state |= BRUSH_LARGE3D;

  OBJECT(o)->tag |= TAG_VIEW;

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -