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

📄 view.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:
      o->clip = safeclip;

    };

    OBJECT(p)->state = states[nobj];
    p = VIEW(OBJECT(p)->next_view(OBJECT(p)));
  };

  _cfree(states);
};



void  view_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 )
    o->background(o, out, rect_move(r, p.x, p.y));

  o->end_of_paint(o, r);
};


void  view_draw_me ( p_view o ) {
  l_bool dwm = o->is_draw_mode(o, DWM_TESTSUBVIEWS);
  o->set_draw_mode(o, DWM_TESTSUBVIEWS, true);
  o->draw(o);
  o->set_draw_mode(o, DWM_TESTSUBVIEWS, dwm);
};


void  view_draw_view ( p_view o ) {
  if ( OBJECT(o)->is_state(OBJECT(o), OB_SF_VISIBLE) ) {
    o->draw(o);
    o->draw_sub_views(o, VIEW(OBJECT(o)->first_view(OBJECT(o))), VIEW(OBJECT(o)->first_view(OBJECT(o))));
  };
};


void  view_draw_sub_views ( p_view o, p_view from, p_view to )
{
   p_view s = from;
   p_view f = VIEW(OBJECT(o)->first_view(OBJECT(o)));

   if ( !f ) return;

   if ( !to ) to = from;

   if ( from && OBJECT(o)->is_state(OBJECT(o), OB_SF_VISIBLE) ) {
	 l_bool old = o->is_draw_mode(o,DWM_DRAWSUBVIEW);


	 o->set_draw_mode(o,DWM_DRAWSUBVIEW,true);


     from = s;
     do {   /* draw only owner views */

       if ( rect_overlay(o->clip, from->bounds) ) {
         t_rect old = from->clip;
         from->clip = rect_cliped(o->clip,from->bounds);
         from->clip = rect_move(from->clip,-from->bounds.a.x,-from->bounds.a.y);
         from->draw(from);
         from->clip = old;
       };

       from = VIEW(OBJECT(from)->next_view(OBJECT(from)));

     } while ( from != to && from != f );

     from = s;

     do {   /* draw only sub-views */
       if ( rect_overlay(o->clip, from->bounds) ) {
	     t_rect *old = malloc(sizeof(t_rect));
	     if ( old ) {
		   memcpy(old,&from->clip,sizeof(t_rect));
		   from->clip = rect_cliped(o->clip,from->bounds);
		   from->clip = rect_move(from->clip,-from->bounds.a.x,-from->bounds.a.y);
	     };
         from->draw_sub_views(from, VIEW(OBJECT(from)->first_view(OBJECT(from))),
                                    VIEW(OBJECT(from)->first_view(OBJECT(from))));
         if ( old ) {
	       memcpy(&from->clip,old,sizeof(t_rect));
	       free(old);
         };
        };
       from = VIEW(OBJECT(from)->next_view(OBJECT(from)));

     } while ( from != to && from != f );
     o->set_draw_mode(o,DWM_DRAWSUBVIEW,old);
   };
};


void    view_draw_under_rect ( p_view o, t_rect r )
{
  p_view own = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
  if ( own && OBJECT(own)->is_state(OBJECT(own), OB_SF_VISIBLE) ) {

    p_view f = VIEW(OBJECT(o)->next_view(OBJECT(o)));

    l_dword dwm = own->is_draw_mode(own, DWM_TESTSUBVIEWS);
    t_rect  olc = own->clip;

    own->clip = r;
    own->set_draw_mode(own, DWM_TESTSUBVIEWS, true);
    own->draw(own);
    own->set_draw_mode(own, DWM_TESTSUBVIEWS, dwm);

    if ( f != VIEW(OBJECT(own)->first_view(OBJECT(own))) ) {
      own->draw_sub_views(own, o->is_draw_mode(o,OB_SF_DRAWBACK) ? VIEW(OBJECT(own)->first_view(OBJECT(own))) : f, VIEW(OBJECT(own)->first_view(OBJECT(own))));
    };


    //own->begin_paint(own, NULL, r);

    //own->end_of_paint(own, r);


    own->clip = olc;

  };
};

