MovingPixelsState::MovingPixelsState(Editor* editor, Message* msg, Image* imge, int x, int y, int opacity) { // Copy the mask to the extra cel image Document* document = editor->getDocument(); Sprite* sprite = editor->getSprite(); Image* tmpImage = NewImageFromMask(document); x = document->getMask()->x; y = document->getMask()->y; m_pixelsMovement = new PixelsMovement(document, sprite, tmpImage, x, y, opacity); delete tmpImage; // If the CTRL key is pressed start dragging a copy of the selection if (key[KEY_LCONTROL] || key[KEY_RCONTROL]) // TODO configurable m_pixelsMovement->copyMask(); else m_pixelsMovement->cutMask(); editor->screenToEditor(msg->mouse.x, msg->mouse.y, &x, &y); m_pixelsMovement->catchImage(x, y); // Setup mask color setTransparentColor(app_get_statusbar()->getTransparentColor()); app_get_statusbar()->addListener(this); app_get_statusbar()->showMovePixelsOptions(); editor->captureMouse(); }
void AppTabsDelegate::mouseOverTab(Tabs* tabs, void* data) { // Note: data can be NULL Document* document = (Document*)data; if (data) { app_get_statusbar()->setStatusText(250, "%s", static_cast<const char*>(document->getFilename())); } else { app_get_statusbar()->clearText(); } }
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 MovingPixelsState::onUpdateStatusBar(Editor* editor) { ASSERT(m_pixelsMovement != NULL); gfx::Rect bounds = m_pixelsMovement->getImageBounds(); app_get_statusbar()->setStatusText (100, "Pos %d %d, Size %d %d", bounds.x, bounds.y, bounds.w, bounds.h); return true; }
void NewLayerCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); Sprite* sprite(document->getSprite()); std::string name; // Default name (m_name is a name specified in params) if (!m_name.empty()) name = m_name; else name = get_unique_layer_name(sprite); // If params specify to ask the user about the name... if (m_ask) { // We open the window to ask the name FramePtr window(load_widget("new_layer.xml", "new_layer")); JWidget name_widget = find_widget(window, "name"); name_widget->setText(name.c_str()); jwidget_set_min_size(name_widget, 128, 0); window->open_window_fg(); if (window->get_killer() != window->findChild("ok")) return; name = window->findChild("name")->getText(); } Layer* layer; { UndoTransaction undoTransaction(document, "New Layer"); layer = undoTransaction.newLayer(); undoTransaction.commit(); } layer->setName(name); update_screen_for_document(document); app_get_statusbar()->invalidate(); app_get_statusbar()->showTip(1000, "Layer `%s' created", name.c_str()); }
void UndoCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); app_get_statusbar() ->showTip(1000, "Undid %s", document->getUndoHistory()->getNextUndoLabel()); document->getUndoHistory()->doUndo(); document->generateMaskBoundaries(); document->destroyExtraCel(); // Regenerate extras update_screen_for_document(document); }
void NewFrameCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); Sprite* sprite(document->getSprite()); { UndoTransaction undoTransaction(document, "New Frame"); undoTransaction.newFrame(); undoTransaction.commit(); } update_screen_for_document(document); app_get_statusbar() ->showTip(1000, "New frame %d/%d", sprite->getCurrentFrame()+1, sprite->getTotalFrames()); }
Job::Job(const char* job_name) { m_mutex = NULL; m_thread = NULL; m_progress = NULL; m_monitor = NULL; m_last_progress = 0.0f; m_done_flag = false; m_canceled_flag = false; m_mutex = new Mutex(); m_progress = app_get_statusbar()->addProgress(); m_monitor = add_gui_monitor(&Job::monitor_proc, &Job::monitor_free, (void*)this); m_alert_window = Alert::create("%s<<Working...||&Cancel", job_name); }
void MovingPixelsState::onBeforeChangeState(Editor* editor) { ASSERT(m_pixelsMovement != NULL); // If we are changing to another state, we've to drop the image. if (m_pixelsMovement->isDragging()) m_pixelsMovement->dropImageTemporarily(); // Drop pixels if the user press a button outside the selection m_pixelsMovement->dropImage(); delete m_pixelsMovement; m_pixelsMovement = NULL; editor->releaseMouse(); app_get_statusbar()->hideMovePixelsOptions(); }
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; }
// 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; }
void app_default_statusbar_message() { app_get_statusbar() ->setStatusText(250, "%s %s | %s", PACKAGE, VERSION, COPYRIGHT); }
MovingPixelsState::~MovingPixelsState() { app_get_statusbar()->removeListener(this); delete m_pixelsMovement; }
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); }
bool PaletteView::onProcessMessage(Message* msg) { switch (msg->type) { case JM_REQSIZE: request_size(&msg->reqsize.w, &msg->reqsize.h); return true; case JM_DRAW: { div_t d = div(Palette::MaxColors, m_columns); int cols = m_columns; int rows = d.quot + ((d.rem)? 1: 0); int x, y, u, v; int c, color; BITMAP *bmp; Palette* palette = get_current_palette(); int bordercolor = makecol(255, 255, 255); bmp = create_bitmap(jrect_w(this->rc), jrect_h(this->rc)); clear_to_color(bmp, makecol(0 , 0, 0)); y = this->border_width.t; c = 0; for (v=0; v<rows; v++) { x = this->border_width.l; for (u=0; u<cols; u++) { if (c >= palette->size()) break; if (bitmap_color_depth(ji_screen) == 8) color = c; else color = makecol_depth (bitmap_color_depth(ji_screen), _rgba_getr(palette->getEntry(c)), _rgba_getg(palette->getEntry(c)), _rgba_getb(palette->getEntry(c))); rectfill(bmp, x, y, x+m_boxsize-1, y+m_boxsize-1, color); if (m_selectedEntries[c]) { const int max = Palette::MaxColors; bool top = (c >= m_columns && c-m_columns >= 0 ? m_selectedEntries[c-m_columns]: false); bool bottom = (c < max-m_columns && c+m_columns < max ? m_selectedEntries[c+m_columns]: false); bool left = ((c%m_columns)>0 && c-1 >= 0 ? m_selectedEntries[c-1]: false); bool right = ((c%m_columns)<m_columns-1 && c+1 < max ? m_selectedEntries[c+1]: false); if (!top) hline(bmp, x-1, y-1, x+m_boxsize, bordercolor); if (!bottom) hline(bmp, x-1, y+m_boxsize, x+m_boxsize, bordercolor); if (!left) vline(bmp, x-1, y-1, y+m_boxsize, bordercolor); if (!right) vline(bmp, x+m_boxsize, y-1, y+m_boxsize, bordercolor); } x += m_boxsize+this->child_spacing; c++; } y += m_boxsize+this->child_spacing; } blit(bmp, ji_screen, 0, 0, this->rc->x1, this->rc->y1, bmp->w, bmp->h); destroy_bitmap(bmp); return true; } case JM_BUTTONPRESSED: captureMouse(); /* continue... */ case JM_MOTION: { JRect cpos = jwidget_get_child_rect(this); int req_w, req_h; request_size(&req_w, &req_h); int mouse_x = MID(cpos->x1, msg->mouse.x, cpos->x1+req_w-this->border_width.r-1); int mouse_y = MID(cpos->y1, msg->mouse.y, cpos->y1+req_h-this->border_width.b-1); jrect_free(cpos); Color color = getColorByPosition(mouse_x, mouse_y); if (color.getType() == Color::IndexType) { int idx = color.getIndex(); app_get_statusbar()->showColor(0, "", color, 255); if (hasCapture() && idx != m_currentEntry) { if (!(msg->any.shifts & KB_CTRL_FLAG)) clearSelection(); if (msg->any.shifts & KB_SHIFT_FLAG) selectRange(m_rangeAnchor, idx); else selectColor(idx); // Emit signals jwidget_emit_signal(this, SIGNAL_PALETTE_EDITOR_CHANGE); IndexChange(idx); } } if (hasCapture()) return true; break; } case JM_BUTTONRELEASED: releaseMouse(); return true; case JM_WHEEL: { View* view = View::getView(this); if (view) { gfx::Point scroll = view->getViewScroll(); scroll.y += (jmouse_z(1)-jmouse_z(0)) * 3 * m_boxsize; view->setViewScroll(scroll); } break; } case JM_MOUSELEAVE: app_get_statusbar()->clearText(); break; } return Widget::onProcessMessage(msg); }