void Tabs::calculateHot() { JRect rect = jwidget_get_rect(this); JRect box = jrect_new(rect->x1-m_scrollX, rect->y1, 0, rect->y2-1); Tab *hot = NULL; TabsListIterator it, end = m_list_of_tabs.end(); // For each tab for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; box->x2 = box->x1 + tab->width; if (jrect_point_in(box, jmouse_x(0), jmouse_y(0))) { hot = tab; break; } box->x1 = box->x2; } if (m_hot != hot) { m_hot = hot; if (m_delegate) m_delegate->mouseOverTab(this, m_hot ? m_hot->data: NULL); invalidate(); } jrect_free(rect); jrect_free(box); }
bool jmouse_control_infinite_scroll(const gfx::Rect& rect) { int x, y, u, v; u = jmouse_x(0); v = jmouse_y(0); if (u <= rect.x) x = rect.x+rect.w-2; else if (u >= rect.x+rect.w-1) x = rect.x+1; else x = u; if (v <= rect.y) y = rect.y+rect.h-2; else if (v >= rect.y+rect.h-1) y = rect.y+1; else y = v; if ((x != u) || (y != v)) { jmouse_set_position(x, y); return true; } else return false; }
void AppTabsDelegate::clickTab(Tabs* tabs, void* data, int button) { Document* document = reinterpret_cast<Document*>(data); // put as current sprite set_document_in_more_reliable_editor(document); if (document) { Context* context = UIContext::instance(); context->updateFlags(); // right-button: popup-menu if (button & 2) { Menu* popup_menu = get_document_tab_popup_menu(); if (popup_menu != NULL) { popup_menu->showPopup(jmouse_x(0), jmouse_y(0)); } } // middle-button: close the sprite else if (button & 4) { Command* close_file_cmd = CommandsModule::instance()->getCommandByName(CommandId::CloseFile); context->executeCommand(close_file_cmd, NULL); } } }
void EyedropperCommand::onExecute(Context* context) { Widget* widget = gui::Manager::getDefault()->getMouse(); if (!widget || widget->type != editor_type()) return; Editor* editor = static_cast<Editor*>(widget); Sprite* sprite = editor->getSprite(); if (!sprite) return; // pixel position to get int x, y; editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); // get the color from the image Color color = Color::fromImage(sprite->getPixelFormat(), sprite->getPixel(x, y)); // TODO replace the color in the "context", not directly from the color-bar // set the color of the color-bar if (m_background) app_get_colorbar()->setBgColor(color); else app_get_colorbar()->setFgColor(color); }
void Editor::editor_click_continue(int mode, int *x, int *y) { 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 = click_prev_last_b; screenToEditor(click_start_x, click_start_y, x, y); }
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; }
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(); }
bool StandbyState::onUpdateStatusBar(Editor* editor) { tools::Tool* current_tool = editor->getCurrentEditorTool(); Sprite* sprite = editor->getSprite(); int x, y; editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); if (!sprite) { app_get_statusbar()->clearText(); } // For eye-dropper else if (current_tool->getInk(0)->isEyedropper()) { int imgtype = sprite->getImgType(); uint32_t pixel = sprite->getPixel(x, y); Color color = Color::fromImage(imgtype, pixel); int alpha = 255; switch (imgtype) { case IMAGE_RGB: alpha = _rgba_geta(pixel); break; case IMAGE_GRAYSCALE: alpha = _graya_geta(pixel); break; } char buf[256]; usprintf(buf, "- Pos %d %d", x, y); app_get_statusbar()->showColor(0, buf, color, alpha); } else { Mask* mask = editor->getDocument()->getMask(); app_get_statusbar()->setStatusText (0, "Pos %d %d, Size %d %d, Frame %d", x, y, ((mask && mask->bitmap)? mask->w: sprite->getWidth()), ((mask && mask->bitmap)? mask->h: sprite->getHeight()), sprite->getCurrentFrame()+1); } return true; }
bool StandbyState::onUpdateStatusBar(Editor* editor) { tools::Ink* ink = editor->getCurrentEditorInk(); const Sprite* sprite = editor->sprite(); int x, y; editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); if (!sprite) { StatusBar::instance()->clearText(); } // For eye-dropper else if (ink->isEyedropper()) { bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha(); ColorPicker picker; picker.pickColor(editor->getDocumentLocation(), x, y, grabAlpha ? ColorPicker::FromActiveLayer: ColorPicker::FromComposition); char buf[256]; usprintf(buf, "- Pos %d %d", x, y); StatusBar::instance()->showColor(0, buf, picker.color(), picker.alpha()); } else { Mask* mask = (editor->document()->isMaskVisible() ? editor->document()->mask(): NULL); StatusBar::instance()->setStatusText(0, "Pos %d %d, Size %d %d, Frame %d [%d msecs]", x, y, (mask ? mask->bounds().w: sprite->width()), (mask ? mask->bounds().h: sprite->height()), editor->frame()+1, sprite->getFrameDuration(editor->frame())); } return true; }
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); }
gfx::Point get_mouse_position() { return gfx::Point(jmouse_x(0), jmouse_y(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; } }
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; }