summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorTobias Christiansen <tobyase@serenityos.org>2022-03-07 22:36:19 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-08 22:07:12 +0100
commit96829565d81af9cd7490c1bcb21a974610536af5 (patch)
tree7e3b2536d391caa320e7225b88006dad532f529a /Userland/Applications
parenta180b5f442bba8ea90d26dc6d3cd81701ad9fd54 (diff)
downloadserenity-96829565d81af9cd7490c1bcb21a974610536af5.zip
PixelPaint: Keep track of and expose the type of the edited bitmap
This can be either the content bitmap or the mask bitmap.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/PixelPaint/Layer.cpp21
-rw-r--r--Userland/Applications/PixelPaint/Layer.h12
2 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp
index e5905ce9e3..bf90f60b3b 100644
--- a/Userland/Applications/PixelPaint/Layer.cpp
+++ b/Userland/Applications/PixelPaint/Layer.cpp
@@ -179,4 +179,25 @@ void Layer::create_mask()
update_cached_bitmap();
}
+Gfx::Bitmap& Layer::currently_edited_bitmap()
+{
+ switch (edit_mode()) {
+ case EditMode::Mask:
+ if (is_masked())
+ return *mask_bitmap();
+ [[fallthrough]];
+ case EditMode::Content:
+ return content_bitmap();
+ }
+ VERIFY_NOT_REACHED();
+}
+
+void Layer::set_edit_mode(Layer::EditMode mode)
+{
+ if (m_edit_mode == mode)
+ return;
+
+ m_edit_mode = mode;
+}
+
}
diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h
index 613408ac76..74c1cdc65a 100644
--- a/Userland/Applications/PixelPaint/Layer.h
+++ b/Userland/Applications/PixelPaint/Layer.h
@@ -74,6 +74,16 @@ public:
bool is_masked() { return !m_mask_bitmap.is_null(); }
+ enum class EditMode {
+ Content,
+ Mask,
+ };
+
+ EditMode edit_mode() { return m_edit_mode; }
+ void set_edit_mode(EditMode mode);
+
+ Gfx::Bitmap& currently_edited_bitmap();
+
private:
Layer(Image&, NonnullRefPtr<Gfx::Bitmap>, String name);
@@ -90,6 +100,8 @@ private:
int m_opacity_percent { 100 };
+ EditMode m_edit_mode { EditMode::Content };
+
void update_cached_bitmap();
};