Esempio n. 1
0
void Editor::editor_click_start(int mode, int *x, int *y, int *b)
{
  click_mode = mode;
  click_first = true;

  click_start_x = click_last_x = jmouse_x(0);
  click_start_y = click_last_y = jmouse_y(0);
  click_start_b = click_last_b = jmouse_b(0) ? jmouse_b(0): 1;

  click_prev_last_b = click_last_b;

  screenToEditor(click_start_x, click_start_y, x, y);
  *b = click_start_b;

  captureMouse();
}
Esempio n. 2
0
void ColorBar::onPaletteIndexChange(int index)
{
  m_lock = true;

  Color color = Color::fromIndex(index);

  if (jmouse_b(0) & 2) // TODO create a PaletteChangeEvent and take left/right mouse button from there
    setBgColor(color);
  else
    setFgColor(color);

  m_lock = false;
}
Esempio n. 3
0
bool MovingPixelsState::onKeyDown(Editor* editor, Message* msg)
{
  ASSERT(m_pixelsMovement != NULL);

  if (msg->key.scancode == KEY_LCONTROL || // TODO configurable
      msg->key.scancode == KEY_RCONTROL) {
    // If the user press the CTRL key when he is dragging pixels (but
    // not pressing the mouse buttons).
    if (!jmouse_b(0) && m_pixelsMovement) {
      // Drop pixels (sure the user will press the mouse button to
      // start dragging a copy).
      dropPixels(editor);
    }
  }

  // Use StandbyState implementation
  return StandbyState::onKeyDown(editor, msg);
}
Esempio n. 4
0
// 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;
  }
}