Adding selection mark for texture picker

Adding right clic selection mark for swap, but not implemented yet
This commit is contained in:
EIntemporel
2022-08-07 21:05:42 +02:00
parent 8bca6985dd
commit df58d68fde
7 changed files with 156 additions and 5 deletions

View File

@@ -601,6 +601,8 @@ void MapView::setupTexturePainterUi()
Noggit::Ui::selected_texture::set({filename, _context});
texturingTool->_current_texture->set_texture(filename);
TexturePicker->setMainTexture(texturingTool->_current_texture);
TexturePicker->updateSelection();
}
);
@@ -3616,6 +3618,7 @@ void MapView::tick (float dt)
{
// Pick texture
_texture_picker_dock->setVisible(true);
TexturePicker->setMainTexture(texturingTool->_current_texture);
TexturePicker->getTextures(selection);
}
else if (_mod_shift_down && !!Noggit::Ui::selected_texture::get())

View File

@@ -8,9 +8,18 @@ namespace Noggit
{
ClickableLabel::ClickableLabel(QWidget * parent) : QLabel(parent){}
void ClickableLabel::mouseReleaseEvent (QMouseEvent*)
void ClickableLabel::mouseReleaseEvent (QMouseEvent* event)
{
emit clicked();
if (event->button() == Qt::MiddleButton)
emit middleClicked();
if (event->button() == Qt::LeftButton)
emit leftClicked();
if (event->button() == Qt::RightButton)
emit rightClicked();
}
}
}

View File

@@ -3,6 +3,7 @@
#pragma once
#include <QtWidgets/QLabel>
#include <QMouseEvent>
namespace Noggit
{
@@ -17,6 +18,9 @@ namespace Noggit
signals:
void clicked();
void leftClicked();
void rightClicked();
void middleClicked();
protected:
virtual void mouseReleaseEvent (QMouseEvent* event) override;

View File

@@ -20,6 +20,8 @@ namespace Noggit
: ClickableLabel (parent)
, _filename("tileset\\generic\\black.blp")
, _need_update(true)
, _is_selected(false)
, _is_swap_selected(false)
{
QSizePolicy policy (QSizePolicy::Fixed, QSizePolicy::Fixed);
setSizePolicy (policy);
@@ -48,6 +50,25 @@ namespace Noggit
emit texture_updated();
}
QImage current_texture::createBorder(const QColor &color)
{
QImage _border(QSize(128,128), QImage::Format_ARGB32);
_border.fill(qRgba(0,0,0,0));
for (int i = 0; i < _border_size; ++i)
{
for (int n = 0; n < 128; ++n)
{
_border.setPixelColor(QPoint(n, i), color);
_border.setPixelColor(QPoint(n, 127-i), color);
_border.setPixelColor(QPoint(i, n), color);
_border.setPixelColor(QPoint(127-i, n), color);
}
}
return _border;
}
void current_texture::update_texture_if_needed()
{
if (!_need_update)
@@ -58,7 +79,8 @@ namespace Noggit
_need_update = false;
show();
setPixmap (*BLPRenderer::getInstance().render_blp_to_pixmap (_filename, 128, 128));
_texture_save = *BLPRenderer::getInstance().render_blp_to_pixmap(_filename, 128,128);
setPixmap (_texture_save);
setToolTip(QString::fromStdString(_filename));
}
@@ -113,5 +135,41 @@ namespace Noggit
set_texture(filename);
emit texture_dropped(filename);
}
void current_texture::unselect()
{
if (_is_swap_selected)
return;
setPixmap(_texture_save);
_is_selected = false;
}
void current_texture::select()
{
QPixmap _new_pixmap = _texture_save;
QPainter _painter(&_new_pixmap);
_painter.drawImage(QPoint(0,0), createBorder(_border_color));
setPixmap(_new_pixmap);
_is_selected = true;
}
void current_texture::unselectSwap()
{
if (_is_selected)
return;
setPixmap(_texture_save);
_is_swap_selected = false;
}
void current_texture::selectSwap()
{
QPixmap _new_pixmap = _texture_save;
QPainter _painter(&_new_pixmap);
_painter.drawImage(QPoint(0,0), createBorder(_border_swap_color));
setPixmap(_new_pixmap);
_is_swap_selected = true;
}
}
}

