Add opacity to grid and grid pixel (close #58)

This commit is contained in:
David Capello 2014-11-24 19:13:25 -03:00
parent 4fc28d5639
commit 3437c49f0b
7 changed files with 213 additions and 44 deletions

View File

@ -47,27 +47,40 @@
<!-- Grid & background -->
<vbox id="section_grid">
<separator text="Grid" horizontal="true" />
<grid columns="2">
<grid columns="3">
<label text="Grid Color:" />
<box id="grid_color_box" /><!-- custom widget -->
<box id="grid_color_placeholder" /><!-- custom widget -->
<hbox />
<label text="Pixel Grid:" />
<box id="pixel_grid_color_box" /><!-- custom widget -->
<label text="Grid Opacity:" />
<slider grid_hspan="1" id="grid_opacity" min="1" max="255" width="128" />
<check id="grid_auto_opacity" text="Auto" />
<label text="Pixel Grid Color:" />
<box id="pixel_grid_color_placeholder" /><!-- custom widget -->
<hbox />
<label text="Pixel Grid Opacity:" />
<slider id="pixel_grid_opacity" min="1" max="255" width="128" />
<check id="pixel_grid_auto_opacity" text="Auto" />
</grid>
<separator text="Checked Background" horizontal="true" />
<box horizontal="true">
<hbox>
<label text="Size:" />
<combobox id="checked_bg_size" expansive="true" />
</box>
</hbox>
<check text="Apply Zoom" id="checked_bg_zoom" />
<grid columns="2">
<label text="Color 1" />
<hbox>
<label text="Colors:" />
<box horizontal="true" id="checked_bg_color1_box" />
<label text="Color 2" />
<box horizontal="true" id="checked_bg_color2_box" />
</grid>
<button id="checked_bg_reset" text="Reset" />
</hbox>
<hbox>
<hbox expansive="true" />
<button id="reset" text="Reset" width="60" />
</hbox>
</vbox>
<!-- Undo -->

View File

@ -64,11 +64,15 @@ public:
// Grid color
m_gridColor->setId("grid_color");
gridColorBox()->addChild(m_gridColor);
gridColorPlaceholder()->addChild(m_gridColor);
gridOpacity()->setValue(m_docSettings->getGridOpacity());
gridAutoOpacity()->setSelected(m_docSettings->getGridAutoOpacity());
// Pixel grid color
m_pixelGridColor->setId("pixel_grid_color");
pixelGridColorBox()->addChild(m_pixelGridColor);
pixelGridColorPlaceholder()->addChild(m_pixelGridColor);
pixelGridOpacity()->setValue(m_docSettings->getPixelGridOpacity());
pixelGridAutoOpacity()->setSelected(m_docSettings->getPixelGridAutoOpacity());
// Others
if (get_config_bool("Options", "AutoShowTimeline", true))
@ -122,7 +126,7 @@ public:
checkedBgColor2Box()->addChild(m_checked_bg_color2);
// Reset button
checkedBgReset()->Click.connect(Bind<void>(&OptionsWindow::onResetCheckedBg, this));
reset()->Click.connect(Bind<void>(&OptionsWindow::onReset, this));
// Links
locateFile()->Click.connect(Bind<void>(&OptionsWindow::onLocateConfigFile, this));
@ -149,8 +153,12 @@ public:
void saveConfig() {
Editor::set_cursor_color(m_cursorColor->getColor());
m_docSettings->setGridColor(m_gridColor->getColor());
m_docSettings->setGridOpacity(gridOpacity()->getValue());
m_docSettings->setGridAutoOpacity(gridAutoOpacity()->isSelected());
m_docSettings->setPixelGridColor(m_pixelGridColor->getColor());
m_docSettings->setPixelGridOpacity(pixelGridOpacity()->getValue());
m_docSettings->setPixelGridAutoOpacity(pixelGridAutoOpacity()->isSelected());
set_config_bool("Options", "AutoShowTimeline", autotimeline()->isSelected());
bool expandOnMouseover = expandMenubarOnMouseover()->isSelected();
@ -201,8 +209,19 @@ private:
panel()->showChild(findChild(item->getValue().c_str()));
}
void onResetCheckedBg() {
void onReset() {
// Default values
// TODO improve settings and default values (store everything in
// an XML and generate code from it)
m_gridColor->setColor(app::Color::fromRgb(0, 0, 255));
gridOpacity()->setValue(200);
gridAutoOpacity()->setSelected(true);
m_pixelGridColor->setColor(app::Color::fromRgb(200, 200, 200));
pixelGridOpacity()->setValue(200);
pixelGridAutoOpacity()->setSelected(true);
checkedBgSize()->setSelectedItemIndex((int)RenderEngine::CHECKED_BG_16X16);
checkedBgZoom()->setSelected(true);
m_checked_bg_color1->setColor(app::Color::fromRgb(128, 128, 128));

View File

@ -44,11 +44,15 @@ namespace app {
virtual bool getGridVisible() = 0;
virtual gfx::Rect getGridBounds() = 0;
virtual app::Color getGridColor() = 0;
virtual int getGridOpacity() = 0;
virtual bool getGridAutoOpacity() = 0;
virtual void setSnapToGrid(bool state) = 0;
virtual void setGridVisible(bool state) = 0;
virtual void setGridBounds(const gfx::Rect& rect) = 0;
virtual void setGridColor(const app::Color& color) = 0;
virtual void setGridOpacity(int opacity) = 0;
virtual void setGridAutoOpacity(bool state) = 0;
virtual void snapToGrid(gfx::Point& point) const = 0;
@ -56,9 +60,13 @@ namespace app {
virtual bool getPixelGridVisible() = 0;
virtual app::Color getPixelGridColor() = 0;
virtual int getPixelGridOpacity() = 0;
virtual bool getPixelGridAutoOpacity() = 0;
virtual void setPixelGridVisible(bool state) = 0;
virtual void setPixelGridColor(const app::Color& color) = 0;
virtual void setPixelGridOpacity(int opacity) = 0;
virtual void setPixelGridAutoOpacity(bool state) = 0;
// Onionskin settings

View File

@ -72,8 +72,12 @@ public:
, m_gridVisible(false)
, m_gridBounds(0, 0, 16, 16)
, m_gridColor(app::Color::fromRgb(0, 0, 255))
, m_gridOpacity(200)
, m_gridAutoOpacity(true)
, m_pixelGridVisible(false)
, m_pixelGridColor(app::Color::fromRgb(200, 200, 200))
, m_pixelGridOpacity(200)
, m_pixelGridAutoOpacity(true)
, m_isLoop(false)
, m_loopBegin(0)
, m_loopEnd(1)
@ -103,7 +107,11 @@ public:
}
m_gridColor = get_config_color("Grid", "Color", m_gridColor);
m_gridOpacity = get_config_int("Grid", "Opacity", m_gridOpacity);
m_gridAutoOpacity = get_config_bool("Grid", "AutoOpacity", m_gridAutoOpacity);
m_pixelGridColor = get_config_color("PixelGrid", "Color", m_pixelGridColor);
m_pixelGridOpacity = get_config_int("PixelGrid", "Opacity", m_pixelGridOpacity);
m_pixelGridAutoOpacity = get_config_bool("PixelGrid", "AutoOpacity", m_pixelGridAutoOpacity);
if (specific_file)
pop_config_state();
@ -154,11 +162,15 @@ public:
virtual bool getGridVisible() override;
virtual gfx::Rect getGridBounds() override;
virtual app::Color getGridColor() override;
virtual int getGridOpacity() override;
virtual bool getGridAutoOpacity() override;
virtual void setSnapToGrid(bool state) override;
virtual void setGridVisible(bool state) override;
virtual void setGridBounds(const gfx::Rect& rect) override;
virtual void setGridColor(const app::Color& color) override;
virtual void setGridOpacity(int opacity) override;
virtual void setGridAutoOpacity(bool state) override;
virtual void snapToGrid(gfx::Point& point) const override;
@ -166,9 +178,13 @@ public:
virtual bool getPixelGridVisible() override;
virtual app::Color getPixelGridColor() override;
virtual int getPixelGridOpacity() override;
virtual bool getPixelGridAutoOpacity() override;
virtual void setPixelGridVisible(bool state) override;
virtual void setPixelGridColor(const app::Color& color) override;
virtual void setPixelGridOpacity(int opacity) override;
virtual void setPixelGridAutoOpacity(bool state) override;
// Onionskin settings
@ -203,7 +219,11 @@ public:
private:
void saveSharedSettings() {
set_config_color("Grid", "Color", m_gridColor);
set_config_int("Grid", "Opacity", m_gridOpacity);
set_config_bool("Grid", "AutoOpacity", m_gridAutoOpacity);
set_config_color("PixelGrid", "Color", m_pixelGridColor);
set_config_int("PixelGrid", "Opacity", m_pixelGridOpacity);
set_config_bool("PixelGrid", "AutoOpacity", m_pixelGridAutoOpacity);
}
std::string configFileName() {
@ -242,8 +262,12 @@ private:
bool m_gridVisible;
gfx::Rect m_gridBounds;
app::Color m_gridColor;
int m_gridOpacity;
bool m_gridAutoOpacity;
bool m_pixelGridVisible;
app::Color m_pixelGridColor;
int m_pixelGridOpacity;
bool m_pixelGridAutoOpacity;
bool m_isLoop;
doc::FrameNumber m_loopBegin;
doc::FrameNumber m_loopEnd;
@ -570,6 +594,16 @@ app::Color UIDocumentSettingsImpl::getGridColor()
return m_gridColor;
}
int UIDocumentSettingsImpl::getGridOpacity()
{
return m_gridOpacity;
}
bool UIDocumentSettingsImpl::getGridAutoOpacity()
{
return m_gridAutoOpacity;
}
void UIDocumentSettingsImpl::setSnapToGrid(bool state)
{
m_snapToGrid = state;
@ -596,6 +630,22 @@ void UIDocumentSettingsImpl::setGridColor(const app::Color& color)
saveSharedSettings();
}
void UIDocumentSettingsImpl::setGridOpacity(int opacity)
{
m_gridOpacity = opacity;
notifyObservers<const app::Color&>(&DocumentSettingsObserver::onSetGridColor, m_gridColor);
saveSharedSettings();
}
void UIDocumentSettingsImpl::setGridAutoOpacity(bool state)
{
m_gridAutoOpacity = state;
notifyObservers<const app::Color&>(&DocumentSettingsObserver::onSetGridColor, m_gridColor);
saveSharedSettings();
}
void UIDocumentSettingsImpl::snapToGrid(gfx::Point& point) const
{
int w = m_gridBounds.w;
@ -622,6 +672,16 @@ app::Color UIDocumentSettingsImpl::getPixelGridColor()
return m_pixelGridColor;
}
int UIDocumentSettingsImpl::getPixelGridOpacity()
{
return m_pixelGridOpacity;
}
bool UIDocumentSettingsImpl::getPixelGridAutoOpacity()
{
return m_pixelGridAutoOpacity;
}
void UIDocumentSettingsImpl::setPixelGridVisible(bool state)
{
m_pixelGridVisible = state;
@ -636,6 +696,18 @@ void UIDocumentSettingsImpl::setPixelGridColor(const app::Color& color)
saveSharedSettings();
}
void UIDocumentSettingsImpl::setPixelGridOpacity(int opacity)
{
m_pixelGridOpacity = opacity;
redrawDocumentViews();
}
void UIDocumentSettingsImpl::setPixelGridAutoOpacity(bool state)
{
m_pixelGridAutoOpacity = state;
redrawDocumentViews();
}
bool UIDocumentSettingsImpl::getUseOnionskin()
{
return m_use_onionskin;

View File

@ -472,14 +472,40 @@ void Editor::drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc)
g->fillRegion(theme->getColor(ThemeColor::EditorFace), outside);
}
// Draw the pixel grid
if ((m_zoom.scale() > 1.0) && docSettings->getPixelGridVisible()) {
drawGrid(g, enclosingRect, Rect(0, 0, 1, 1), docSettings->getPixelGridColor());
}
// Grids
{
// Clipping
IntersectClip clip(g, editorToScreen(rc).offset(-getBounds().getOrigin()));
// Draw the grid
if (docSettings->getGridVisible())
drawGrid(g, enclosingRect, docSettings->getGridBounds(), docSettings->getGridColor());
// Draw the pixel grid
if ((m_zoom.scale() > 2.0) && docSettings->getPixelGridVisible()) {
int alpha = docSettings->getPixelGridOpacity();
if (docSettings->getPixelGridAutoOpacity()) {
alpha = int(alpha * (m_zoom.scale()-2.) / (16.-2.));
alpha = MID(0, alpha, 255);
}
drawGrid(g, enclosingRect, Rect(0, 0, 1, 1),
docSettings->getPixelGridColor(), alpha);
}
// Draw the grid
if (docSettings->getGridVisible()) {
int alpha = docSettings->getGridOpacity();
if (docSettings->getGridAutoOpacity()) {
gfx::Rect rc = docSettings->getGridBounds();
double len = (m_zoom.apply(rc.w) + m_zoom.apply(rc.h)) / 2.;
alpha = int(alpha * len / 32.);
alpha = MID(0, alpha, 255);
}
drawGrid(g, enclosingRect, docSettings->getGridBounds(),
docSettings->getGridColor(), alpha);
}
}
if (m_flags & kShowOutside) {
// Draw the borders that enclose the sprite.
@ -503,21 +529,17 @@ void Editor::drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc)
void Editor::drawSpriteClipped(const gfx::Region& updateRegion)
{
Region region;
getDrawableRegion(region, kCutTopWindows);
Region screenRegion;
getDrawableRegion(screenRegion, kCutTopWindows);
ScreenGraphics g;
ScreenGraphics screenGraphics;
GraphicsPtr editorGraphics = getGraphics(getClientBounds());
for (Region::const_iterator
it=region.begin(), end=region.end(); it != end; ++it) {
const Rect& rc = *it;
IntersectClip clip(&g, rc);
if (clip) {
for (Region::const_iterator
it2=updateRegion.begin(), end2=updateRegion.end(); it2 != end2; ++it2) {
drawSpriteUnclippedRect(getGraphics(getClientBounds()), *it2);
}
for (const Rect& updateRect : updateRegion) {
for (const Rect& screenRect : screenRegion) {
IntersectClip clip(&screenGraphics, screenRect);
if (clip)
drawSpriteUnclippedRect(editorGraphics, updateRect);
}
}
}
@ -541,9 +563,9 @@ void Editor::drawMask(Graphics* g)
int nseg = m_document->getBoundariesSegmentsCount();
const BoundSeg* seg = m_document->getBoundariesSegments();
CheckedDrawMode checked(g, m_offset_count);
for (int c=0; c<nseg; ++c, ++seg) {
CheckedDrawMode checked(g, m_offset_count);
x1 = m_zoom.apply(seg->x1);
y1 = m_zoom.apply(seg->y1);
x2 = m_zoom.apply(seg->x2);
@ -576,7 +598,8 @@ void Editor::drawMask(Graphics* g)
}
// The color doesn't matter, we are using CheckedDrawMode
g->drawLine(0, gfx::Point(x+x1, y+y1), gfx::Point(x+x2, y+y2));
g->drawLine(gfx::rgba(0, 0, 0),
gfx::Point(x+x1, y+y1), gfx::Point(x+x2, y+y2));
}
}
@ -601,9 +624,8 @@ void Editor::drawMaskSafe()
GraphicsPtr g = getGraphics(getClientBounds());
for (Region::const_iterator it=region.begin(), end=region.end();
it != end; ++it) {
IntersectClip clip(g, gfx::Rect(*it));
for (const gfx::Rect& rc : region) {
IntersectClip clip(g, rc);
if (clip)
drawMask(g);
}
@ -616,7 +638,7 @@ void Editor::drawMaskSafe()
}
}
void Editor::drawGrid(Graphics* g, const gfx::Rect& spriteBounds, const Rect& gridBounds, const app::Color& color)
void Editor::drawGrid(Graphics* g, const gfx::Rect& spriteBounds, const Rect& gridBounds, const app::Color& color, int alpha)
{
if ((m_flags & kShowGrid) == 0)
return;
@ -648,6 +670,10 @@ void Editor::drawGrid(Graphics* g, const gfx::Rect& spriteBounds, const Rect& gr
// Get the grid's color
gfx::Color grid_color = color_utils::color_for_ui(color);
grid_color = gfx::rgba(
gfx::getr(grid_color),
gfx::getg(grid_color),
gfx::getb(grid_color), alpha);
// Draw horizontal lines
int x1 = spriteBounds.x;

View File

@ -228,7 +228,8 @@ namespace app {
void drawMaskSafe();
void drawMask(ui::Graphics* g);
void drawGrid(ui::Graphics* g, const gfx::Rect& spriteBounds, const gfx::Rect& gridBounds, const app::Color& color);
void drawGrid(ui::Graphics* g, const gfx::Rect& spriteBounds, const gfx::Rect& gridBounds,
const app::Color& color, int alpha);
void editor_setcursor();

View File

@ -272,23 +272,53 @@ namespace she {
}
void drawHLine(gfx::Color color, int x, int y, int w) override {
if (gfx::geta(color) < 255) {
set_trans_blender(0, 0, 0, gfx::geta(color));
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
}
hline(m_bmp, x, y, x+w-1, to_allegro(bitmap_color_depth(m_bmp), color));
solid_mode();
}
void drawVLine(gfx::Color color, int x, int y, int h) override {
if (gfx::geta(color) < 255) {
set_trans_blender(0, 0, 0, gfx::geta(color));
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
}
vline(m_bmp, x, y, y+h-1, to_allegro(bitmap_color_depth(m_bmp), color));
solid_mode();
}
void drawLine(gfx::Color color, const gfx::Point& a, const gfx::Point& b) override {
if (gfx::geta(color) < 255) {
set_trans_blender(0, 0, 0, gfx::geta(color));
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
}
line(m_bmp, a.x, a.y, b.x, b.y, to_allegro(bitmap_color_depth(m_bmp), color));
solid_mode();
}
void drawRect(gfx::Color color, const gfx::Rect& rc) override {
if (gfx::geta(color) < 255) {
set_trans_blender(0, 0, 0, gfx::geta(color));
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
}
rect(m_bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, to_allegro(bitmap_color_depth(m_bmp), color));
solid_mode();
}
void fillRect(gfx::Color color, const gfx::Rect& rc) override {
if (gfx::geta(color) < 255) {
set_trans_blender(0, 0, 0, gfx::geta(color));
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
}
rectfill(m_bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, to_allegro(bitmap_color_depth(m_bmp), color));
solid_mode();
}
void blitTo(LockedSurface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const override {