コード例 #1
0
ファイル: imagearray.c プロジェクト: s0be/naev
/**
 * @brief Mouse event focus on image array.
 *
 *    @param iar Image Array widget.
 *    @param bx X position click.
 *    @param by Y position click.
 */
static void iar_focus( Widget* iar, double bx, double by )
{
   double y, h;
   double scroll_pos, hmax;
   int yelem;
   int selected;

   /* element dimensions */
   iar_getDim( iar, NULL, &h );

   /* number of elements */
   yelem = iar->dat.iar.yelem;

   /* Test for item click. */
   selected = iar_focusImage( iar, bx, by );
   if (selected >= 0) {
      iar->dat.iar.selected = selected;
      if (iar->dat.iar.fptr != NULL)
         iar->dat.iar.fptr( iar->wdw, iar->name );
   }
   /* Scrollbar click. */
   else if (bx > iar->w - 10.) {
      /* Get bar position (center). */
      hmax = h * (yelem - (int)(iar->h / h));
      if (fabs(hmax) < 1e-05)
         scroll_pos = 0.;
      else
         scroll_pos = iar->dat.iar.pos / hmax;
      y = iar->h - (iar->h - 30.) * scroll_pos - 15.;

      /* Click below the bar. */
      if (by < y-15.)
         iar_scroll( iar, -2 );
      /* Click above the bar. */
      else if (by > y+15.)
         iar_scroll( iar, +2 );
      /* Click on the bar. */
      else
         iar->status = WIDGET_STATUS_SCROLLING;
   }
}
コード例 #2
0
ファイル: imagearray.c プロジェクト: reynir/naev
/**
 * @brief Handles mouse movement for an image array.
 *
 *    @param iar Widget handling the mouse motion.
 *    @param mmove Mouse motion event to handle.
 *    @return 1 if the event is used.
 */
static int iar_mmove( Widget* iar, int x, int y, int rx, int ry )
{
    (void) rx;
    (void) ry;
    double w,h;
    int xelem, yelem;
    double hmax;

    if (iar->status == WIDGET_STATUS_SCROLLING) {

        y = CLAMP( 15, iar->h - 15., iar->h - y );

        /* element dimensions */
        iar_getDim( iar, &w, &h );

        /* number of elements */
        xelem = iar->dat.iar.xelem;
        yelem = iar->dat.iar.yelem;

        hmax = h * (yelem - (int)(iar->h / h));
        iar->dat.iar.pos = (y - 15.) * hmax / (iar->h - 30.);

        /* Does boundry checks. */
        iar_scroll( iar, 0 );

        return 1;
    }
    else {
        if ((x < 0) || (x >= iar->w) || (y < 0) || (y >= iar->h))
            iar->dat.iar.alt  = -1;
        else {
            iar->dat.iar.alt  = iar_focusImage( iar, x, y );
            iar->dat.iar.altx = x;
            iar->dat.iar.alty = y;
        }
    }

    return 0;
}