Exemplo n.º 1
0
void scroller::draw_first(image *screen) {
	if (sx >= t)
		sx = t - 1;
	draw(0, screen);
	screen->widget_bar(b1x(), b1y(), b1x() + bw() - 1, b1y() + bh() - 1,
			wm->bright_color(), wm->medium_color(), wm->dark_color());
	screen->widget_bar(b2x(), b2y(), b2x() + bw() - 1, b2y() + bh() - 1,
			wm->bright_color(), wm->medium_color(), wm->dark_color());
	show_icon(screen, b1x() + 2, b1y() + 2, bw() - 4, bh() - 4, b1());
	show_icon(screen, b2x() + 2, b2y() + 2, bw() - 4, bh() - 4, b2());

	int x1, y1, x2, y2;
	dragger_area(x1, y1, x2, y2);
	screen->bar(x1, y1, x2, y2, wm->black());
	screen->bar(x1 + 1, y1 + 1, x2 - 1, y2 - 1, wm->medium_color());
	draw_widget(screen, 0);
	scroll_event(sx, screen);
}
Exemplo n.º 2
0
void scroller::handle_event(Event &ev, image *screen, InputManager *inm)
{
  int mx=ev.mouse_move.x,my=ev.mouse_move.y;
  switch (ev.type)
  {
    case EV_MOUSE_BUTTON :
    {
      if (ev.mouse_button && drag==-1)
      {
    if (mx>=b1x() && mx<b1x()+bw() && my>=b1y()-2 && my<b1y()+bh())
    {
      if (sx>0)
      {
        draw_widget(screen,1);
        sx--;
        draw_widget(screen,0);
        scroll_event(sx,screen);
      }
    } else if (mx>=b2x() && mx<b2x()+bw() && my>=b2y() && my<=b2y()+bh())
    {
      if (sx<t-1)
      {
        draw_widget(screen,1);
        sx++;
        draw_widget(screen,0);
        scroll_event(sx,screen);
      }
    }
    else
    {
      int dx1,dy1,dx2,dy2;
      dragger_area(dx1,dy1,dx2,dy2);
      if (mx>=dx1 && mx<=dx2 && my>=dy1 && my<=dy2)
      {
        int x1,y1,x2,y2;
        wig_area(x1,y1,x2,y2);
        if (mx>=x1 && mx<=x2 && my>=y1 && my<=y2)
        {
          drag=sx;
          inm->grab_focus(this);
        }
        else if (t>1)
        {
          int nx=mouse_to_drag(mx,my);
          if (nx!=sx && nx>=0 && nx<t)
          {
        draw_widget(screen,1);
        sx=nx;
        draw_widget(screen,0);
        scroll_event(sx,screen);
          }
        }
      } else handle_inside_event(ev,screen,inm);
    }
      } else if (!ev.mouse_button && drag!=-1)
      {
    inm->release_focus();
    drag=-1;
      }
    } break;

    case EV_MOUSE_MOVE :
    {
      if (drag!=-1)
      {
    int nx=mouse_to_drag(mx,my);
    if (nx<0) nx=0; else if (nx>=t) nx=t-1;
    if (nx!=sx)
    {
      draw_widget(screen,1);
      sx=nx;
      draw_widget(screen,0);
      scroll_event(sx,screen);
    }
      } else if ( activate_on_mouse_move())
      {
    int x1,y1,x2,y2;
    wig_area(x1,y1,x2,y2);
    if (mx>=m_pos.x && mx<=m_pos.x+l-1 && my>=m_pos.y && my<=m_pos.y+h-1)
      handle_inside_event(ev,screen,inm);
      }

    } break;
    case EV_KEY :
    {
      switch (ev.key)
      {
    case JK_LEFT :
    { handle_left(screen,inm); } break;
    case JK_RIGHT :
    { handle_right(screen,inm); } break;
    case JK_UP :
    { handle_up(screen,inm); } break;
    case JK_DOWN :
    { handle_down(screen,inm); } break;

    default :
      handle_inside_event(ev,screen,inm);
      }
    } break;
  }
}