mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 09:04:02 +00:00
Add new advanced options in New Sprite dialog to change the pixel ratio
This commit is contained in:
parent
87ef12fbea
commit
73bda9bd19
@ -187,6 +187,8 @@
|
||||
<option id="height" type="int" default="32" />
|
||||
<option id="color_mode" type="doc::PixelFormat" default="doc::IMAGE_RGB" />
|
||||
<option id="background_color" type="int" default="0" />
|
||||
<option id="advanced" type="bool" default="false" />
|
||||
<option id="pixel_ratio" type="std::string" />
|
||||
</section>
|
||||
<section id="text_tool">
|
||||
<option id="font_face" type="std::string" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!-- ASEPRITE -->
|
||||
<!-- Copyright (C) 2001-2013, 2015 by David Capello -->
|
||||
<!-- Copyright (C) 2001-2016 by David Capello -->
|
||||
<gui>
|
||||
<window text="New Sprite" id="new_sprite">
|
||||
<box vertical="true">
|
||||
@ -26,6 +26,18 @@
|
||||
<item text="&Black" icon="icon_black" />
|
||||
</buttonset>
|
||||
|
||||
<check id="advanced_check" text="Advanced Options" />
|
||||
<vbox id="advanced">
|
||||
<grid columns="2">
|
||||
<label text="Pixel Ratio:" />
|
||||
<combobox id="pixel_ratio" cell_align="horizontal">
|
||||
<listitem text="Square Pixels (1:1)" value="1:1" />
|
||||
<listitem text="Double-wide Pixels (2:1)" value="2:1" />
|
||||
<listitem text="Double-high Pixels (1:2)" value="1:2" />
|
||||
</combobox>
|
||||
</grid>
|
||||
</vbox>
|
||||
|
||||
<box horizontal="true">
|
||||
<box horizontal="true" expansive="true" />
|
||||
<box horizontal="true" homogeneous="true">
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -22,6 +22,9 @@
|
||||
#include "app/ui/workspace.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "app/util/clipboard.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/split_string.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/image.h"
|
||||
@ -102,6 +105,26 @@ void NewFileCommand::onExecute(Context* context)
|
||||
// Select background color
|
||||
window.bgColor()->setSelectedItem(bg);
|
||||
|
||||
// Advance options
|
||||
bool advanced = pref.newFile.advanced();
|
||||
window.advancedCheck()->setSelected(advanced);
|
||||
window.advancedCheck()->Click.connect(
|
||||
base::Bind<void>(
|
||||
[&]{
|
||||
gfx::Rect bounds = window.bounds();
|
||||
window.advanced()->setVisible(window.advancedCheck()->isSelected());
|
||||
window.setBounds(gfx::Rect(window.bounds().origin(),
|
||||
window.sizeHint()));
|
||||
window.layout();
|
||||
|
||||
window.manager()->invalidateRect(bounds);
|
||||
}));
|
||||
window.advanced()->setVisible(advanced);
|
||||
if (advanced)
|
||||
window.pixelRatio()->setValue(pref.newFile.pixelRatio());
|
||||
else
|
||||
window.pixelRatio()->setValue("1:1");
|
||||
|
||||
// Open the window
|
||||
window.openWindowInForeground();
|
||||
|
||||
@ -136,6 +159,8 @@ void NewFileCommand::onExecute(Context* context)
|
||||
pref.newFile.height(h);
|
||||
pref.newFile.colorMode(format);
|
||||
pref.newFile.backgroundColor(bg);
|
||||
pref.newFile.advanced(window.advancedCheck()->isSelected());
|
||||
pref.newFile.pixelRatio(window.pixelRatio()->getValue());
|
||||
|
||||
// Create the new sprite
|
||||
ASSERT(format == IMAGE_RGB || format == IMAGE_GRAYSCALE || format == IMAGE_INDEXED);
|
||||
@ -143,6 +168,22 @@ void NewFileCommand::onExecute(Context* context)
|
||||
|
||||
base::UniquePtr<Sprite> sprite(Sprite::createBasicSprite(format, w, h, ncolors));
|
||||
|
||||
if (window.advancedCheck()->isSelected()) {
|
||||
std::string value = window.pixelRatio()->getValue();
|
||||
std::vector<std::string> parts;
|
||||
base::split_string(value, parts, ":");
|
||||
PixelRatio pixelRatio(1, 1);
|
||||
|
||||
if (parts.size() == 2) {
|
||||
pixelRatio.w = base::convert_to<int>(parts[0]);
|
||||
pixelRatio.h = base::convert_to<int>(parts[1]);
|
||||
pixelRatio.w = MAX(1, pixelRatio.w);
|
||||
pixelRatio.h = MAX(1, pixelRatio.h);
|
||||
}
|
||||
|
||||
sprite->setPixelRatio(pixelRatio);
|
||||
}
|
||||
|
||||
if (sprite->pixelFormat() != IMAGE_GRAYSCALE)
|
||||
get_default_palette()->copyColorsTo(sprite->palette(frame_t(0)));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user