コード例 #1
0
ファイル: scrolling_state.cpp プロジェクト: Skiles/aseprite
bool ScrollingState::onMouseMove(Editor* editor, Message* msg)
{
  View* view = View::getView(editor);
  gfx::Rect vp = view->getViewportBounds();
  gfx::Point scroll = view->getViewScroll();

  editor->setEditorScroll(scroll.x+jmouse_x(1)-jmouse_x(0),
			  scroll.y+jmouse_y(1)-jmouse_y(0), true);

  jmouse_control_infinite_scroll(vp);

  int x, y;
  editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y);
  app_get_statusbar()->setStatusText
    (0, "Pos %3d %3d (Size %3d %3d)", x, y,
     editor->getSprite()->getWidth(),
     editor->getSprite()->getHeight());

  return true;
}
コード例 #2
0
ファイル: textbox.cpp プロジェクト: optigon/aseprite
bool TextBox::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_DRAW:
      getTheme()->draw_textbox(this, &msg->draw.rect);
      return true;

    case JM_SIGNAL:
      if (msg->signal.num == JI_SIGNAL_SET_TEXT) {
        View* view = View::getView(this);
        if (view)
          view->updateView();
      }
      break;

    case JM_KEYPRESSED:
      if (hasFocus()) {
        View* view = View::getView(this);
        if (view) {
          gfx::Rect vp = view->getViewportBounds();
          gfx::Point scroll = view->getViewScroll();
          int textheight = jwidget_get_text_height(this);

          switch (msg->key.scancode) {

            case KEY_LEFT:
              scroll.x -= vp.w/2;
              view->setViewScroll(scroll);
              break;

            case KEY_RIGHT:
              scroll.x += vp.w/2;
              view->setViewScroll(scroll);
              break;

            case KEY_UP:
              scroll.y -= vp.h/2;
              view->setViewScroll(scroll);
              break;

            case KEY_DOWN:
              scroll.y += vp.h/2;
              view->setViewScroll(scroll);
              break;

            case KEY_PGUP:
              scroll.y -= (vp.h-textheight);
              view->setViewScroll(scroll);
              break;

            case KEY_PGDN:
              scroll.y += (vp.h-textheight);
              view->setViewScroll(scroll);
              break;

            case KEY_HOME:
              scroll.y = 0;
              view->setViewScroll(scroll);
              break;

            case KEY_END:
              scroll.y = jrect_h(this->rc) - vp.h;
              view->setViewScroll(scroll);
              break;

            default:
              return false;
          }
        }
        return true;
      }
      break;

    case JM_BUTTONPRESSED: {
      View* view = View::getView(this);
      if (view) {
        captureMouse();
        jmouse_set_cursor(JI_CURSOR_SCROLL);
        return true;
      }
      break;
    }

    case JM_MOTION: {
      View* view = View::getView(this);
      if (view && hasCapture()) {
        gfx::Rect vp = view->getViewportBounds();
        gfx::Point scroll = view->getViewScroll();

        scroll.x += jmouse_x(1) - jmouse_x(0);
        scroll.y += jmouse_y(1) - jmouse_y(0);

        view->setViewScroll(scroll);

        jmouse_control_infinite_scroll(vp);
      }
      break;
    }

    case JM_BUTTONRELEASED: {
      View* view = View::getView(this);
      if (view && hasCapture()) {
        releaseMouse();
        jmouse_set_cursor(JI_CURSOR_NORMAL);
        return true;
      }
      break;
    }

    case JM_WHEEL: {
      View* view = View::getView(this);
      if (view) {
        gfx::Point scroll = view->getViewScroll();

        scroll.y += (jmouse_z(1) - jmouse_z(0)) * jwidget_get_text_height(this)*3;

        view->setViewScroll(scroll);
      }
      break;
    }
  }

  return Widget::onProcessMessage(msg);
}
コード例 #3
0
ファイル: click.cpp プロジェクト: optigon/aseprite
// Returns false when the user stop the click-loop: releases the
// button or press the second click (depend of the mode)
int Editor::editor_click(int *x, int *y, int *update,
                         void (*scroll_callback) (int before_change))
{
  int prev_x, prev_y;

  poll_keyboard();

  if (click_first) {
    click_first = false;

    if (click_mode == MODE_CLICKANDCLICK) {
      do {
        jmouse_poll();
        gui_feedback();
      } while (jmouse_b(0));

      jmouse_set_position(click_start_x, click_start_y);
      clear_keybuf();
    }
  }

  *update = jmouse_poll();

  screenToEditor(click_last_x, click_last_y, &prev_x, &prev_y);

  click_prev_last_b = click_last_b;

  click_last_x = jmouse_x(0);
  click_last_y = jmouse_y(0);
  click_last_b = jmouse_b(0);

  screenToEditor(click_last_x, click_last_y, x, y);

  /* the mouse was moved */
  if (*update) {
    View* view = View::getView(this);
    gfx::Rect vp = view->getViewportBounds();

    /* update scroll */
    if (jmouse_control_infinite_scroll(vp)) {
      if (scroll_callback)
        (*scroll_callback)(true);

      /* smooth scroll movement */
      if (get_config_bool("Options", "MoveSmooth", true)) {
        jmouse_set_position(MID(vp.x+1, click_last_x, vp.x+vp.w-2),
                            MID(vp.y+1, click_last_y, vp.y+vp.h-2));
      }
      /* this is better for high resolutions: scroll movement by big steps */
      else {
        jmouse_set_position((click_last_x != jmouse_x(0)) ?
                            (click_last_x + (vp.x+vp.w/2))/2: jmouse_x(0),

                            (click_last_y != jmouse_y(0)) ?
                            (click_last_y + (vp.y+vp.h/2))/2: jmouse_y(0));
      }

      gfx::Point scroll = view->getViewScroll();
      setEditorScroll(scroll.x+click_last_x-jmouse_x(0),
                      scroll.y+click_last_y-jmouse_y(0), true);

      click_last_x = jmouse_x(0);
      click_last_y = jmouse_y(0);

      if (scroll_callback)
        (*scroll_callback)(false);
    }

    // If the cursor hasn't subpixel movement
    if (!editor_cursor_is_subpixel()) {
      // Check if the mouse change to other pixel of the sprite
      *update = ((prev_x != *x) || (prev_y != *y));
    }
    else {
      // Check if the mouse change to other pixel of the screen
      *update = ((prev_x != click_last_x) || (prev_y != click_last_y));
    }
  }

  /* click-and-click mode */
  if (click_mode == MODE_CLICKANDCLICK) {
    if (click_last_b) {
      click_prev_last_b = click_last_b;

      do {
        jmouse_poll();
        gui_feedback();
      } while (jmouse_b(0));

      jmouse_set_position(click_last_x, click_last_y);
      clear_keybuf();

      return false;
    }
    else {
      return true;
    }
  }
  /* click-and-release mode */
  else {
    return (click_last_b) ? true: false;
  }
}