Exemplo n.º 1
0
int
test_3_bitvec(void)
{
  Bitvec a;
  size_t n = 128;
  bitvec_initZ(&a, n);
  for (size_t i = 0; i < n; i++) {
    if (bitvec_get(&a, i) != 0) { PWARN("Failed for a[i:%zd] != 0\n", i); }
    bitvec_set1(&a, i);
    if (bitvec_get(&a, i) != 1) { PWARN("Failed for a[i:%zd] != 1\n", i); }
  }
  bitvec_print(&a); printf("\n");
  return 0;
}
Exemplo n.º 2
0
static error draw_walk(treeview_t     *tr,
                       int             depth,
                       int             x,
                       int             y,
                       ntree_t        *t,
                       connector_flags flags,
                       int             index,
                       txtfmt_t       *tx,
                       int             height,
                       void           *opaque)
{
  error               err;
  treeview_draw_data *draw = opaque;
  int                 line_height;
  wimp_colour         bgcolour;
  int                 x0;

  /* plot initial connectors */

  err = draw_connectors(tr, t, draw, depth, x, y, flags, index);
  if (err)
    goto Failure;

  line_height = tr->line_height;

  if (bitvec_get(tr->multiline, index))
  {
    int i;
    int hy;

    /* plot remainder of connectors */

    for (i = 0; i < depth + 1; i++)
      if (draw->stack & (1u << i))
        for (hy = y - 1 * line_height;
             hy != y - height * line_height;
             hy -= line_height)
          plot_connector(VBAR, x + i * line_height, hy, line_height);
  }

  /* select background colour */

  bgcolour = ntree_first_child(t) ? wimp_COLOUR_TRANSPARENT :
                                    tr->bgcolour;

  /* plot text */

  x0 = x + (depth + 1) * line_height;
  err = txtfmt_paint(tx, x0, y, bgcolour);
  if (err)
    goto Failure;

  return error_OK;


Failure:

  return err;
}
Exemplo n.º 3
0
static error map(filerwin     *fw,
                 mapfn        *fn,
                 int           x,
                 int           y,
                 const os_box *test,
                 void         *opaque)
{
  error err;
  int   c;
  int   yr;
  int   yy;

  c = 0;

  yr = y;

  for (yy = 0; yy < fw->rows; yy++)
  {
    int xr;
    int xx;

    xr = x + fw->hpad;
    yr = yr - fw->vpad - fw->object_height;

    for (xx = 0; xx < fw->columns; xx++)
    {
      os_box box;

      if (c >= fw->nobjects)
        break;

      box.x0 = xr;
      box.y0 = yr;
      box.x1 = box.x0 + fw->object_width;
      box.y1 = box.y0 + fw->object_height;

      if (!test || (test && box_intersects(&box, test)))
      {
        err = fn(fw, xr, yr, c, bitvec_get(fw->selection, c), opaque);
        if (err)
          return err;
      }

      xr += fw->object_width + fw->hpad;

      c++;
    }
  }

  return error_OK;
}
Exemplo n.º 4
0
void
x11_btv2d(const XDpy * dpy, XAnim * anim,
	int x, int y, uint w, uint h, Bitvec * btv)
{
  uint i, j;
  if (w * h != btv->l) {
    leprintf("Dimension mismatch.\n");
    return;
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      x11_setFG(dpy, &anim->win, bitvec_get(btv, i * w + j) ?
	      COLOR_WHITE : COLOR_BLACK);
      x11_dPnt(dpy, anim, x + j, y + i);
    }
  }
}
Exemplo n.º 5
0
error treeview_click(treeview_t *tr, int x, int y, int *redraw_y)
{
  error               err;
  treeview_click_data click;

  click.x = x;
  click.y = y;

  err = treeview_walk(tr, click_walk, &click);

  if (err == error_TREEVIEW_FOUND) /* found it */
  {
    /* tr->walk.y, tr->walk.index updated */

    /* the user may have clicked in the position of a collapse control,
     * even if one was not present, so check */

    if (bitvec_get(tr->openable, tr->walk.index))
    {
      bitvec_toggle(tr->open, tr->walk.index);

      *redraw_y = tr->walk.y;
    }
    else
    {
      *redraw_y = +1; /* no update */
    }

    err = error_OK;
  }
  else if (err == error_OK)
  {
    *redraw_y = +1; /* no update */
  }

  return err;
}
Exemplo n.º 6
0
static error treeview_walk_node(ntree_t *t, void *opaque)
{
  error            err;
  treeview_t      *tr = opaque;
  int              x,y;
  connector_flags  flags;
  int              stop = 0;
  int              depth;
  txtfmt_t        *tx;
  int              height;

  x = tr->walk.x;
  y = tr->walk.y - tr->line_height;

  tr->walk.index++; /* index of node (0..N-1) */

  /* retrieve the flags from bitvecs */

  flags = 0;

  if (bitvec_get(tr->openable, tr->walk.index))
  {
    flags |= OPENABLE;
    if (bitvec_get(tr->open, tr->walk.index))
      flags |= OPEN;
  }

  /* if 'next' is set then skip nodes until we hit the one we want */

  if (tr->walk.next)
  {
    if (tr->walk.next != t)
      return error_OK; /* skip */

    tr->walk.next = NULL; /* stop skipping */
  }

  /* skip nodes whose parent is collapsed */

  if ((flags & OPENABLE) && (flags & OPEN) == 0)
  {
    ntree_t *next;

    /* we want to process /this/ node and then skip all intermediate ones
     * until the next sibling (if any) */

    next = ntree_next_sibling(t);

    /* if there's no next sibling, then we need to look further up/ahead in
     * the tree */

    if (next == NULL)
    {
      ntree_t *cur;
      ntree_t *par;

      for (cur = t; ; cur = par)
      {
        /* fetch the parent (which we've already seen) */

        par = ntree_parent(cur);
        if (par == NULL)
        {
          stop = 1;
          break; /* no parent? must be at the root, so give up */
        }

        next = ntree_next_sibling(par);
        if (next)
          break;
      }
    }

    tr->walk.next = next;
  }

  /* it might be cheaper for ntree_walk to pass the depth into us than to
   * have to find it ourselves here */

  depth = ntree_depth(t) - 1;

#if SKIP_ROOT
  if (depth == 0)
    return error_OK;

  depth--;
#endif

  tx = ntree_get_data(t);

  /* need to know how high the text will be */

  height = txtfmt_get_height(tx);

  /* call the callback */

  if (tr->walk.cb)
  {
    err = tr->walk.cb(tr,
                      depth,
                      x,
                      y,
                      t,
                      flags,
                      tr->walk.index,
                      tx,
                      height,
                      tr->walk.cbarg);
    if (err)
      return err;
  }

  /* calculate new y */

  if (bitvec_get(tr->multiline, tr->walk.index))
    y -= tr->line_height * (height - 1); /* -1 to adjust for initial step */

  tr->walk.x = x;
  tr->walk.y = y;

  /* if the walk needs to stop now, then we raise a non-terminal error to
   * make ntree_walk stop */

  return (stop) ? error_TREEVIEW_STOP_WALK : error_OK;
}