void   view_draw_overlays_rect ( p_view o, t_rect on ) {
  if ( OBJECT(o)->state & OB_SF_VISIBLE && !o->is_draw_mode(o,DWM_DONTDRAWBACK) ) {
    t_point p = o->get_global_point(o, point_assign(0, 0));
    l_bool xdraw = screen_double_buffer && !draw_to_2nd_buffer;
    OBJECT(o)->state &= ~OB_SF_VISIBLE;
    if ( xdraw ) {
      set_clip(screen_double_buffer,p.x+on.a.x,p.y+on.a.y,p.x+on.b.x,p.y+on.b.y);
      draw_to_2nd_buffer++;
    };
    view_draw_under_rect(o,rect_move(on,o->bounds.a.x,o->bounds.a.y));
    if ( xdraw ) {
      draw_to_2nd_buffer--;
      if ( draw_to_2nd_buffer < 0 ) draw_to_2nd_buffer=0;
      set_clip(o->draw_buffer,p.x+on.a.x,p.y+on.a.y,p.x+on.b.x,p.y+on.b.y);
      blit(screen_double_buffer,o->draw_buffer,p.x+on.a.x,p.y+on.a.y,p.x+on.a.x,p.y+on.a.y, rect_sizex(on)+1,rect_sizey(on)+1);
      set_clip(screen_double_buffer,0,0,screen_double_buffer->w-1,screen_double_buffer->h-1);
    } else {
      set_clip(o->draw_buffer,p.x+on.a.x,p.y+on.a.y,p.x+on.b.x,p.y+on.b.y);
      blit(draw_to_2nd_buffer?screen_double_buffer:OUTBUFFER(o->draw_out),o->draw_buffer,
            p.x+on.a.x,p.y+on.a.y,p.x+on.a.x,p.y+on.a.y, rect_sizex(on)+1,rect_sizey(on)+1);
    };
    OBJECT(o)->state |= OB_SF_VISIBLE;
  };
};

void    view_draw_on_rect ( p_view o, t_rect r ) {
  if ( o && OBJECT(o)->is_state(OBJECT(o), OB_SF_VISIBLE) ) {
    t_rect  olc = o->clip;
    o->clip = r;
    o->draw_sub_views(o, VIEW(OBJECT(o)->first_view(OBJECT(o))), VIEW(OBJECT(o)->first_view(OBJECT(o))));
    o->clip = olc;
  };

};

void    view_draw_under_view ( p_view o )
{
  o->draw_under_rect(o, o->bounds);
};


void    view_draw_in_rect ( p_view o, t_rect r )
{

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

};

l_bool  view_draw_mini_box ( p_view o, BITMAP *out, BITMAP *buffer, t_rect rwhere )
{
  t_view *p = o;
  l_long  rnum = 1;
  t_rect* r = NULL;
  t_rect* rout = NULL;
  t_rect  clip = o->get_cliped_extent(o);
  l_bool  isscr = is_same_bitmap(out, screen);
  if ( !rect_check_empty(clip) && OBJECT(o)->is_state(OBJECT(o), OB_SF_VISIBLE) && out ) { /* object is visible and output bitmap is set */

    t_rect* r = o->get_not_overlays ( o, rwhere, rect_move(rwhere, o->bounds.a.x, o->bounds.a.y),
                                      o, p, &rnum, &rout, o->is_draw_mode(o, DWM_TESTSUBVIEWS), false);


    if ( r ) { /* rect exist */

      t_point globe = o->get_global_point(o, point_assign(0, 0));

      while ( !rect_check_empty(*r) ) {

        t_rect d = rect_move(*r, globe.x, globe.y);
        l_int  i = 0;

        o->set_clips(o, *r);

        if ( isscr ) i = mouse->block(mouse, d);

        if ( o->trans_effect == 255 )
          blit(buffer, out, d.a.x, d.a.y, d.a.x, d.a.y, rect_sizex(d)+1, rect_sizey(d)+1);
        else {
	      if ( isscr && screen_double_buffer ) {
		    trans_blit(buffer, screen_double_buffer, d.a.x, d.a.y, d.a.x, d.a.y, rect_sizex(d)+1, rect_sizey(d)+1,o->trans_effect,255);
		    blit(screen_double_buffer,out, d.a.x, d.a.y, d.a.x, d.a.y, rect_sizex(d)+1, rect_sizey(d)+1);
	      } else
            trans_blit(buffer, out, d.a.x, d.a.y, d.a.x, d.a.y, rect_sizex(d)+1, rect_sizey(d)+1,o->trans_effect,255);
        };

        if ( isscr ) mouse->unblock(mouse, i);

        o->reset_clips(o);

        r++;
      };


      sf_free(rout);
      return true;

    };

  };

  return false;
};


