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

📄 badctrls.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:
{
  o->icons->free_all(o->icons);
  o->count = 0;

  VIEW(o)->draw_view(VIEW(o));
};

void bad_iconbox_translate_event(p_object o, t_event *event)
{
  RETVIEW(o, event);
  view_translate_event(o, event);

  if ( o->phase == PH_PREPROCESS ) return;

  if (VIEW(o)->is_mouse_in_view(VIEW(o)))
  if ((event->type & EV_MOUSE) && ((OBJECT(mouse)->state & MO_SF_MOUSELDOWN) || (OBJECT(mouse)->state & MO_SF_MOUSELDOUBLE)))
  {
    p_bad_iconbox ib = ((p_bad_iconbox)(o));
    l_int i, idx;

    idx = -1;

    if (ib->count > 0) {
      l_int on_icon = FALSE;
      for (i=0;i<ib->count;i++) if (bad_iconbox_mouse_under_icon_at(ib, i)) {
        if (OBJECT(mouse)->state & MO_SF_MOUSELDOWN) { /* single click */
          p_bad_iconbox_item ii;
          idx = i;
          if (!(keyb->shifts & KB_CTRL_FLAG)) {
            int i;

            for (i=0;i<ib->count;i++) {
              ii = ib->icons->at(ib->icons, i);
              ii->selected = FALSE;
            };
          };
          ii = ib->icons->at(ib->icons, i);
          ii->selected = TRUE;
          ib->index = i;
          VIEW(o)->draw_view(VIEW(o));
          on_icon = TRUE;
        } else { /* double click */
          if (ib->on_dclick) ib->on_dclick(ib, i);
        };
        break;
      };

      if (!on_icon) {
        int i;
        p_bad_iconbox_item ii;
        t_point p = VIEW(o)->get_global_point(VIEW(o), point_assign(0, 0));

        ib->selection = rect_assign(mouse->where.x, mouse->where.y, mouse->where.x+5, mouse->where.y+5);
        VIEW(o)->draw_view(VIEW(o));

        for (i=0;i<ib->count;i++) {
          ii = ib->icons->at(ib->icons, i);
          ii->selected = FALSE;
        };
        do {
          if (OBJECT(mouse)->state & MO_SF_MOUSEMOVE) {
            ib->selection.b.x = mouse->where.x;
            ib->selection.b.y = mouse->where.y;
            if (ib->selection.b.x-ib->selection.a.x < 5) ib->selection.b.x = ib->selection.a.x+5;
            if (ib->selection.b.y-ib->selection.a.y < 5) ib->selection.b.y = ib->selection.a.y+5;

            for (i=0;i<ib->count;i++) {
              t_point pp = bad_iconbox_icon_position(ib, i);
              ii = ib->icons->at(ib->icons, i);
              pp.x += p.x;
              pp.y += p.y;
              ii->selected = (pp.x > ib->selection.a.x && pp.y > ib->selection.a.y && pp.x < ib->selection.b.x && pp.y < ib->selection.b.y);
            };

            VIEW(o)->draw_view(VIEW(o));
          };

          o->get_event(o, event);
        } while (OBJECT(mouse)->state & MO_SF_MOUSELPRESS);
        ib->selection = rect_assign(-1, -1, -1, -1);
        VIEW(o)->draw_view(VIEW(o));
      };
    };
    while (OBJECT(mouse)->state & MO_SF_MOUSELPRESS) o->get_event(o, event);
    clear_event(event);
  };
};

void bad_iconbox_on_scroll(p_bad_vscrollbar o, l_int newpos)
{
  if (OBJECT(o)->owner)
    VIEW(OBJECT(o)->owner)->draw_view(VIEW(OBJECT(o)->owner));
}

void bad_iconbox_change_bounds(p_view o, t_rect nr)
{
  p_bad_iconbox ib = ((p_bad_iconbox)(o));
  t_point p;
  view_change_bounds(o, nr);

  if (!ib->scr) return;
  p = bad_iconbox_icon_position(ib, ib->count);
  ib->scr->change_max(ib->scr, p.y+ib->scr->pos);
}

l_bool bad_iconbox_done(p_object o)
{
  p_bad_iconbox ib = BAD_ICONBOX(o);
  l_int i;
  if (!view_done(o)) return false;

  for (i=0;i<ib->count;i++) {
    p_bad_iconbox_item ii = ib->icons->at(ib->icons, i);
    destroy_bitmap(ii->icon);
    free(ii->caption);
  };

  dispose_list(&ib->icons, TRUE);

  return TRUE;
};

p_bad_iconbox _bad_iconbox_init(p_bad_iconbox o, t_rect r, l_big flags)
{
  if (!o) return NULL;

  clear_type(o, sizeof(t_bad_iconbox));

  view_init(&o->obclass, r);

  o->icons = list_init(malloc(sizeof(t_list)), &free, 0);
  o->caption_size = point_assign(64, 24);
  o->spacing = point_assign(43, 43);
  o->count = 0;
  o->index = -1;
  o->flags = flags;
  o->selection = rect_assign(-1, -1, -1, -1);

  o->on_dclick = NULL;
  o->add = &bad_iconbox_add;
  o->clear = &bad_iconbox_clear;

  VIEW(o)->draw = &bad_iconbox_draw;
  VIEW(o)->change_bounds = &bad_iconbox_change_bounds;
  VIEW(o)->set_palette(VIEW(o), pal_bad_common);
  VIEW(o)->brush.color = pal_bad_common[6];
  VIEW(o)->brush.color2 = pal_bad_common[6];
  VIEW(o)->brush.background = NULL;

  OBJECT(o)->translate_event = &bad_iconbox_translate_event;
  OBJECT(o)->done = &bad_iconbox_done;

  if (flags & BIB_VER_SCROLLBAR) {
    r = rect_assign(rect_sizex(r)-BAD_SCROLLBAR_WIDTH, 0, rect_sizex(r), rect_sizey(r));
    if (flags & BIB_3D_BORDER) {
      r.a.x -= 2;
      r.a.y += 2;
      r.b.x -= 2;
      r.b.y -= 2;
    };
    o->scr = bad_vscrollbar_init(malloc(sizeof(t_bad_vscrollbar)), r, 0);
    o->scr->max = 1;
    o->scr->pos = 0;
    o->scr->on_scroll = &bad_iconbox_on_scroll;
    VIEW(o->scr)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT|TX_ALIGN_FIXEDX;
    OBJECT(o)->insert(OBJECT(o), OBJECT(o->scr));
  };

  return o;
};

void bad_vscrollbar_draw(p_view o)
{
  p_bad_vscrollbar sb = BAD_VSCROLLBAR(o);
  t_rect r = o->get_local_extent(o);
  t_point p;
  BITMAP *out = o->begin_paint(VIEW(o), &p, r);

  if (out) {
    rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, o->get_color(o, 0));
    light_image ( out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, 20, 20, 20);
    if (!(sb->flags & BSB_NO_3D_BORDER))
      button(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, o->get_color(o, 2), o->get_color(o, 1));
#ifdef USE_SKIN_CODE
    if (!SKINFOR(o)) {
#endif
      rectfill(out, r.a.x+p.x+1, r.a.y+p.y+sb->bar_pos, r.b.x+p.x-1, r.a.y+p.y+sb->bar_pos+sb->delta-1, o->get_color(o, 0));

      draw_bevel(out, r.a.x+p.x, r.a.y+p.y+sb->bar_pos, r.b.x+p.x, r.a.y+p.y+sb->bar_pos+sb->delta-1, o->get_color(o, 0), o->get_color(o, 3));
      draw_bevel(out, r.a.x+p.x+1, r.a.y+p.y+sb->bar_pos+1, r.b.x+p.x-1, r.a.y+p.y+sb->bar_pos+sb->delta-2, o->get_color(o, 1), o->get_color(o, 2));
#ifdef USE_SKIN_CODE
    } else { /* skin */
      DRAW_SKIN_RECT(out, SKINFOR(o), "ScrollBar", rect_assign(r.a.x+p.x+1, r.a.y+p.y+sb->bar_pos, r.b.x+p.x-1, r.a.y+p.y+sb->bar_pos+sb->delta-1));
    };
#endif
  };

  r.b.x += 15;

  o->end_of_paint(o, r);
}

void bad_vscrollbar_change_pos(p_bad_vscrollbar o, l_int newpos)
{
  l_int old_bar_pos = o->bar_pos;
  o->pos = newpos;
  o->bar_pos = newpos*(rect_sizey(VIEW(o)->bounds)-o->delta)/lmax(o->max, 1);

  if (old_bar_pos != o->bar_pos) VIEW(o)->draw_view(VIEW(o));
}

void bad_vscrollbar_change_max(p_bad_vscrollbar o, l_int newmax)
{
  l_int old_bar_pos = o->bar_pos;
  l_int old_delta = o->delta;
  o->max = newmax;
  if (o->max <= rect_sizey(VIEW(o)->bounds))
    o->delta = rect_sizey(VIEW(o)->bounds);
  else
    o->delta = lmax(BAD_SCROLLBAR_MIN_SIZE, rect_sizey(VIEW(o)->bounds)*rect_sizey(VIEW(o)->bounds)/lmax(o->max, 1));
  o->bar_pos = o->pos*(rect_sizey(VIEW(o)->bounds)-o->delta)/lmax(o->max, 1);

  if (old_bar_pos != o->bar_pos || old_delta != o->delta) VIEW(o)->draw_view(VIEW(o));
}

void bad_vscrollbar_change_bounds(p_view o, t_rect nr)
{
  view_change_bounds(o, nr);

  if (BAD_VSCROLLBAR(o)->max <= rect_sizey(nr))
    BAD_VSCROLLBAR(o)->delta = rect_sizey(nr);
  else
    BAD_VSCROLLBAR(o)->delta = lmax(BAD_SCROLLBAR_MIN_SIZE, rect_sizey(o->bounds)*rect_sizey(nr)/lmax(BAD_VSCROLLBAR(o)->max, 1));
  BAD_VSCROLLBAR(o)->bar_pos = BAD_VSCROLLBAR(o)->pos*(rect_sizey(nr)-BAD_VSCROLLBAR(o)->delta)/lmax(BAD_VSCROLLBAR(o)->max, 1);

  VIEW(o)->draw_view(VIEW(o));
}

void bad_vscrollbar_translate_event(p_object o, t_event *event)
{
  p_bad_vscrollbar sb = BAD_VSCROLLBAR(o);
  RETVIEW(o, event);
  view_translate_event(o, event);

  if ((event->type & EV_MOUSE) && (OBJECT(mouse)->state & MO_SF_MOUSELDOWN))
  {
    t_point p = VIEW(o)->get_global_point(VIEW(o), point_assign(0, 0));
    t_rect r = VIEW(o)->get_local_extent(VIEW(o));
    l_long my = (r.b.y-r.a.y-sb->delta), sy = (mouse->where.y-p.y)-sb->bar_pos;
    l_long first_pos = sb->pos;
    l_bool in_view;

    if (mouse->where.y >= p.y+sb->bar_pos && mouse->where.y < p.y+sb->bar_pos+sb->delta && sb->max > rect_sizey(r))
    while (OBJECT(mouse)->state & MO_SF_MOUSELPRESS)
    {
      l_bool old_in_view = in_view;
      l_long old_pos = sb->pos;
      in_view = VIEW(o)->is_mouse_in_view(VIEW(o));

      sb->pos = ((mouse->where.y)-p.y-sy)*sb->max/my;
      if (sb->pos > sb->max) sb->pos = sb->max; else
      if (sb->pos < 0) sb->pos = 0;
      sb->bar_pos = sb->pos*(rect_sizey(r)-sb->delta)/lmax(sb->max, 1);

      if (sb->pos != old_pos) {
        VIEW(o)->draw_view(VIEW(o));
        if (sb->on_scroll) sb->on_scroll(sb, sb->pos);
      };

      o->get_event(o, event);
    };

    clear_event(event);
  };
}

p_bad_vscrollbar _bad_vscrollbar_init(p_bad_vscrollbar o, t_rect r, l_int flags)
{
  if (!o) return NULL;
  clear_type(o, sizeof(t_bad_vscrollbar));
  view_init(&o->obclass, r);

  o->max = 100;
  o->change = 5;

  o->delta = lmax(BAD_SCROLLBAR_MIN_SIZE, rect_sizey(r)*rect_sizey(r)/lmax(o->max, 1));
  o->bar_pos = o->pos*(rect_sizey(r)-o->delta)/lmax(o->max, 1);

  o->flags = flags;

  o->change_pos = &bad_vscrollbar_change_pos;
  o->change_max = &bad_vscrollbar_change_max;

  VIEW(o)->draw = &bad_vscrollbar_draw;
  VIEW(o)->change_bounds = &bad_vscrollbar_change_bounds;
  VIEW(o)->set_palette(VIEW(o), pal_bad_common);

  OBJECT(o)->translate_event = &bad_vscrollbar_translate_event;

  return o;
}

#include "badctrls.exp"

lib_begin(void)
{
  if (ap_process == AP_ALLOC)
  {
    AP_EXPORTLIB();
  } else
  if (ap_process == AP_INIT)
  {
    AP_SETNUMOFCALLS(1);
    dat = conv_to_skipcolor_data(DLXGetFileData(ap_id), CO_SKIP_RED, CO_SKIP_GREEN, CO_SKIP_BLUE);

    pal_bad_common[0] = registry_color("3d_face");
    pal_bad_common[1] = registry_color("3d_light");
    pal_bad_common[2] = registry_color("3d_shadow");
    pal_bad_common[3] = registry_color("3d_dark");
    pal_bad_common[4] = registry_color("3d_border");
    pal_bad_common[5] = registry_color("text");
    pal_bad_common[6] = registry_color("flat_background");
    pal_bad_common[7] = registry_color("flat_border");
    pal_bad_common[8] = registry_color("highlight");
    pal_bad_common[9] = registry_color("highlight_text");
    pal_bad_common[10] = registry_color("iconbox_text");
    pal_bad_common[11] = registry_color("filebox");
    pal_bad_common[12] = registry_color("filebox_text");
/*    pal_beditor[0] = registry_color("flat_background");
    pal_beditor[1] = registry_color("3d_light");
    pal_beditor[2] = registry_color("3d_shadow");
    pal_beditor[3] = registry_color("3d_dark");
    pal_beditor[4] = registry_color("3d_flat");
    pal_beditor[5] = registry_color("edit_text");*/
  };
} lib_end;

⌨️ 快捷键说明

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