mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
PixelPaint: Add selection functionality to the LayerListWidget
Now we can get rid of the old table view and with it the LayerModel.
This commit is contained in:
parent
e4b11a23b7
commit
18d68c8c94
10 changed files with 77 additions and 185 deletions
|
@ -7,7 +7,6 @@ set(SOURCES
|
||||||
ImageEditor.cpp
|
ImageEditor.cpp
|
||||||
Layer.cpp
|
Layer.cpp
|
||||||
LayerListWidget.cpp
|
LayerListWidget.cpp
|
||||||
LayerModel.cpp
|
|
||||||
LineTool.cpp
|
LineTool.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
MoveTool.cpp
|
MoveTool.cpp
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
#include "LayerModel.h"
|
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
|
||||||
//#define PAINT_DEBUG
|
//#define PAINT_DEBUG
|
||||||
|
@ -72,13 +71,6 @@ void Image::add_layer(NonnullRefPtr<Layer> layer)
|
||||||
client->image_did_add_layer(m_layers.size() - 1);
|
client->image_did_add_layer(m_layers.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::Model& Image::layer_model()
|
|
||||||
{
|
|
||||||
if (!m_layer_model)
|
|
||||||
m_layer_model = LayerModel::create(*this);
|
|
||||||
return *m_layer_model;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Image::index_of(const Layer& layer) const
|
size_t Image::index_of(const Layer& layer) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_layers.size(); ++i) {
|
for (size_t i = 0; i < m_layers.size(); ++i) {
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
|
|
||||||
size_t layer_count() const { return m_layers.size(); }
|
size_t layer_count() const { return m_layers.size(); }
|
||||||
const Layer& layer(size_t index) const { return m_layers.at(index); }
|
const Layer& layer(size_t index) const { return m_layers.at(index); }
|
||||||
|
Layer& layer(size_t index) { return m_layers.at(index); }
|
||||||
|
|
||||||
const Gfx::Size& size() const { return m_size; }
|
const Gfx::Size& size() const { return m_size; }
|
||||||
Gfx::Rect rect() const { return { {}, m_size }; }
|
Gfx::Rect rect() const { return { {}, m_size }; }
|
||||||
|
@ -63,8 +64,6 @@ public:
|
||||||
|
|
||||||
void paint_into(GUI::Painter&, const Gfx::Rect& dest_rect);
|
void paint_into(GUI::Painter&, const Gfx::Rect& dest_rect);
|
||||||
|
|
||||||
GUI::Model& layer_model();
|
|
||||||
|
|
||||||
void move_layer_to_front(Layer&);
|
void move_layer_to_front(Layer&);
|
||||||
void move_layer_to_back(Layer&);
|
void move_layer_to_back(Layer&);
|
||||||
void move_layer_up(Layer&);
|
void move_layer_up(Layer&);
|
||||||
|
@ -77,17 +76,16 @@ public:
|
||||||
|
|
||||||
void layer_did_modify_bitmap(Badge<Layer>, const Layer&);
|
void layer_did_modify_bitmap(Badge<Layer>, const Layer&);
|
||||||
|
|
||||||
|
size_t index_of(const Layer&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Image(const Gfx::Size&);
|
explicit Image(const Gfx::Size&);
|
||||||
|
|
||||||
void did_change();
|
void did_change();
|
||||||
void did_modify_layer_stack();
|
void did_modify_layer_stack();
|
||||||
|
|
||||||
size_t index_of(const Layer&) const;
|
|
||||||
|
|
||||||
Gfx::Size m_size;
|
Gfx::Size m_size;
|
||||||
NonnullRefPtrVector<Layer> m_layers;
|
NonnullRefPtrVector<Layer> m_layers;
|
||||||
RefPtr<GUI::Model> m_layer_model;
|
|
||||||
|
|
||||||
HashTable<ImageClient*> m_clients;
|
HashTable<ImageClient*> m_clients;
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "ImageEditor.h"
|
#include "ImageEditor.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
#include "LayerModel.h"
|
|
||||||
#include "Tool.h"
|
#include "Tool.h"
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/FloatRect.h>
|
#include <LibGfx/FloatRect.h>
|
||||||
|
@ -268,7 +267,7 @@ void ImageEditor::set_active_layer(Layer* layer)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (on_active_layer_change)
|
if (on_active_layer_change)
|
||||||
on_active_layer_change(m_image->layer_model().index(index));
|
on_active_layer_change(layer);
|
||||||
} else {
|
} else {
|
||||||
if (on_active_layer_change)
|
if (on_active_layer_change)
|
||||||
on_active_layer_change({});
|
on_active_layer_change({});
|
||||||
|
@ -293,7 +292,6 @@ void ImageEditor::set_active_tool(Tool* tool)
|
||||||
|
|
||||||
void ImageEditor::layers_did_change()
|
void ImageEditor::layers_did_change()
|
||||||
{
|
{
|
||||||
static_cast<LayerModel&>(m_image->layer_model()).update_without_invalidating_indexes();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
Function<void(Color)> on_primary_color_change;
|
Function<void(Color)> on_primary_color_change;
|
||||||
Function<void(Color)> on_secondary_color_change;
|
Function<void(Color)> on_secondary_color_change;
|
||||||
|
|
||||||
Function<void(const GUI::ModelIndex&)> on_active_layer_change;
|
Function<void(Layer*)> on_active_layer_change;
|
||||||
|
|
||||||
Gfx::FloatRect layer_rect_to_editor_rect(const Layer&, const Gfx::Rect&) const;
|
Gfx::FloatRect layer_rect_to_editor_rect(const Layer&, const Gfx::Rect&) const;
|
||||||
Gfx::FloatRect image_rect_to_editor_rect(const Gfx::Rect&) const;
|
Gfx::FloatRect image_rect_to_editor_rect(const Gfx::Rect&) const;
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
#include "LayerListWidget.h"
|
#include "LayerListWidget.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
#include "ImageEditor.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
#include <LibGUI/Model.h>
|
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ void LayerListWidget::rebuild_gadgets()
|
||||||
m_gadgets.clear();
|
m_gadgets.clear();
|
||||||
if (m_image) {
|
if (m_image) {
|
||||||
for (size_t layer_index = 0; layer_index < m_image->layer_count(); ++layer_index) {
|
for (size_t layer_index = 0; layer_index < m_image->layer_count(); ++layer_index) {
|
||||||
m_gadgets.append({ layer_index, {}, {}, false, {} });
|
m_gadgets.append({ layer_index, {}, {}, false, false, {} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
relayout_gadgets();
|
relayout_gadgets();
|
||||||
|
@ -92,7 +92,12 @@ void LayerListWidget::paint_event(GUI::PaintEvent& event)
|
||||||
|
|
||||||
if (gadget.is_moving) {
|
if (gadget.is_moving) {
|
||||||
adjusted_rect.move_by(0, gadget.movement_delta.y());
|
adjusted_rect.move_by(0, gadget.movement_delta.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gadget.is_moving) {
|
||||||
painter.fill_rect(adjusted_rect, palette().threed_shadow1());
|
painter.fill_rect(adjusted_rect, palette().threed_shadow1());
|
||||||
|
} else if (gadget.is_selected) {
|
||||||
|
painter.fill_rect(adjusted_rect, palette().selection());
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.draw_rect(adjusted_rect, Color::Black);
|
painter.draw_rect(adjusted_rect, Color::Black);
|
||||||
|
@ -104,7 +109,7 @@ void LayerListWidget::paint_event(GUI::PaintEvent& event)
|
||||||
Gfx::Rect text_rect { thumbnail_rect.right() + 10, adjusted_rect.y(), adjusted_rect.width(), adjusted_rect.height() };
|
Gfx::Rect text_rect { thumbnail_rect.right() + 10, adjusted_rect.y(), adjusted_rect.width(), adjusted_rect.height() };
|
||||||
text_rect.intersect(adjusted_rect);
|
text_rect.intersect(adjusted_rect);
|
||||||
|
|
||||||
painter.draw_text(text_rect, layer.name(), Gfx::TextAlignment::CenterLeft);
|
painter.draw_text(text_rect, layer.name(), Gfx::TextAlignment::CenterLeft, gadget.is_selected ? palette().selection_text() : palette().button_text());
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& gadget : m_gadgets) {
|
for (auto& gadget : m_gadgets) {
|
||||||
|
@ -132,11 +137,16 @@ void LayerListWidget::mousedown_event(GUI::MouseEvent& event)
|
||||||
if (event.button() != GUI::MouseButton::Left)
|
if (event.button() != GUI::MouseButton::Left)
|
||||||
return;
|
return;
|
||||||
auto gadget_index = gadget_at(event.position());
|
auto gadget_index = gadget_at(event.position());
|
||||||
if (!gadget_index.has_value())
|
if (!gadget_index.has_value()) {
|
||||||
|
if (on_layer_select)
|
||||||
|
on_layer_select(nullptr);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
m_moving_gadget_index = gadget_index;
|
m_moving_gadget_index = gadget_index;
|
||||||
m_moving_event_origin = event.position();
|
m_moving_event_origin = event.position();
|
||||||
auto& gadget = m_gadgets[m_moving_gadget_index.value()];
|
auto& gadget = m_gadgets[m_moving_gadget_index.value()];
|
||||||
|
if (on_layer_select)
|
||||||
|
on_layer_select(&m_image->layer(gadget_index.value()));
|
||||||
gadget.is_moving = true;
|
gadget.is_moving = true;
|
||||||
gadget.movement_delta = {};
|
gadget.movement_delta = {};
|
||||||
update();
|
update();
|
||||||
|
@ -180,7 +190,7 @@ void LayerListWidget::image_did_add_layer(size_t layer_index)
|
||||||
m_gadgets[m_moving_gadget_index.value()].is_moving = false;
|
m_gadgets[m_moving_gadget_index.value()].is_moving = false;
|
||||||
m_moving_gadget_index = {};
|
m_moving_gadget_index = {};
|
||||||
}
|
}
|
||||||
Gadget gadget { layer_index, {}, {}, false, {} };
|
Gadget gadget { layer_index, {}, {}, false, false, {} };
|
||||||
m_gadgets.insert(layer_index, move(gadget));
|
m_gadgets.insert(layer_index, move(gadget));
|
||||||
relayout_gadgets();
|
relayout_gadgets();
|
||||||
}
|
}
|
||||||
|
@ -217,6 +227,28 @@ size_t LayerListWidget::hole_index_during_move() const
|
||||||
return center_y_of_moving_gadget / vertical_step;
|
return center_y_of_moving_gadget / vertical_step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LayerListWidget::select_bottom_layer()
|
||||||
|
{
|
||||||
|
if (!m_image || !m_image->layer_count())
|
||||||
|
return;
|
||||||
|
set_selected_layer(&m_image->layer(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayerListWidget::select_top_layer()
|
||||||
|
{
|
||||||
|
if (!m_image || !m_image->layer_count())
|
||||||
|
return;
|
||||||
|
set_selected_layer(&m_image->layer(m_image->layer_count() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayerListWidget::move_selection(int delta)
|
||||||
|
{
|
||||||
|
if (!m_image || !m_image->layer_count())
|
||||||
|
return;
|
||||||
|
int new_layer_index = min(max(0, (int)m_image->layer_count() + delta), (int)m_image->layer_count() - 1);
|
||||||
|
set_selected_layer(&m_image->layer(new_layer_index));
|
||||||
|
}
|
||||||
|
|
||||||
void LayerListWidget::relayout_gadgets()
|
void LayerListWidget::relayout_gadgets()
|
||||||
{
|
{
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
@ -239,4 +271,23 @@ void LayerListWidget::relayout_gadgets()
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LayerListWidget::set_selected_layer(Layer* layer)
|
||||||
|
{
|
||||||
|
if (!m_image)
|
||||||
|
return;
|
||||||
|
if (!layer) {
|
||||||
|
for (auto& gadget : m_gadgets)
|
||||||
|
gadget.is_selected = false;
|
||||||
|
} else {
|
||||||
|
auto layer_index = m_image->index_of(*layer);
|
||||||
|
for (auto& gadget : m_gadgets) {
|
||||||
|
if (gadget.layer_index == layer_index)
|
||||||
|
gadget.is_selected = true;
|
||||||
|
else
|
||||||
|
gadget.is_selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,13 @@ public:
|
||||||
|
|
||||||
void set_image(Image*);
|
void set_image(Image*);
|
||||||
|
|
||||||
|
void set_selected_layer(Layer*);
|
||||||
|
Function<void(Layer*)> on_layer_select;
|
||||||
|
|
||||||
|
void select_bottom_layer();
|
||||||
|
void select_top_layer();
|
||||||
|
void move_selection(int delta);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit LayerListWidget();
|
explicit LayerListWidget();
|
||||||
|
|
||||||
|
@ -65,6 +72,7 @@ private:
|
||||||
Gfx::Rect rect;
|
Gfx::Rect rect;
|
||||||
Gfx::Rect temporary_rect_during_move;
|
Gfx::Rect temporary_rect_during_move;
|
||||||
bool is_moving { false };
|
bool is_moving { false };
|
||||||
|
bool is_selected { false };
|
||||||
Gfx::Point movement_delta;
|
Gfx::Point movement_delta;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "LayerModel.h"
|
|
||||||
#include "Image.h"
|
|
||||||
#include "Layer.h"
|
|
||||||
|
|
||||||
namespace PixelPaint {
|
|
||||||
|
|
||||||
NonnullRefPtr<LayerModel> LayerModel::create(Image& image)
|
|
||||||
{
|
|
||||||
return adopt(*new LayerModel(image));
|
|
||||||
}
|
|
||||||
|
|
||||||
LayerModel::LayerModel(Image& image)
|
|
||||||
: m_image(image)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int LayerModel::row_count(const GUI::ModelIndex&) const
|
|
||||||
{
|
|
||||||
return m_image.layer_count();
|
|
||||||
}
|
|
||||||
|
|
||||||
String LayerModel::column_name(int column) const
|
|
||||||
{
|
|
||||||
switch (column) {
|
|
||||||
case Column::Name:
|
|
||||||
return "Name";
|
|
||||||
case Column::Size:
|
|
||||||
return "Size";
|
|
||||||
case Column::Location:
|
|
||||||
return "Location";
|
|
||||||
}
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
GUI::Variant LayerModel::data(const GUI::ModelIndex& index, Role role) const
|
|
||||||
{
|
|
||||||
auto& layer = m_image.layer(index.row());
|
|
||||||
if (role == Role::Display) {
|
|
||||||
switch (index.column()) {
|
|
||||||
case Column::Name:
|
|
||||||
return layer.name();
|
|
||||||
case Column::Size:
|
|
||||||
return layer.size();
|
|
||||||
case Column::Location:
|
|
||||||
return layer.location();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <LibGUI/Model.h>
|
|
||||||
|
|
||||||
namespace PixelPaint {
|
|
||||||
|
|
||||||
class Image;
|
|
||||||
|
|
||||||
class LayerModel final : public GUI::Model {
|
|
||||||
public:
|
|
||||||
enum Column {
|
|
||||||
Name,
|
|
||||||
Size,
|
|
||||||
Location,
|
|
||||||
__Count
|
|
||||||
};
|
|
||||||
|
|
||||||
static NonnullRefPtr<LayerModel> create(Image&);
|
|
||||||
|
|
||||||
virtual int row_count(const GUI::ModelIndex&) const override;
|
|
||||||
virtual int column_count(const GUI::ModelIndex&) const override { return Column::__Count; }
|
|
||||||
virtual String column_name(int) const override;
|
|
||||||
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
|
|
||||||
virtual void update() override { did_update(); }
|
|
||||||
|
|
||||||
void update_without_invalidating_indexes() { did_update(0); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
explicit LayerModel(Image&);
|
|
||||||
|
|
||||||
Image& m_image;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/MenuBar.h>
|
#include <LibGUI/MenuBar.h>
|
||||||
#include <LibGUI/MessageBox.h>
|
#include <LibGUI/MessageBox.h>
|
||||||
#include <LibGUI/Model.h>
|
|
||||||
#include <LibGUI/TableView.h>
|
#include <LibGUI/TableView.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
|
@ -90,8 +89,6 @@ int main(int argc, char** argv)
|
||||||
right_panel.set_preferred_size(230, 0);
|
right_panel.set_preferred_size(230, 0);
|
||||||
right_panel.set_layout<GUI::VerticalBoxLayout>();
|
right_panel.set_layout<GUI::VerticalBoxLayout>();
|
||||||
|
|
||||||
auto& layer_table_view = right_panel.add<GUI::TableView>();
|
|
||||||
|
|
||||||
auto& layer_list_widget = right_panel.add<PixelPaint::LayerListWidget>();
|
auto& layer_list_widget = right_panel.add<PixelPaint::LayerListWidget>();
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
@ -145,22 +142,22 @@ int main(int argc, char** argv)
|
||||||
layer_menu.add_separator();
|
layer_menu.add_separator();
|
||||||
layer_menu.add_action(GUI::Action::create(
|
layer_menu.add_action(GUI::Action::create(
|
||||||
"Select previous layer", { 0, Key_PageUp }, [&](auto&) {
|
"Select previous layer", { 0, Key_PageUp }, [&](auto&) {
|
||||||
layer_table_view.move_selection(1);
|
layer_list_widget.move_selection(1);
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
layer_menu.add_action(GUI::Action::create(
|
layer_menu.add_action(GUI::Action::create(
|
||||||
"Select next layer", { 0, Key_PageDown }, [&](auto&) {
|
"Select next layer", { 0, Key_PageDown }, [&](auto&) {
|
||||||
layer_table_view.move_selection(-1);
|
layer_list_widget.move_selection(-1);
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
layer_menu.add_action(GUI::Action::create(
|
layer_menu.add_action(GUI::Action::create(
|
||||||
"Select top layer", { 0, Key_Home }, [&](auto&) {
|
"Select top layer", { 0, Key_Home }, [&](auto&) {
|
||||||
layer_table_view.selection().set(layer_table_view.model()->index(image_editor.image()->layer_count() - 1));
|
layer_list_widget.select_top_layer();
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
layer_menu.add_action(GUI::Action::create(
|
layer_menu.add_action(GUI::Action::create(
|
||||||
"Select bottom layer", { 0, Key_End }, [&](auto&) {
|
"Select bottom layer", { 0, Key_End }, [&](auto&) {
|
||||||
layer_table_view.selection().set(layer_table_view.model()->index(0));
|
layer_list_widget.select_bottom_layer();
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
layer_menu.add_separator();
|
layer_menu.add_separator();
|
||||||
|
@ -170,8 +167,6 @@ int main(int argc, char** argv)
|
||||||
if (!active_layer)
|
if (!active_layer)
|
||||||
return;
|
return;
|
||||||
image_editor.image()->move_layer_up(*active_layer);
|
image_editor.image()->move_layer_up(*active_layer);
|
||||||
layer_table_view.move_selection(1);
|
|
||||||
image_editor.layers_did_change();
|
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
layer_menu.add_action(GUI::Action::create(
|
layer_menu.add_action(GUI::Action::create(
|
||||||
|
@ -180,8 +175,6 @@ int main(int argc, char** argv)
|
||||||
if (!active_layer)
|
if (!active_layer)
|
||||||
return;
|
return;
|
||||||
image_editor.image()->move_layer_down(*active_layer);
|
image_editor.image()->move_layer_down(*active_layer);
|
||||||
layer_table_view.move_selection(-1);
|
|
||||||
image_editor.layers_did_change();
|
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
layer_menu.add_separator();
|
layer_menu.add_separator();
|
||||||
|
@ -191,8 +184,6 @@ int main(int argc, char** argv)
|
||||||
if (!active_layer)
|
if (!active_layer)
|
||||||
return;
|
return;
|
||||||
image_editor.image()->remove_layer(*active_layer);
|
image_editor.image()->remove_layer(*active_layer);
|
||||||
image_editor.set_active_layer(nullptr);
|
|
||||||
image_editor.layers_did_change();
|
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
|
|
||||||
|
@ -203,11 +194,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
app.set_menubar(move(menubar));
|
app.set_menubar(move(menubar));
|
||||||
|
|
||||||
image_editor.on_active_layer_change = [&](auto& index) {
|
image_editor.on_active_layer_change = [&](auto* layer) {
|
||||||
if (index.is_valid())
|
layer_list_widget.set_selected_layer(layer);
|
||||||
layer_table_view.selection().set(index);
|
|
||||||
else
|
|
||||||
layer_table_view.selection().clear();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto image = PixelPaint::Image::create_with_size({ 640, 480 });
|
auto image = PixelPaint::Image::create_with_size({ 640, 480 });
|
||||||
|
@ -226,13 +214,8 @@ int main(int argc, char** argv)
|
||||||
image->add_layer(*fg_layer2);
|
image->add_layer(*fg_layer2);
|
||||||
fg_layer2->bitmap().fill(Color::Blue);
|
fg_layer2->bitmap().fill(Color::Blue);
|
||||||
|
|
||||||
layer_table_view.set_model(image->layer_model());
|
layer_list_widget.on_layer_select = [&](auto* layer) {
|
||||||
layer_table_view.on_selection_change = [&] {
|
image_editor.set_active_layer(layer);
|
||||||
auto index = layer_table_view.selection().first();
|
|
||||||
if (index.is_valid())
|
|
||||||
image_editor.set_active_layer(const_cast<PixelPaint::Layer*>(&image->layer(index.row())));
|
|
||||||
else
|
|
||||||
image_editor.set_active_layer(nullptr);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
layer_list_widget.set_image(image);
|
layer_list_widget.set_image(image);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue