/* ASEPRITE * Copyright (C) 2001-2012 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "app.h" #include "app/find_widget.h" #include "app/load_widget.h" #include "base/bind.h" #include "commands/command.h" #include "commands/commands.h" #include "console.h" #include "document_wrappers.h" #include "gfx/size.h" #include "modules/editors.h" #include "modules/gfx.h" #include "modules/gui.h" #include "raster/image.h" #include "raster/mask.h" #include "raster/pen.h" #include "raster/sprite.h" #include "settings/document_settings.h" #include "settings/settings.h" #include "skin/skin_parts.h" #include "tools/ink.h" #include "tools/point_shape.h" #include "tools/tool.h" #include "ui/gui.h" #include "ui_context.h" #include "widgets/button_set.h" #include "widgets/color_button.h" #include "widgets/editor/editor.h" #include "widgets/status_bar.h" #include using namespace gfx; using namespace ui; using namespace tools; static Window* window = NULL; static bool window_close_hook(Widget* widget, void *data); class BrushPreview : public Widget { public: BrushPreview() : Widget(JI_WIDGET) { } protected: bool onProcessMessage(Message* msg) { switch (msg->type) { case JM_DRAW: { BITMAP *bmp = create_bitmap(jrect_w(this->rc), jrect_h(this->rc)); Tool* current_tool = UIContext::instance() ->getSettings() ->getCurrentTool(); IPenSettings* pen_settings = UIContext::instance() ->getSettings() ->getToolSettings(current_tool) ->getPen(); ASSERT(pen_settings != NULL); UniquePtr pen(new Pen(pen_settings->getType(), pen_settings->getSize(), pen_settings->getAngle())); clear_to_color(bmp, makecol(0, 0, 0)); image_to_allegro(pen->get_image(), bmp, bmp->w/2 - pen->get_size()/2, bmp->h/2 - pen->get_size()/2, NULL); blit(bmp, ji_screen, 0, 0, this->rc->x1, this->rc->y1, bmp->w, bmp->h); destroy_bitmap(bmp); return true; } } return Widget::onProcessMessage(msg); } }; // Slot for App::Exit signal static void on_exit_delete_this_widget() { ASSERT(window != NULL); delete window; } static void on_pen_size_after_change() { Slider* brush_size = window->findChildT("brush_size"); BrushPreview* brushPreview = window->findChildT("brush_preview"); ASSERT(brush_size != NULL); Tool* current_tool = UIContext::instance() ->getSettings() ->getCurrentTool(); IToolSettings* tool_settings = UIContext::instance() ->getSettings() ->getToolSettings(current_tool); brush_size->setValue(tool_settings->getPen()->getSize()); // Regenerate the preview brushPreview->invalidate(); } static void on_current_tool_change() { Slider* brush_size = window->findChildT("brush_size"); Slider* brush_angle = window->findChildT("brush_angle"); ButtonSet* brush_type = window->findChildT("brush_type"); BrushPreview* brushPreview = window->findChildT("brush_preview"); Widget* opacity_label = window->findChild("opacity_label"); Slider* opacity = window->findChildT("opacity"); Widget* tolerance_label = window->findChild("tolerance_label"); Slider* tolerance = window->findChildT("tolerance"); Widget* spray_box = window->findChild("spray_box"); Slider* spray_width = window->findChildT("spray_width"); Slider* air_speed = window->findChildT("air_speed"); Tool* current_tool = UIContext::instance() ->getSettings() ->getCurrentTool(); IToolSettings* tool_settings = UIContext::instance() ->getSettings() ->getToolSettings(current_tool); opacity->setValue(tool_settings->getOpacity()); tolerance->setValue(tool_settings->getTolerance()); brush_size->setValue(tool_settings->getPen()->getSize()); brush_angle->setValue(tool_settings->getPen()->getAngle()); spray_width->setValue(tool_settings->getSprayWidth()); air_speed->setValue(tool_settings->getSpraySpeed()); // Select the brush type brush_type->setSelectedItem(tool_settings->getPen()->getType()); // Regenerate the preview brushPreview->invalidate(); // True if the current tool needs opacity options bool hasOpacity = (current_tool->getInk(0)->isPaint() || current_tool->getInk(0)->isEffect() || current_tool->getInk(1)->isPaint() || current_tool->getInk(1)->isEffect()); // True if the current tool needs tolerance options bool hasTolerance = (current_tool->getPointShape(0)->isFloodFill() || current_tool->getPointShape(1)->isFloodFill()); // True if the current tool needs spray options bool hasSprayOptions = (current_tool->getPointShape(0)->isSpray() || current_tool->getPointShape(1)->isSpray()); // Show/Hide parameters opacity_label->setVisible(hasOpacity); opacity->setVisible(hasOpacity); tolerance_label->setVisible(hasTolerance); tolerance->setVisible(hasTolerance); spray_box->setVisible(hasSprayOptions); // Get the required size of the whole window Size reqSize = window->getPreferredSize(); if (jrect_w(window->rc) < reqSize.w || jrect_h(window->rc) != reqSize.h) { JRect rect = jrect_new(window->rc->x1, window->rc->y1, (jrect_w(window->rc) < reqSize.w) ? window->rc->x1 + reqSize.w: window->rc->x2, window->rc->y1 + reqSize.h); // Show the expanded area inside the screen if (rect->y2 > JI_SCREEN_H) jrect_displace(rect, 0, JI_SCREEN_H - rect->y2); window->moveWindow(rect); jrect_free(rect); } else window->setBounds(window->getBounds()); // TODO layout() method is missing // Redraw the window window->invalidate(); } ////////////////////////////////////////////////////////////////////// class ConfigureTools : public Command { public: ConfigureTools(); Command* clone() const { return new ConfigureTools(*this); } protected: void onExecute(Context* context); private: CheckBox* m_tiled; CheckBox* m_tiledX; CheckBox* m_tiledY; CheckBox* m_pixelGrid; CheckBox* m_snapToGrid; CheckBox* m_onionSkin; CheckBox* m_viewGrid; Widget* m_brushPreview; ButtonSet* m_brushType; Slider* m_brushSize; Slider* m_brushAngle; Slider* m_opacity; Slider* m_tolerance; Slider* m_sprayWidth; Slider* m_airSpeed; ISettings* m_settings; IDocumentSettings* m_docSettings; void onWindowClose(); void onTiledClick(); void onTiledXYClick(int tiled_axis, CheckBox* checkbox); void onViewGridClick(); void onPixelGridClick(); void onSetGridClick(); void onSnapToGridClick(); void onOnionSkinClick(); void onBrushSizeSliderChange(); void onBrushAngleSliderChange(); void onOpacitySliderChange(); void onToleranceSliderChange(); void onSprayWidthSliderChange(); void onAirSpeedSliderChange(); void onBrushTypeChange(); }; ConfigureTools::ConfigureTools() : Command("ConfigureTools", "Configure Tools", CmdUIOnlyFlag) { m_settings = NULL; m_docSettings = NULL; } void ConfigureTools::onExecute(Context* context) { m_settings = UIContext::instance()->getSettings(); m_docSettings = m_settings->getDocumentSettings(NULL); Button* set_grid; Widget* brush_preview_box; Widget* brush_type_box; bool first_time = false; if (!window) { window = app::load_widget("tools_configuration.xml", "configure_tool"); first_time = true; } // If the window is opened, close it else if (window->isVisible()) { window->closeWindow(NULL); return; } try { m_tiled = app::find_widget(window, "tiled"); m_tiledX = app::find_widget(window, "tiled_x"); m_tiledY = app::find_widget(window, "tiled_y"); m_snapToGrid = app::find_widget(window, "snap_to_grid"); m_viewGrid = app::find_widget(window, "view_grid"); m_pixelGrid = app::find_widget(window, "pixel_grid"); set_grid = app::find_widget