l_color view_get_color ( p_view o, l_int cpos )
{
  l_color  *color = o->palette;
  if ( color ) return color[cpos];
  return 0;
};


l_bool view_is_top_view ( p_view o )
{
  p_view p = o;
  p_view t = NULL;

  while ( p ) {

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

    if ( t && OBJECT(t)->first_view(OBJECT(t)) != OBJECT(p) ) return false;

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

  return true;
};

void  view_move_accel ( p_view o, t_rect from, t_rect to )
{
  p_view p = VIEW(OBJECT(o)->owner_view(OBJECT(o)));
  t_rect clip;

  t_rect xfrom;
  t_rect xto;
  l_int  x;
  l_int  y;
  l_int  nx;
  l_int  ny;

  l_int  i = 0;

  t_rect  d;
  t_point pt;

  if ( !p ) return;

  clip = rect_cliped(p->get_cliped_extent(p), o->get_limits(o));

  xfrom = rect_cliped(from, clip);
  xto = rect_cliped(to, clip);
  x  = (from.a.x - to.a.x)+1;
  y  = (from.a.y - to.a.y)+1;
  nx = (from.a.x > to.a.x)?1:0;
  ny = (from.a.y > to.a.y)?1:0;

  xfrom = rect_move(xfrom, ((xfrom.a.x > xto.a.x) ? -x : (to.b.x - from.b.x)-nx),
                           ((xfrom.a.y > xto.a.y) ? -y : (to.b.y - from.b.y)-ny));

  p->set_clips(p, clip);

  pt = p->get_global_point(p, point_assign(0, 0));

  /* blit function */
  d = rect_assign(pt.x+to.a.x, pt.y+to.a.y, pt.x+to.b.x, pt.y+to.b.y);

  i = mouse->block(mouse, d);

  blit(OUTBUFFER(o->draw_out), OUTBUFFER(o->draw_out), pt.x+from.a.x, pt.y+from.a.y, pt.x+to.a.x, pt.y+to.a.y, rect_sizex(from)+1, rect_sizey(from)+1);

  mouse->unblock(mouse, i);

  p->reset_clips(p);

  rect_double_overlay(&xfrom, &xto);

  if ( !rect_check_empty(xfrom) ) {

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

    o->draw_in_rect(o, xfrom);

  };

  if ( !rect_check_empty(xto) ) {

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

    o->draw_in_rect(o, xto);

  };

};

void  view_move_view ( p_view o, t_rect r ) {
  t_rect safebounds = o->bounds;

  if ( !rect_equals(r, safebounds) &&
        rect_sizex(r) == rect_sizex(safebounds) &&
        rect_sizey(r) == rect_sizey(safebounds) ) {

      o->set_bounds(o, r);

      if ( !o->is_top_view(o) || !OBJECT(o)->owner_view(OBJECT(o)) ||
            o->is_draw_mode(o, DWM_CANTACCELMOVE) || o->transparent )

        o->draw_view(o);

      else

        o->move_accel(o, safebounds, r);

        o->draw_under_rect(o, safebounds);

    };
};


void  view_grow_view ( p_view o, t_rect r )
{
  p_object p = OBJECT(o)->first_view(OBJECT(o));
  p_object f = p;
  p_view own = VIEW(OBJECT(o)->owner);
  t_point pt;
  t_rect sb = o->bounds;
  t_rect ff;

  if ( screen_double_buffer ) {
    if ( !draw_to_2nd_buffer ) {
      l_int i = 0;
      pt = own->get_global_point(own, point_assign(0, 0));
      ff = rect_assign(pt.x+min(r.a.x,sb.a.x),pt.y+min(r.a.y,sb.a.y),pt.x+max(r.b.x,sb.b.x),pt.y+max(r.b.y,sb.b.y));
      set_clip(screen_double_buffer,ff.a.x,ff.a.y,ff.b.x,ff.b.y);
      i = mouse->block(mouse, ff);
      blit(screen,screen_double_buffer,ff.a.x,ff.a.y,ff.a.x,ff.a.y, rect_sizex(ff)+1,rect_sizey(ff)+1);
      mouse->unblock(mouse, i);
    };
    draw_to_2nd_buffer++;
  };

  o->set_bounds(o, r);
  o->draw(o);

  if ( p )

    do {

         p_view v = VIEW(p);
         t_rect r = v->bounds;

         l_rect dx = rect_sizex(o->bounds) - rect_sizex(sb);
         l_rect dy = rect_sizey(o->bounds) - rect_sizey(sb);

         if ( v->align & TX_ALIGN_RIGHT ) {

               if ( v->align & TX_ALIGN_FIXEDX )  r.a.x += dx;

               r.b.x += dx;

         };

         if ( v->align & TX_ALIGN_BOTTOM )  {

               if ( v->align & TX_ALIGN_FIXEDY )  r.a.y += dy;

               r.b.y += dy;
         };

         if ( !rect_equals(r, v->bounds) )

               NOT_ACCEL_MOVE(v, v->change_bounds(v, r));

         else

               v->draw_view(v);

         p = p->next_view_to_last(p);

    } while ( p );

  o->draw_under_rect(o, sb);

  if ( screen_double_buffer ) {
    draw_to_2nd_buffer--;
    if ( draw_to_2nd_buffer <= 0 ) draw_to_2nd_buffer=0;
    if ( !draw_to_2nd_buffer ) {
      l_int i = 0;
      set_clip(screen,ff.a.x,ff.a.y,ff.b.x,ff.b.y);
      i = mouse->block(mouse, ff);
      blit(screen_double_buffer,screen,ff.a.x,ff.a.y,ff.a.x,ff.a.y, rect_sizex(ff)+1,rect_sizey(ff)+1);
      mouse->unblock(mouse, i);
    };
  };
};


void    view_set_palette ( p_view o, l_int *palette )
{
  /* each object has own palette */
  #ifdef __EACH_OWN_PALETTE__
  l_int i = 1;

  if ( o->palette ) sf_free(o->palette);

  if ( palette ) {

      /* get num of colors */
      while ( CO_ISCOLOR(*pallette) ) i++;

      /* allocate mem and copy palette to destination */
      o->palette = copy_type(palette, i*sizeof(l_int));

  } else o->palette = NULL;
  #else
  /* each object has global palette */
      o->palette = palette;
  #endif
};

BITMAP* view_begin_paint ( p_view o, t_point *p, t_rect r )
{
  t_point t = point_assign(0, 0);
  l_bool  is_screen_out = o->is_draw_mode(o, DWM_ONLYTOSCREEN);
  p_view  own = VIEW(OBJECT(o)->owner_view(OBJECT(o)));

  if ( p ) *p = o->get_global_point(o, t);
  if ( OBJECT(o)->state & OB_SF_DRAWBACK ) return NULL;
  if ( !o->draw_lock &&  own && !own->is_draw_mode(own,DWM_DRAWSUBVIEW)
       && ( o->transparent || o->trans_effect != 255 ) ) {
    OBJECT(o)->state |= OB_SF_DRAWBACK;
    view_draw_overlays_rect(o,r);
    OBJECT(o)->state &= ~OB_SF_DRAWBACK;
  };

  /* fifo safe_clip => ptr to each clip */
  o->safe_clip = fifo_add_rect(o->safe_clip, &(o->clip), o->draw_lock);

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

  o->set_clips(o, r);

  o->lock_drawing(o);

  if ( is_screen_out )

     return rect_check_empty(o->get_cliped_extent(o))?NULL:OUTBUFFER(o->draw_out);

  else
         /* when we don't want to write into buffer => only for speed */
    return rect_check_empty(o->get_cliped_extent(o))?NULL:o->draw_buffer;
};


void    view_end_of_paint ( p_view o, t_rect rwhere )
{

  t_rect *t = NULL;

  if ( OBJECT(o)->state & OB_SF_DRAWBACK ) return;

  o->unlock_drawing(o);

  if ( !o->draw_lock ) { /* not locking, so i'm going to draw */

    if ( !o->is_draw_mode(o, DWM_ONLYTOBUFFER) &&
         !o->is_draw_mode(o, DWM_ONLYTOSCREEN) ) {

      o->draw_mini_box(o, (draw_to_2nd_buffer)? screen_double_buffer : OUTBUFFER(o->draw_out), o->draw_buffer, rwhere);

    };
  };

⌨️ 快捷键说明

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