예제 #1
0
파일: system.cpp 프로젝트: eledot/aseprite
void SetDisplay(she::Display* display)
{
  CursorType cursor = jmouse_get_cursor();

  jmouse_set_cursor(kNoCursor);
  ji_screen = (display ? reinterpret_cast<BITMAP*>(display->getSurface()->nativeHandle()): NULL);
  ji_screen_w = (ji_screen ? ji_screen->w: 0);
  ji_screen_h = (ji_screen ? ji_screen->h: 0);

  if (ji_screen != NULL) {
    Manager* manager = Manager::getDefault();
    if (manager) {
      manager->setDisplay(display);

      // Update default-manager size
      if ((jrect_w(manager->rc) != JI_SCREEN_W ||
           jrect_h(manager->rc) != JI_SCREEN_H)) {
        JRect rect = jrect_new(0, 0, JI_SCREEN_W, JI_SCREEN_H);
        jwidget_set_rect(manager, rect);
        jrect_free(rect);
      }
    }

    jmouse_set_cursor(cursor);  // Restore mouse cursor
  }
}
예제 #2
0
bool LinkLabel::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_SETCURSOR:
      // TODO theme stuff
      if (isEnabled()) {
        jmouse_set_cursor(kHandCursor);
        return true;
      }
      break;

    case JM_MOUSEENTER:
    case JM_MOUSELEAVE:
      // TODO theme stuff
      if (isEnabled())
        invalidate();
      break;

    case JM_BUTTONRELEASED:
      if (isEnabled()) {
        if (!m_url.empty())
          Launcher::openUrl(m_url);
        Click();
      }
      break;
  }

  return CustomLabel::onProcessMessage(msg);
}
예제 #3
0
bool MovingPixelsState::onSetCursor(Editor* editor)
{
  ASSERT(m_pixelsMovement != NULL);

  // Move selection
  if (m_pixelsMovement->isDragging() || editor->isInsideSelection()) {
    editor->hideDrawingCursor();
    jmouse_set_cursor(JI_CURSOR_MOVE);
    return true;
  }

  // Use StandbyState implementation
  return StandbyState::onSetCursor(editor);
}
예제 #4
0
파일: system.cpp 프로젝트: atzkey/aseprite
void SetDisplay(she::Display* display)
{
  CursorType cursor = jmouse_get_cursor();

  jmouse_set_cursor(kNoCursor);
  ji_screen = (display ? reinterpret_cast<BITMAP*>(display->getSurface()->nativeHandle()): NULL);
  ji_screen_w = (ji_screen ? ji_screen->w: 0);
  ji_screen_h = (ji_screen ? ji_screen->h: 0);

  if (ji_screen != NULL) {
    Manager* manager = Manager::getDefault();
    if (manager) {
      manager->setDisplay(display);

      // Update default-manager size
      if ((manager->getBounds().w != JI_SCREEN_W ||
           manager->getBounds().h != JI_SCREEN_H)) {
        manager->setBounds(gfx::Rect(0, 0, JI_SCREEN_W, JI_SCREEN_H));
      }
    }

    jmouse_set_cursor(cursor);  // Restore mouse cursor
  }
}
예제 #5
0
bool StandbyState::onSetCursor(Editor* editor)
{
  tools::Tool* current_tool = editor->getCurrentEditorTool();

  if (current_tool) {
    // If the current tool change selection (e.g. rectangular marquee, etc.)
    if (current_tool->getInk(0)->isSelection()) {
      // Move pixels
      if (editor->isInsideSelection()) {
	editor->hideDrawingCursor();

	if (key[KEY_LCONTROL] ||
	    key[KEY_RCONTROL]) // TODO configurable keys
	  jmouse_set_cursor(JI_CURSOR_NORMAL_ADD);
	else
	  jmouse_set_cursor(JI_CURSOR_MOVE);

	return true;
      }
    }
    else if (current_tool->getInk(0)->isEyedropper()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
      return true;
    }
    else if (current_tool->getInk(0)->isScrollMovement()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(JI_CURSOR_SCROLL);
      return true;
    }
    else if (current_tool->getInk(0)->isCelMovement()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(JI_CURSOR_MOVE);
      return true;
    }
  }

  // Draw
  if (editor->canDraw()) {
    jmouse_set_cursor(JI_CURSOR_NULL);
    editor->showDrawingCursor();
  }
  // Forbidden
  else {
    editor->hideDrawingCursor();
    jmouse_set_cursor(JI_CURSOR_FORBIDDEN);
  }

  return true;
}
예제 #6
0
파일: window.cpp 프로젝트: atzkey/aseprite
bool Window::onProcessMessage(Message* msg)
{
  switch (msg->type()) {

    case kOpenMessage:
      m_killer = NULL;
      break;

    case kCloseMessage:
      saveLayout();
      break;

    case kMouseDownMessage: {
      if (!m_isMoveable)
        break;

      clickedMousePos = static_cast<MouseMessage*>(msg)->position();
      m_hitTest = hitTest(clickedMousePos);

      if (m_hitTest != HitTestNowhere &&
          m_hitTest != HitTestClient) {
        if (clickedWindowPos == NULL)
          clickedWindowPos = new gfx::Rect(getBounds());
        else
          *clickedWindowPos = getBounds();

        captureMouse();
        return true;
      }
      else
        break;
    }

    case kMouseUpMessage:
      if (hasCapture()) {
        releaseMouse();
        jmouse_set_cursor(kArrowCursor);

        if (clickedWindowPos != NULL) {
          delete clickedWindowPos;
          clickedWindowPos = NULL;
        }

        m_hitTest = HitTestNowhere;
        return true;
      }
      break;

    case kMouseMoveMessage:
      if (!m_isMoveable)
        break;

      // Does it have the mouse captured?
      if (hasCapture()) {
        gfx::Point mousePos = static_cast<MouseMessage*>(msg)->position();

        // Reposition/resize
        if (m_hitTest == HitTestCaption) {
          int x = clickedWindowPos->x + (mousePos.x - clickedMousePos.x);
          int y = clickedWindowPos->y + (mousePos.y - clickedMousePos.y);
          moveWindow(gfx::Rect(x, y,
                               getBounds().w,
                               getBounds().h), true);
        }
        else {
          int x, y, w, h;

          w = clickedWindowPos->w;
          h = clickedWindowPos->h;

          bool hitLeft = (m_hitTest == HitTestBorderNW ||
                          m_hitTest == HitTestBorderW ||
                          m_hitTest == HitTestBorderSW);
          bool hitTop = (m_hitTest == HitTestBorderNW ||
                         m_hitTest == HitTestBorderN ||
                         m_hitTest == HitTestBorderNE);
          bool hitRight = (m_hitTest == HitTestBorderNE ||
                           m_hitTest == HitTestBorderE ||
                           m_hitTest == HitTestBorderSE);
          bool hitBottom = (m_hitTest == HitTestBorderSW ||
                            m_hitTest == HitTestBorderS ||
                            m_hitTest == HitTestBorderSE);

          if (hitLeft) {
            w += clickedMousePos.x - mousePos.x;
          }
          else if (hitRight) {
            w += mousePos.x - clickedMousePos.x;
          }

          if (hitTop) {
            h += (clickedMousePos.y - mousePos.y);
          }
          else if (hitBottom) {
            h += (mousePos.y - clickedMousePos.y);
          }

          limitSize(&w, &h);

          if ((getBounds().w != w) ||
              (getBounds().h != h)) {
            if (hitLeft)
              x = clickedWindowPos->x - (w - clickedWindowPos->w);
            else
              x = getBounds().x;

            if (hitTop)
              y = clickedWindowPos->y - (h - clickedWindowPos->h);
            else
              y = getBounds().y;

            moveWindow(gfx::Rect(x, y, w, h), false);
            invalidate();
          }
        }
      }
      break;

    case kSetCursorMessage:
      if (m_isMoveable) {
        gfx::Point mousePos = static_cast<MouseMessage*>(msg)->position();
        HitTest ht = hitTest(mousePos);
        CursorType cursor = kArrowCursor;

        switch (ht) {

          case HitTestCaption:
            cursor = kArrowCursor;
            break;

          case HitTestBorderNW:
            cursor = kSizeTLCursor;
            break;

          case HitTestBorderW:
            cursor = kSizeLCursor;
            break;

          case HitTestBorderSW:
            cursor = kSizeBLCursor;
            break;

          case HitTestBorderNE:
            cursor = kSizeTRCursor;
            break;

          case HitTestBorderE:
            cursor = kSizeRCursor;
            break;

          case HitTestBorderSE:
            cursor = kSizeBRCursor;
            break;

          case HitTestBorderN:
            cursor = kSizeTCursor;
            break;

          case HitTestBorderS:
            cursor = kSizeBCursor;
            break;

        }

        jmouse_set_cursor(cursor);
        return true;
      }
      break;

  }

  return Widget::onProcessMessage(msg);
}
예제 #7
0
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);
}
예제 #8
0
파일: misc.cpp 프로젝트: Skiles/aseprite
// Gives to the user the possibility to move the sprite's layer in the
// current editor, returns true if the position was changed.
int interactive_move_layer(int mode, bool use_undo, int (*callback)())
{
    Editor* editor = current_editor;
    Document* document = editor->getDocument();
    undo::UndoHistory* undo = document->getUndoHistory();
    Sprite* sprite = document->getSprite();

    ASSERT(sprite->getCurrentLayer()->is_image());

    LayerImage* layer = static_cast<LayerImage*>(sprite->getCurrentLayer());
    Cel *cel = layer->getCel(sprite->getCurrentFrame());
    int start_x, new_x;
    int start_y, new_y;
    int start_b;
    int ret;
    int update = false;
    int quiet_clock = -1;
    int first_time = true;
    int begin_x;
    int begin_y;

    if (!cel)
        return false;

    begin_x = cel->getX();
    begin_y = cel->getY();

    editor->hideDrawingCursor();
    jmouse_set_cursor(JI_CURSOR_MOVE);

    editor->editor_click_start(mode, &start_x, &start_y, &start_b);

    do {
        if (update) {
            cel->setPosition(begin_x - start_x + new_x,
                             begin_y - start_y + new_y);

            // Update layer-bounds.
            editor->invalidate();

            // Update status bar.
            app_get_statusbar()->setStatusText
            (0,
             "Pos %3d %3d Offset %3d %3d",
             (int)cel->getX(),
             (int)cel->getY(),
             (int)(cel->getX() - begin_x),
             (int)(cel->getY() - begin_y));

            /* update clock */
            quiet_clock = ji_clock;
            first_time = false;
        }

        /* call the user's routine */
        if (callback)
            (*callback)();

        /* redraw dirty widgets */
        jwidget_flush_redraw(ji_get_default_manager());
        jmanager_dispatch_messages(ji_get_default_manager());

        gui_feedback();
    } while (editor->editor_click(&new_x, &new_y, &update, NULL));

    new_x = cel->getX();
    new_y = cel->getY();
    cel->setPosition(begin_x, begin_y);

    /* the position was changed */
    if (!editor->editor_click_cancel()) {
        if (use_undo && undo->isEnabled()) {
            undo->setLabel("Cel Movement");
            undo->setModification(undo::ModifyDocument);

            undo->pushUndoer(new undoers::SetCelPosition(undo->getObjects(), cel));
        }

        cel->setPosition(new_x, new_y);
        ret = true;
    }
    /* the position wasn't changed */
    else {
        ret = false;
    }

    /* redraw the sprite in all editors */
    update_screen_for_document(document);

    /* restore the cursor */
    editor->showDrawingCursor();

    editor->editor_click_done();

    return ret;
}
예제 #9
0
파일: app.cpp 프로젝트: optigon/aseprite
int App::run()
{
#ifdef ENABLE_UPDATER
  app::CheckUpdateThreadLauncher checkUpdate;
#endif

  // Initialize GUI interface
  if (isGui()) {
    View* view;
    Editor* editor;

    PRINTF("GUI mode\n");

    // Setup the GUI screen
    jmouse_set_cursor(JI_CURSOR_NORMAL);
    gui::Manager::getDefault()->invalidate();

    // Load main window
    top_window = static_cast<Frame*>(load_widget("main_window.xml", "main_window"));

    box_menubar = top_window->findChild("menubar");
    box_editors = top_window->findChild("editor");
    box_colorbar = top_window->findChild("colorbar");
    box_toolbar = top_window->findChild("toolbar");
    box_statusbar = top_window->findChild("statusbar");
    box_tabsbar = top_window->findChild("tabsbar");

    menubar = new MenuBar();
    statusbar = new StatusBar();
    colorbar = new ColorBar(box_colorbar->getAlign());
    toolbar = toolbar_new();
    tabsbar = new Tabs(m_tabsDelegate = new AppTabsDelegate());
    view = new EditorView(EditorView::CurrentEditorMode);
    editor = create_new_editor();

    // configure all widgets to expansives
    menubar->setExpansive(true);
    statusbar->setExpansive(true);
    colorbar->setExpansive(true);
    toolbar->setExpansive(true);
    tabsbar->setExpansive(true);
    view->setExpansive(true);

    /* prepare the first editor */
    view->attachToView(editor);

    /* setup the menus */
    menubar->setMenu(get_root_menu());

    /* start text of status bar */
    app_default_statusbar_message();

    /* add the widgets in the boxes */
    if (box_menubar) box_menubar->addChild(menubar);
    if (box_editors) box_editors->addChild(view);
    if (box_colorbar) box_colorbar->addChild(colorbar);
    if (box_toolbar) box_toolbar->addChild(toolbar);
    if (box_statusbar) box_statusbar->addChild(statusbar);
    if (box_tabsbar) box_tabsbar->addChild(tabsbar);

    /* prepare the window */
    top_window->remap_window();

    // Create the list of tabs
    app_rebuild_documents_tabs();
    app_rebuild_recent_list();

    // Set current editor
    set_current_editor(editor);

    // Open the window
    top_window->open_window();

    // Redraw the whole screen.
    gui::Manager::getDefault()->invalidate();
  }

  /* set background mode for non-GUI modes */
/*   if (!(ase_mode & MODE_GUI)) */
/*     set_display_switch_mode(SWITCH_BACKAMNESIA); */
    set_display_switch_mode(SWITCH_BACKGROUND);

    // procress options
  PRINTF("Processing options...\n");

  ASSERT(m_checkArgs != NULL);
  {
    Console console;
    for (CheckArgs::iterator
           it  = m_checkArgs->begin();
         it != m_checkArgs->end(); ++it) {
      CheckArgs::Option* option = *it;

      switch (option->type()) {

        case CheckArgs::Option::OpenSprite: {
          // Load the sprite
          Document* document = load_document(option->data().c_str());
          if (!document) {
            if (!isGui())
              console.printf("Error loading file \"%s\"\n", option->data().c_str());
          }
          else {
            // Mount and select the sprite
            UIContext* context = UIContext::instance();
            context->addDocument(document);
            context->setActiveDocument(document);

            if (isGui()) {
              // Show it
              set_document_in_more_reliable_editor(context->getFirstDocument());

              // Recent file
              getRecentFiles()->addRecentFile(option->data().c_str());
            }
          }
          break;
        }
      }
    }
    delete m_checkArgs;
    m_checkArgs = NULL;
  }

  // Run the GUI
  if (isGui()) {
    // Support to drop files from Windows explorer
    install_drop_files();

#ifdef ENABLE_UPDATER
    // Launch the thread to check for updates.
    checkUpdate.launch();
#endif

    // Run the GUI main message loop
    gui_run();

    // Uninstall support to drop files
    uninstall_drop_files();

    // Remove the root-menu from the menu-bar (because the rootmenu
    // module should destroy it).
    menubar->setMenu(NULL);

    // Delete all editors first because they used signals from other
    // widgets (e.g. color bar).
    delete box_editors;

    // Destroy mini-editor.
    exit_module_editors();

    // Destroy the top-window
    delete top_window;
    top_window = NULL;
  }

  return 0;
}
예제 #10
0
bool ScrollingState::onSetCursor(Editor* editor)
{
  editor->hideDrawingCursor();
  jmouse_set_cursor(JI_CURSOR_SCROLL);
  return true;
}
예제 #11
0
bool ColorButton::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_CLOSE:
      if (m_frame && m_frame->isVisible())
	m_frame->closeWindow(NULL);
      break;

    case JM_MOUSEENTER:
      app_get_statusbar()->showColor(0, "", m_color, 255);
      break;

    case JM_MOUSELEAVE:
      app_get_statusbar()->clearText();
      break;

    case JM_SIGNAL:
      if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT) {
	// If the popup window was not created or shown yet..
	if (m_frame == NULL || !m_frame->isVisible()) {
	  // Open it
	  openSelectorDialog();
	}
	else if (!m_frame->is_moveable()) {
	  // If it is visible, close it
	  closeSelectorDialog();
	}
	return true;
      }
      break;

    case JM_MOTION:
      if (hasCapture()) {
	Widget* picked = ji_get_default_manager()->pick(msg->mouse.x, msg->mouse.y);
	Color color = m_color;

	if (picked && picked != this) {
	  // Pick a color from another color-button
	  if (ColorButton* pickedColBut = dynamic_cast<ColorButton*>(picked)) {
	    color = pickedColBut->getColor();
	  }
	  // Pick a color from the color-bar
	  else if (picked->type == palette_view_type()) {
	    color = ((PaletteView*)picked)->getColorByPosition(msg->mouse.x, msg->mouse.y);
	  }
	  // Pick a color from a editor
	  else if (picked->type == editor_type()) {
	    Editor* editor = static_cast<Editor*>(picked);
	    Sprite* sprite = editor->getSprite();
	    int x, y, imgcolor;

	    if (sprite) {
	      x = msg->mouse.x;
	      y = msg->mouse.y;
	      editor->screenToEditor(x, y, &x, &y);
	      imgcolor = sprite->getPixel(x, y);
	      color = Color::fromImage(sprite->getImgType(), imgcolor);
	    }
	  }
	}

	// Did the color change?
	if (color != m_color) {
	  setColor(color);
	}
      }
      break;

    case JM_SETCURSOR:
      if (hasCapture()) {
	jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
	return true;
      }
      break;

  }

  return ButtonBase::onProcessMessage(msg);
}
예제 #12
0
bool TextBox::onProcessMessage(Message* msg)
{
    switch (msg->type()) {

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

                switch (static_cast<KeyMessage*>(msg)->scancode()) {

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

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

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

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

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

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

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

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

                default:
                    return Widget::onProcessMessage(msg);
                }
            }
            return true;
        }
        break;

    case kMouseDownMessage: {
        View* view = View::getView(this);
        if (view) {
            captureMouse();
            m_oldPos = static_cast<MouseMessage*>(msg)->position();
            jmouse_set_cursor(kScrollCursor);
            return true;
        }
        break;
    }

    case kMouseMoveMessage: {
        View* view = View::getView(this);
        if (view && hasCapture()) {
            gfx::Rect vp = view->getViewportBounds();
            gfx::Point scroll = view->getViewScroll();
            gfx::Point newPos = static_cast<MouseMessage*>(msg)->position();

            scroll += m_oldPos - newPos;
            view->setViewScroll(scroll);

            m_oldPos = ui::control_infinite_scroll(this, vp, newPos);
        }
        break;
    }

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

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

            scroll.y += -static_cast<MouseMessage*>(msg)->wheelDelta() * getTextHeight()*3;

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

    return Widget::onProcessMessage(msg);
}
예제 #13
0
bool StandbyState::Decorator::onSetCursor(Editor* editor)
{
  if (!editor->document()->isMaskVisible())
    return false;

  const gfx::Transformation transformation(m_standbyState->getTransformation(editor));
  TransformHandles* tr = getTransformHandles(editor);
  HandleType handle = tr->getHandleAtPoint(editor,
                                           gfx::Point(jmouse_x(0), jmouse_y(0)),
                                           transformation);

  CursorType newCursor = kArrowCursor;

  switch (handle) {
    case ScaleNWHandle:         newCursor = kSizeNWCursor; break;
    case ScaleNHandle:          newCursor = kSizeNCursor; break;
    case ScaleNEHandle:         newCursor = kSizeNECursor; break;
    case ScaleWHandle:          newCursor = kSizeWCursor; break;
    case ScaleEHandle:          newCursor = kSizeECursor; break;
    case ScaleSWHandle:         newCursor = kSizeSWCursor; break;
    case ScaleSHandle:          newCursor = kSizeSCursor; break;
    case ScaleSEHandle:         newCursor = kSizeSECursor; break;
    case RotateNWHandle:        newCursor = kRotateNWCursor; break;
    case RotateNHandle:         newCursor = kRotateNCursor; break;
    case RotateNEHandle:        newCursor = kRotateNECursor; break;
    case RotateWHandle:         newCursor = kRotateWCursor; break;
    case RotateEHandle:         newCursor = kRotateECursor; break;
    case RotateSWHandle:        newCursor = kRotateSWCursor; break;
    case RotateSHandle:         newCursor = kRotateSCursor; break;
    case RotateSEHandle:        newCursor = kRotateSECursor; break;
    case PivotHandle:           newCursor = kHandCursor; break;
    default:
      return false;
  }

  // Adjust the cursor depending the current transformation angle.
  fixed angle = ftofix(128.0 * transformation.angle() / PI);
  angle = fixadd(angle, itofix(16));
  angle &= (255<<16);
  angle >>= 16;
  angle /= 32;

  if (newCursor >= kSizeNCursor && newCursor <= kSizeNWCursor) {
    size_t num = sizeof(rotated_size_cursors) / sizeof(rotated_size_cursors[0]);
    size_t c;
    for (c=num-1; c>0; --c)
      if (rotated_size_cursors[c] == newCursor)
        break;

    newCursor = rotated_size_cursors[(c+angle) % num];
  }
  else if (newCursor >= kRotateNCursor && newCursor <= kRotateNWCursor) {
    size_t num = sizeof(rotated_rotate_cursors) / sizeof(rotated_rotate_cursors[0]);
    size_t c;
    for (c=num-1; c>0; --c)
      if (rotated_rotate_cursors[c] == newCursor)
        break;

    newCursor = rotated_rotate_cursors[(c+angle) % num];
  }

  // Hide the drawing cursor (just in case) and show the new system cursor.
  editor->hideDrawingCursor();
  jmouse_set_cursor(newCursor);
  return true;
}
예제 #14
0
bool StandbyState::onSetCursor(Editor* editor)
{
  tools::Ink* ink = editor->getCurrentEditorInk();
  if (ink) {
    // If the current tool change selection (e.g. rectangular marquee, etc.)
    if (ink->isSelection()) {
      // See if the cursor is in some selection handle.
      if (m_decorator->onSetCursor(editor))
        return true;

      // Move pixels
      if (editor->isInsideSelection()) {
        EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();

        editor->hideDrawingCursor();

        if (customization && customization->isCopySelectionKeyPressed())
          jmouse_set_cursor(kArrowPlusCursor);
        else
          jmouse_set_cursor(kMoveCursor);

        return true;
      }
    }
    else if (ink->isEyedropper()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(kEyedropperCursor);
      return true;
    }
    else if (ink->isZoom()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(kMagnifierCursor);
      return true;
    }
    else if (ink->isScrollMovement()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(kScrollCursor);
      return true;
    }
    else if (ink->isCelMovement()) {
      editor->hideDrawingCursor();
      jmouse_set_cursor(kMoveCursor);
      return true;
    }
    else if (ink->isSlice()) {
      jmouse_set_cursor(kNoCursor);
      editor->showDrawingCursor();
      return true;
    }
  }

  // Draw
  if (editor->canDraw()) {
    jmouse_set_cursor(kNoCursor);
    editor->showDrawingCursor();
  }
  // Forbidden
  else {
    editor->hideDrawingCursor();
    jmouse_set_cursor(kForbiddenCursor);
  }

  return true;
}