mirror of
https://github.com/aseprite/aseprite.git
synced 2024-12-29 00:23:48 +00:00
Add sampling options to Edit > Preferences dialog too (#3183)
This commit is contained in:
parent
5ccf414183
commit
b212a24479
@ -1,5 +1,5 @@
|
||||
<!-- Aseprite -->
|
||||
<!-- Copyright (C) 2018-2021 Igara Studio S.A. -->
|
||||
<!-- Copyright (C) 2018-2022 Igara Studio S.A. -->
|
||||
<!-- Copyright (C) 2001-2018 David Capello -->
|
||||
<gui>
|
||||
<window id="options" text="@.title">
|
||||
@ -230,6 +230,7 @@
|
||||
pref="editor.auto_fit" />
|
||||
<check text="@.straight_line_preview" id="straight_line_preview" tooltip="@.straight_line_preview_tooltip" />
|
||||
<check text="@.discard_brush" id="discard_brush" />
|
||||
<hbox id="sampling_placeholder" />
|
||||
<hbox>
|
||||
<label text="@.right_click" />
|
||||
<combobox id="right_click_behavior" expansive="true" />
|
||||
@ -498,7 +499,8 @@
|
||||
<vbox id="section_experimental">
|
||||
<separator text="@.user_interface" horizontal="true" />
|
||||
<hbox>
|
||||
<check text="@.new_render_engine"
|
||||
<check id="new_render_engine"
|
||||
text="@.new_render_engine"
|
||||
pref="experimental.new_render_engine" />
|
||||
<link text="(#1671)" url="https://github.com/aseprite/aseprite/issues/1671" />
|
||||
</hbox>
|
||||
|
@ -375,6 +375,7 @@ if(ENABLE_UI)
|
||||
ui/preview_editor.cpp
|
||||
ui/recent_listbox.cpp
|
||||
ui/resources_listbox.cpp
|
||||
ui/sampling_selector.cpp
|
||||
ui/search_entry.cpp
|
||||
ui/select_accelerator.cpp
|
||||
ui/selection_mode_field.cpp
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "app/ui/color_button.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/pref_widget.h"
|
||||
#include "app/ui/sampling_selector.h"
|
||||
#include "app/ui/separator_in_view.h"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "base/clamp.h"
|
||||
@ -449,8 +450,18 @@ public:
|
||||
|
||||
showHome()->setSelected(m_pref.general.showHome());
|
||||
|
||||
// Right-click
|
||||
// Editor sampling
|
||||
samplingPlaceholder()->addChild(
|
||||
m_samplingSelector = new SamplingSelector(
|
||||
SamplingSelector::Behavior::ChangeOnSave));
|
||||
|
||||
m_samplingSelector->setEnabled(newRenderEngine()->isSelected());
|
||||
newRenderEngine()->Click.connect(
|
||||
[this]{
|
||||
m_samplingSelector->setEnabled(newRenderEngine()->isSelected());
|
||||
});
|
||||
|
||||
// Right-click
|
||||
static_assert(int(app::gen::RightClickMode::PAINT_BGCOLOR) == 0, "");
|
||||
static_assert(int(app::gen::RightClickMode::PICK_FGCOLOR) == 1, "");
|
||||
static_assert(int(app::gen::RightClickMode::ERASE) == 2, "");
|
||||
@ -618,6 +629,8 @@ public:
|
||||
m_pref.editor.straightLinePreview(straightLinePreview()->isSelected());
|
||||
m_pref.eyedropper.discardBrush(discardBrush()->isSelected());
|
||||
m_pref.editor.rightClickMode(static_cast<app::gen::RightClickMode>(rightClickBehavior()->getSelectedItemIndex()));
|
||||
if (m_samplingSelector)
|
||||
m_samplingSelector->save();
|
||||
m_pref.cursor.paintingCursorType(static_cast<app::gen::PaintingCursorType>(paintingCursorType()->getSelectedItemIndex()));
|
||||
m_pref.cursor.cursorColor(cursorColor()->getColor());
|
||||
m_pref.cursor.brushPreview(static_cast<app::gen::BrushPreview>(brushPreview()->getSelectedItemIndex()));
|
||||
@ -1628,6 +1641,7 @@ private:
|
||||
int m_restoreUIScaling;
|
||||
std::vector<os::ColorSpaceRef> m_colorSpaces;
|
||||
std::string m_templateTextForDisplayCS;
|
||||
SamplingSelector* m_samplingSelector = nullptr;
|
||||
};
|
||||
|
||||
class OptionsCommand : public Command {
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "app/ui/editor/editor.h"
|
||||
#include "app/ui/icon_button.h"
|
||||
#include "app/ui/keyboard_shortcuts.h"
|
||||
#include "app/ui/sampling_selector.h"
|
||||
#include "app/ui/selection_mode_field.h"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "app/ui_context.h"
|
||||
@ -134,49 +135,6 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
class ContextBar::SamplingOptions : public HBox {
|
||||
public:
|
||||
class Item : public ListItem {
|
||||
public:
|
||||
Item(const char* label,
|
||||
const gen::Downsampling sampling)
|
||||
: ListItem(label)
|
||||
, m_sampling(sampling) {
|
||||
}
|
||||
const gen::Downsampling& sampling() const { return m_sampling; }
|
||||
private:
|
||||
gen::Downsampling m_sampling;
|
||||
};
|
||||
|
||||
SamplingOptions()
|
||||
: m_downsamplingLabel("Downsampling:")
|
||||
{
|
||||
addChild(&m_downsamplingLabel);
|
||||
addChild(&m_downsampling);
|
||||
|
||||
m_downsampling.addItem(new Item("Nearest", gen::Downsampling::NEAREST));
|
||||
m_downsampling.addItem(new Item("Bilinear", gen::Downsampling::BILINEAR));
|
||||
m_downsampling.addItem(new Item("Bilinear mipmapping", gen::Downsampling::BILINEAR_MIPMAP));
|
||||
m_downsampling.addItem(new Item("Trilinear mipmapping", gen::Downsampling::TRILINEAR_MIPMAP));
|
||||
m_downsampling.setSelectedItemIndex(
|
||||
(int)Preferences::instance().editor.downsampling());
|
||||
|
||||
m_downsampling.Change.connect([this]{ onDownsamplingChange(); });
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void onDownsamplingChange() {
|
||||
if (auto item = dynamic_cast<Item*>(m_downsampling.getSelectedItem())) {
|
||||
Preferences::instance().editor.downsampling(
|
||||
item->sampling());
|
||||
}
|
||||
}
|
||||
|
||||
Label m_downsamplingLabel;
|
||||
ComboBox m_downsampling;
|
||||
};
|
||||
|
||||
class ContextBar::BrushBackField : public ButtonSet {
|
||||
public:
|
||||
BrushBackField()
|
||||
@ -1581,7 +1539,7 @@ ContextBar::ContextBar(TooltipManager* tooltipManager,
|
||||
m_selectionOptionsBox->addChild(m_rotAlgo = new RotAlgorithmField());
|
||||
|
||||
addChild(m_zoomButtons = new ZoomButtons);
|
||||
addChild(m_samplingOptions = new SamplingOptions);
|
||||
addChild(m_samplingSelector = new SamplingSelector);
|
||||
|
||||
addChild(m_brushBack = new BrushBackField);
|
||||
addChild(m_brushType = new BrushTypeField(this));
|
||||
@ -2034,8 +1992,8 @@ bool ContextBar::updateSamplingVisibility(tools::Tool* tool)
|
||||
current_editor->projection().scaleY() < 1.0) &&
|
||||
current_editor->isUsingNewRenderEngine();
|
||||
|
||||
if (newVisibility == m_samplingOptions->hasFlags(HIDDEN)) {
|
||||
m_samplingOptions->setVisible(newVisibility);
|
||||
if (newVisibility == m_samplingSelector->hasFlags(HIDDEN)) {
|
||||
m_samplingSelector->setVisible(newVisibility);
|
||||
layout();
|
||||
return true;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ namespace app {
|
||||
class ColorBar;
|
||||
class DitheringSelector;
|
||||
class GradientTypeSelector;
|
||||
class SamplingSelector;
|
||||
|
||||
class ContextBar : public DocObserverWidget<ui::HBox>
|
||||
, public obs::observable<ContextBarObserver>
|
||||
@ -133,7 +134,6 @@ namespace app {
|
||||
bool needZoomButtons(tools::Tool* tool) const;
|
||||
|
||||
class ZoomButtons;
|
||||
class SamplingOptions;
|
||||
class BrushBackField;
|
||||
class BrushTypeField;
|
||||
class BrushAngleField;
|
||||
@ -161,7 +161,7 @@ namespace app {
|
||||
class SliceFields;
|
||||
|
||||
ZoomButtons* m_zoomButtons;
|
||||
SamplingOptions* m_samplingOptions;
|
||||
SamplingSelector* m_samplingSelector;
|
||||
BrushBackField* m_brushBack;
|
||||
BrushTypeField* m_brushType;
|
||||
BrushAngleField* m_brushAngle;
|
||||
|
54
src/app/ui/sampling_selector.cpp
Normal file
54
src/app/ui/sampling_selector.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2022 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/ui/sampling_selector.h"
|
||||
|
||||
#include "ui/listitem.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
SamplingSelector::SamplingSelector(Behavior behavior)
|
||||
: m_behavior(behavior)
|
||||
, m_downsamplingLabel("Downsampling:")
|
||||
{
|
||||
addChild(&m_downsamplingLabel);
|
||||
addChild(&m_downsampling);
|
||||
|
||||
m_downsampling.addItem(new ListItem("Nearest"));
|
||||
m_downsampling.addItem(new ListItem("Bilinear"));
|
||||
m_downsampling.addItem(new ListItem("Bilinear mipmapping"));
|
||||
m_downsampling.addItem(new ListItem("Trilinear mipmapping"));
|
||||
m_downsampling.setSelectedItemIndex(
|
||||
(int)Preferences::instance().editor.downsampling());
|
||||
|
||||
if (m_behavior == Behavior::ChangeOnRealTime)
|
||||
m_downsampling.Change.connect([this]{ save(); });
|
||||
|
||||
m_samplingChangeConn =
|
||||
Preferences::instance().editor.downsampling.AfterChange.connect(
|
||||
[this]{ onPreferenceChange(); });
|
||||
}
|
||||
|
||||
void SamplingSelector::save()
|
||||
{
|
||||
const int i = m_downsampling.getSelectedItemIndex();
|
||||
Preferences::instance().editor.downsampling((gen::Downsampling)i);
|
||||
}
|
||||
|
||||
void SamplingSelector::onPreferenceChange()
|
||||
{
|
||||
const int i = (int)Preferences::instance().editor.downsampling();
|
||||
if (m_downsampling.getSelectedItemIndex() != i)
|
||||
m_downsampling.setSelectedItemIndex(i);
|
||||
}
|
||||
|
||||
} // namespace app
|
41
src/app/ui/sampling_selector.h
Normal file
41
src/app/ui/sampling_selector.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2022 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifndef APP_UI_FILE_SELECTOR_H_INCLUDED
|
||||
#define APP_UI_FILE_SELECTOR_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/pref/preferences.h"
|
||||
#include "obs/connection.h"
|
||||
#include "ui/box.h"
|
||||
#include "ui/combobox.h"
|
||||
#include "ui/label.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class SamplingSelector : public ui::HBox {
|
||||
public:
|
||||
enum class Behavior {
|
||||
ChangeOnRealTime,
|
||||
ChangeOnSave
|
||||
};
|
||||
|
||||
SamplingSelector(Behavior behavior = Behavior::ChangeOnRealTime);
|
||||
|
||||
void save();
|
||||
|
||||
private:
|
||||
void onPreferenceChange();
|
||||
|
||||
Behavior m_behavior;
|
||||
ui::Label m_downsamplingLabel;
|
||||
ui::ComboBox m_downsampling;
|
||||
obs::scoped_connection m_samplingChangeConn;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user