View File

@@ -24,9 +24,21 @@ namespace Noggit
class current_texture : public ClickableLabel
{
Q_OBJECT
public:
bool _is_selected;
bool _is_swap_selected;
private:
std::string _filename;
bool _need_update;
QPixmap _texture_save;
const int _border_size = 4;
const QColor _border_color = QColor(82,128,185,255);
const QColor _border_swap_color = QColor(252,186,3,255);
QImage createBorder(const QColor& color);
virtual void resizeEvent (QResizeEvent*) override
{
@@ -52,6 +64,10 @@ namespace Noggit
std::string const& filename() { return _filename; };
void set_texture (std::string const& texture);
void unselect();
void select();
void unselectSwap();
void selectSwap();
void mouseMoveEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;

View File

@@ -25,6 +25,7 @@ namespace Noggit
: widget (parent, Qt::Window)
, layout (new ::QGridLayout(this))
, _chunk (nullptr)
, _main_texture_window(current_texture_window)
{
setWindowTitle ("Texture Picker");
setWindowFlags (Qt::Tool | Qt::WindowStaysOnTopHint);
@@ -32,13 +33,51 @@ namespace Noggit
for (int i = 0; i < 4; i++)
{
current_texture* click_label = new current_texture(false, this);
connect ( click_label, &ClickableLabel::clicked
, [=]
connect ( click_label, &ClickableLabel::leftClicked
, [=]()
{
if (click_label->_is_swap_selected)
return;
setTexture(i, current_texture_window);
for (unsigned long long i = 0; i < _labels.size(); ++i)
{
_labels[i]->unselect();
if (_labels[i] == click_label && !_labels[i]->_is_swap_selected)
_labels[i]->select();
}
}
);
connect(click_label, &ClickableLabel::rightClicked, [=]()
{
if (click_label->_is_selected)
return;
if (click_label->_is_swap_selected)
{
click_label->_is_swap_selected = false;
click_label->unselectSwap();
return;
}
for (unsigned long long i = 0; i < _labels.size(); ++i)
{
_labels[i]->unselectSwap();
if (_labels[i] == click_label && !_labels[i]->_is_selected)
{
_labels[i]->selectSwap();
}
}
});
if (click_label->filename() == current_texture_window->filename())
click_label->select();
layout->addWidget(click_label, 0, i);
_labels.push_back(click_label);
}
@@ -76,6 +115,21 @@ namespace Noggit
}
void texture_picker::updateSelection()
{
for (size_t index; index < _chunk->texture_set->num(); ++index)
{
_labels[index]->unselect();
if (_main_texture_window->filename() == _labels[index]->filename())
_labels[index]->select();
}
}
void texture_picker::setMainTexture(current_texture *tex)
{
_main_texture_window = tex;
}
void texture_picker::getTextures(selection_type lSelection)
{
if (lSelection.index() == eEntry_MapChunk)
@@ -138,9 +192,13 @@ namespace Noggit
for (; index < _chunk->texture_set->num(); ++index)
{
_labels[index]->unselect();
_textures.push_back(_chunk->texture_set->texture(index));
_labels[index]->set_texture(_textures[index]->file_key().filepath());
_labels[index]->show();
if (_main_texture_window->filename() == _labels[index]->filename())
_labels[index]->select();
}
for (; index < 4U; ++index)

View File

@@ -23,6 +23,8 @@ namespace Noggit
public:
texture_picker (current_texture*, QWidget* parent = nullptr);
void updateSelection();
void setMainTexture(current_texture* tex);
void getTextures(selection_type lSelection);
void setTexture(size_t id, current_texture*);
void shiftSelectedTextureLeft();
@@ -36,6 +38,7 @@ namespace Noggit
std::vector<current_texture*> _labels;
std::vector<scoped_blp_texture_reference> _textures;
MapChunk* _chunk;
current_texture* _main_texture_window;
signals:
void set_texture(scoped_blp_texture_reference texture);