Ejemplo n.º 1
0
//
// overrides
//
void TilesetWidget::mousePressEvent(QMouseEvent * event)
{
    event->accept();

    auto state = MainWindow::getCurrentState();
    if (!state)
        return;

    if (event->button() == Qt::LeftButton)
    {

        auto pos = event->localPos();
        auto tileProperties = state->getTileProperties();
        int tw = tileProperties.size.width();
        int th = tileProperties.size.height();

        int x = (pos.x() - OFFSET) / _pixelSize.width() / 8 / tw;
        int y = (pos.y() - OFFSET) / _pixelSize.height() / 8 / th;

        int tileIndex = x + y * (_columns / tw);

        // quick sanity check
        if (! (tileIndex >= 0 && tileIndex < _maxTiles))
            return;

        if (QGuiApplication::keyboardModifiers() & Qt::ShiftModifier)
        {
            // Click + Shift == select mode
            _selecting = true;

            if (x >= _cursorPos.x())
                x++;
            if (y >= _cursorPos.y())
                y++;

            _selectingSize = {x - _cursorPos.x(),
                              y - _cursorPos.y()};

            // sanity check
            _selectingSize = {
                qBound(-_cursorPos.x(), _selectingSize.width(), _tileColums - _cursorPos.x()),
                qBound(-_cursorPos.y(), _selectingSize.height(), _tileRows - _cursorPos.y())
            };
            update();
        }
        else
        {
            // different and valid tileIndex?
            if (_cursorPos.x() != x || _cursorPos.y() != y)
            {
                _selecting = false;
                _selectingSize = {1,1};

                _cursorPos = {x,y};
                state->setTileIndex(tileIndex);
                update();
            }
        }
    }
}
Ejemplo n.º 2
0
void TilesetWidget::paintEvent(QPaintEvent *event)
{
    auto state = MainWindow::getCurrentState();

    // no open documents?
    if (!state)
        return;

    QPainter painter;

    painter.begin(this);
    painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole()));

    painter.setBrush(QColor(0,0,0));
    painter.setPen(Qt::NoPen);

    QPen pen;
    pen.setColor({149,195,244,255});
    pen.setWidth(hasFocus() ? 3 : 1 );
    pen.setStyle(Qt::PenStyle::SolidLine);

    auto tileProperties = state->getTileProperties();
    int tw = tileProperties.size.width();
    int th = tileProperties.size.height();

    int max_tiles = 256 / (tw*th);

    for (int i=0; i<max_tiles;i++)
    {
        quint8 charIdx = tileProperties.interleaved == 1 ?
                                                    i * tw * th :
                                                    i;

        int w = (i * tw) % _columns;
        int h = th * ((i * tw) / _columns);

        for (int char_idx=0; char_idx < (tw * th); char_idx++)
        {
            int local_w = w + char_idx % tw;
            int local_h = h + char_idx / tw;

            utilsDrawChar(state, &painter, _pixelSize, QPoint(OFFSET, OFFSET), QPoint(local_w, local_h), charIdx);

            charIdx += tileProperties.interleaved;
        }
    }

    painter.setPen(Qt::NoPen);

    paintFocus(painter);
    paintSelectedTile(painter);

    painter.end();
}
Ejemplo n.º 3
0
TilePropertiesDialog::TilePropertiesDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TilePropertiesDialog)
{
    ui->setupUi(this);

    auto state = State::getInstance();
    auto properties = state->getTileProperties();
    ui->spinBoxSizeX->setValue(properties.size.width());
    ui->spinBoxSizeY->setValue(properties.size.height());
    ui->spinBoxInterleaved->setValue(properties.interleaved);
}
Ejemplo n.º 4
0
void BigCharWidget::onTilePropertiesUpdated()
{
    auto state = State::getInstance();
    _tileProperties = state->getTileProperties();

    // keep aspect ratio
    int maxTileSize = qMax(_tileProperties.size.width(), _tileProperties.size.height());
    int minWidgetSize = qMin(size().width(), size().height());
    _pixelSize.setWidth(minWidgetSize / (8*maxTileSize));
    _pixelSize.setHeight(minWidgetSize / (8*maxTileSize));

//    _pixelSize.setWidth(size().width() / (8*_tileProperties.size.width()));
//    _pixelSize.setHeight(size().height() / (8*_tileProperties.size.height()));

    update();
}
Ejemplo n.º 5
0
void TilesetWidget::onTilePropertiesUpdated()
{
    auto state = MainWindow::getCurrentState();
    auto properties = state->getTileProperties();

    _columns = (COLUMNS / properties.size.width()) * properties.size.width();
    _tileColums = _columns / properties.size.width();

    _rows = qCeil((256.0f / _columns) / properties.size.height()) * properties.size.height();
    _tileRows = _rows / properties.size.height();

    _maxTiles = 256 / (properties.size.width() * properties.size.height());

    _sizeHint = QSize(_pixelSize.width() * _columns * 8 + OFFSET * 2,
                 _pixelSize.height() * _rows * 8 + OFFSET * 2);
    update();
}
Ejemplo n.º 6
0
void XlinkPreview::tileUpdated(int tileIndex)
{
    if(!isConnected()) return;

    auto state = State::getInstance();

    State::TileProperties properties = state->getTileProperties();

    int charIndex = state->getCharIndexFromTileIndex(tileIndex);
    int numChars = properties.size.width() * properties.size.height();

    if(properties.interleaved == 1) {
        xlink_load(0xb7, 0x00, 0x3000 + charIndex * 8, (uchar*) state->getCharAtIndex(charIndex), numChars*8);
    }
    else {
        for(int sent=0; sent<numChars; sent++) {
            xlink_load(0xb7, 0x00, 0x3000 + charIndex * 8, (uchar*) state->getCharAtIndex(charIndex), 8);
            charIndex += properties.interleaved;
        }
    }
}
Ejemplo n.º 7
0
void TilesetWidget::mouseMoveEvent(QMouseEvent * event)
{
    event->accept();

    if (event->buttons() == Qt::LeftButton)
    {
        auto state = MainWindow::getCurrentState();

        auto pos = event->localPos();
        auto tileProperties = state->getTileProperties();
        int tw = tileProperties.size.width();
        int th = tileProperties.size.height();

        int x = (pos.x() - OFFSET) / _pixelSize.width() / 8 / tw;
        int y = (pos.y() - OFFSET) / _pixelSize.height() / 8 / th;

        // sanity check
        int tileIndex = x + y * (_columns / tw);
        if (! (tileIndex >= 0 && tileIndex < _maxTiles))
            return;

        if (x >= _cursorPos.x())
            x++;
        if (y >= _cursorPos.y())
            y++;

        _selectingSize = {x - _cursorPos.x(),
                          y - _cursorPos.y()};

        // sanity check
        _selectingSize = {
            qBound(-_cursorPos.x(), _selectingSize.width(), _tileColums-_cursorPos.x()),
            qBound(-_cursorPos.y(), _selectingSize.height(), _tileRows-_cursorPos.y())
        };

        _selecting = true;

        update();
    }
}