| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2018-2022 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2017 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_UI_CONTEXT_BAR_H_INCLUDED |
| 9 | #define APP_UI_CONTEXT_BAR_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/pref/preferences.h" |
| 13 | #include "app/shade.h" |
| 14 | #include "app/tools/active_tool_observer.h" |
| 15 | #include "app/tools/dynamics.h" |
| 16 | #include "app/tools/ink_type.h" |
| 17 | #include "app/tools/tool_loop_modifiers.h" |
| 18 | #include "app/ui/context_bar_observer.h" |
| 19 | #include "app/ui/doc_observer_widget.h" |
| 20 | #include "doc/brush.h" |
| 21 | #include "obs/connection.h" |
| 22 | #include "obs/observable.h" |
| 23 | #include "obs/signal.h" |
| 24 | #include "render/gradient.h" |
| 25 | #include "ui/box.h" |
| 26 | |
| 27 | #include <vector> |
| 28 | |
| 29 | namespace doc { |
| 30 | class Remap; |
| 31 | } |
| 32 | |
| 33 | namespace render { |
| 34 | class DitheringAlgorithmBase; |
| 35 | class DitheringMatrix; |
| 36 | } |
| 37 | |
| 38 | namespace ui { |
| 39 | class Box; |
| 40 | class Button; |
| 41 | class Label; |
| 42 | class TooltipManager; |
| 43 | } |
| 44 | |
| 45 | namespace app { |
| 46 | |
| 47 | namespace tools { |
| 48 | class Ink; |
| 49 | class Tool; |
| 50 | } |
| 51 | |
| 52 | class BrushSlot; |
| 53 | class ColorBar; |
| 54 | class DitheringSelector; |
| 55 | class GradientTypeSelector; |
| 56 | class SamplingSelector; |
| 57 | class Transformation; |
| 58 | |
| 59 | class ContextBar : public DocObserverWidget<ui::HBox> |
| 60 | , public obs::observable<ContextBarObserver> |
| 61 | , public tools::ActiveToolObserver { |
| 62 | public: |
| 63 | ContextBar(ui::TooltipManager* tooltipManager, |
| 64 | ColorBar* colorBar); |
| 65 | ~ContextBar(); |
| 66 | |
| 67 | void updateForActiveTool(); |
| 68 | void updateForTool(tools::Tool* tool); |
| 69 | void updateForMovingPixels(const Transformation& t); |
| 70 | void updateForSelectingBox(const std::string& text); |
| 71 | void updateToolLoopModifiersIndicators(tools::ToolLoopModifiers modifiers); |
| 72 | bool updateSamplingVisibility(tools::Tool* tool = nullptr); |
| 73 | void updateAutoSelectLayer(bool state); |
| 74 | bool isAutoSelectLayer() const; |
| 75 | |
| 76 | void setActiveBrush(const doc::BrushRef& brush); |
| 77 | void setActiveBrushBySlot(tools::Tool* tool, int slot); |
| 78 | doc::BrushRef activeBrush(tools::Tool* tool = nullptr, |
| 79 | tools::Ink* ink = nullptr) const; |
| 80 | void discardActiveBrush(); |
| 81 | |
| 82 | BrushSlot createBrushSlotFromPreferences(); |
| 83 | static doc::BrushRef createBrushFromPreferences( |
| 84 | ToolPreferences::Brush* brushPref = nullptr); |
| 85 | |
| 86 | doc::Remap* createShadeRemap(bool left); |
| 87 | void reverseShadeColors(); |
| 88 | Shade getShade() const; |
| 89 | |
| 90 | void setInkType(tools::InkType type); |
| 91 | |
| 92 | // For gradients |
| 93 | render::DitheringMatrix ditheringMatrix(); |
| 94 | render::DitheringAlgorithmBase* ditheringAlgorithm(); |
| 95 | render::GradientType gradientType(); |
| 96 | |
| 97 | // For freehand with dynamics |
| 98 | const tools::DynamicsOptions& getDynamics() const; |
| 99 | |
| 100 | // Signals |
| 101 | obs::signal<void()> BrushChange; |
| 102 | |
| 103 | protected: |
| 104 | void onInitTheme(ui::InitThemeEvent& ev) override; |
| 105 | void onSizeHint(ui::SizeHintEvent& ev) override; |
| 106 | void onToolSetOpacity(const int& newOpacity); |
| 107 | void onToolSetFreehandAlgorithm(); |
| 108 | void onToolSetContiguous(); |
| 109 | |
| 110 | // ContextObserver impl |
| 111 | void onActiveSiteChange(const Site& site) override; |
| 112 | |
| 113 | // DocObserverWidget overrides |
| 114 | void onDocChange(Doc* doc) override; |
| 115 | |
| 116 | // DocObserver impl |
| 117 | void onAddSlice(DocEvent& ev) override; |
| 118 | void onRemoveSlice(DocEvent& ev) override; |
| 119 | void onSliceNameChange(DocEvent& ev) override; |
| 120 | |
| 121 | private: |
| 122 | void onBrushSizeChange(); |
| 123 | void onBrushAngleChange(); |
| 124 | void onSymmetryModeChange(); |
| 125 | void onFgOrBgColorChange(doc::Brush::ImageColor imageColor); |
| 126 | void onDropPixels(ContextBarObserver::DropAction action); |
| 127 | void updateSliceFields(const Site& site); |
| 128 | |
| 129 | // ActiveToolObserver impl |
| 130 | void onActiveToolChange(tools::Tool* tool) override; |
| 131 | |
| 132 | void setupTooltips(ui::TooltipManager* tooltipManager); |
| 133 | void registerCommands(); |
| 134 | void showBrushes(); |
| 135 | void showDynamics(); |
| 136 | bool needZoomButtons(tools::Tool* tool) const; |
| 137 | |
| 138 | class ZoomButtons; |
| 139 | class BrushBackField; |
| 140 | class BrushTypeField; |
| 141 | class BrushAngleField; |
| 142 | class BrushSizeField; |
| 143 | class ToleranceField; |
| 144 | class ContiguousField; |
| 145 | class PaintBucketSettingsField; |
| 146 | class InkTypeField; |
| 147 | class InkOpacityField; |
| 148 | class InkShadesField; |
| 149 | class SprayWidthField; |
| 150 | class SpraySpeedField; |
| 151 | class SelectionModeField; |
| 152 | class GradientTypeField; |
| 153 | class TransparentColorField; |
| 154 | class PivotField; |
| 155 | class RotAlgorithmField; |
| 156 | class TransformationFields; |
| 157 | class DynamicsField; |
| 158 | class FreehandAlgorithmField; |
| 159 | class BrushPatternField; |
| 160 | class EyedropperField; |
| 161 | class DropPixelsField; |
| 162 | class AutoSelectLayerField; |
| 163 | class SymmetryField; |
| 164 | class SliceFields; |
| 165 | |
| 166 | ZoomButtons* m_zoomButtons; |
| 167 | SamplingSelector* m_samplingSelector; |
| 168 | BrushBackField* m_brushBack; |
| 169 | BrushTypeField* m_brushType; |
| 170 | BrushAngleField* m_brushAngle; |
| 171 | BrushSizeField* m_brushSize; |
| 172 | ui::Label* m_toleranceLabel; |
| 173 | ToleranceField* m_tolerance; |
| 174 | ContiguousField* m_contiguous; |
| 175 | PaintBucketSettingsField* m_paintBucketSettings; |
| 176 | InkTypeField* m_inkType; |
| 177 | ui::Label* m_inkOpacityLabel; |
| 178 | InkOpacityField* m_inkOpacity; |
| 179 | InkShadesField* m_inkShades; |
| 180 | EyedropperField* m_eyedropperField; |
| 181 | AutoSelectLayerField* m_autoSelectLayer; |
| 182 | ui::Box* m_freehandBox; |
| 183 | DynamicsField* m_dynamics; |
| 184 | FreehandAlgorithmField* m_freehandAlgo; |
| 185 | BrushPatternField* m_brushPatternField; |
| 186 | ui::Box* m_sprayBox; |
| 187 | ui::Label* m_sprayLabel; |
| 188 | SprayWidthField* m_sprayWidth; |
| 189 | SpraySpeedField* m_spraySpeed; |
| 190 | ui::Box* m_selectionOptionsBox; |
| 191 | DitheringSelector* m_ditheringSelector; |
| 192 | SelectionModeField* m_selectionMode; |
| 193 | GradientTypeField* m_gradientType; |
| 194 | TransparentColorField* m_transparentColor; |
| 195 | PivotField* m_pivot; |
| 196 | RotAlgorithmField* m_rotAlgo; |
| 197 | TransformationFields* m_transformation = nullptr; |
| 198 | DropPixelsField* m_dropPixels; |
| 199 | doc::BrushRef m_activeBrush; |
| 200 | ui::Label* m_selectBoxHelp; |
| 201 | SymmetryField* m_symmetry; |
| 202 | SliceFields* m_sliceFields; |
| 203 | obs::scoped_connection m_symmModeConn; |
| 204 | obs::scoped_connection m_fgColorConn; |
| 205 | obs::scoped_connection m_bgColorConn; |
| 206 | obs::scoped_connection m_keysConn; |
| 207 | obs::scoped_connection m_dropPixelsConn; |
| 208 | obs::scoped_connection m_sizeConn; |
| 209 | obs::scoped_connection m_angleConn; |
| 210 | obs::scoped_connection m_opacityConn; |
| 211 | obs::scoped_connection m_freehandAlgoConn; |
| 212 | obs::scoped_connection m_contiguousConn; |
| 213 | }; |
| 214 | |
| 215 | } // namespace app |
| 216 | |
| 217 | #endif |
| 218 |