예제 #1
0
void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode)
{
    for(const OTMLNodePtr& node : styleNode->children()) {
        if(node->tag() == "image-source")
            setImageSource(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "image-offset-x")
            setImageOffsetX(node->value<int>());
        else if(node->tag() == "image-offset-y")
            setImageOffsetY(node->value<int>());
        else if(node->tag() == "image-offset")
            setImageOffset(node->value<Point>());
        else if(node->tag() == "image-width")
            setImageWidth(node->value<int>());
        else if(node->tag() == "image-height")
            setImageHeight(node->value<int>());
        else if(node->tag() == "image-size")
            setImageSize(node->value<Size>());
        else if(node->tag() == "image-rect")
            setImageRect(node->value<Rect>());
        else if(node->tag() == "image-clip")
            setImageClip(node->value<Rect>());
        else if(node->tag() == "image-fixed-ratio")
            setImageFixedRatio(node->value<bool>());
        else if(node->tag() == "image-repeated")
            setImageRepeated(node->value<bool>());
        else if(node->tag() == "image-smooth")
            setImageSmooth(node->value<bool>());
        else if(node->tag() == "image-color")
            setImageColor(node->value<Color>());
        else if(node->tag() == "image-border-top")
            setImageBorderTop(node->value<int>());
        else if(node->tag() == "image-border-right")
            setImageBorderRight(node->value<int>());
        else if(node->tag() == "image-border-bottom")
            setImageBorderBottom(node->value<int>());
        else if(node->tag() == "image-border-left")
            setImageBorderLeft(node->value<int>());
        else if(node->tag() == "image-border")
            setImageBorder(node->value<int>());
        else if(node->tag() == "image-auto-resize")
            setImageAutoResize(node->value<bool>());
    }
}
예제 #2
0
void CVSimpleViewer::setCVMat(const cv::Mat &image, bool contrast, bool conversion)
{
	QSharedPointer<CVMatProvider> provider(new CVMatProvider());
	provider->setCVMat(image, contrast, conversion);
	setImageSource(provider);
}
예제 #3
0
Tiled::Map *TbinMapFormat::read(const QString &fileName)
{
    std::ifstream file( fileName.toStdString(), std::ios::in | std::ios::binary );
    if (!file) {
        mError = tr("Could not open file for reading.");
        return nullptr;
    }

    tbin::Map tmap;
    Tiled::Map* map = nullptr;
    try
    {
        tmap.loadFromStream(file);
        map = new Tiled::Map(Tiled::Map::Orthogonal, tmap.layers[0].layerSize.x, tmap.layers[0].layerSize.y, tmap.layers[0].tileSize.x, tmap.layers[0].tileSize.y);
        tbinToTiledProperties(tmap.props, map);

        const QDir fileDir(QFileInfo(fileName).dir());

        std::map< std::string, int > tmapTilesheetMapping;
        for (std::size_t i = 0; i < tmap.tilesheets.size(); ++i) {
            const tbin::TileSheet& ttilesheet = tmap.tilesheets[i];
            tmapTilesheetMapping[ttilesheet.id] = i;

            if (ttilesheet.spacing.x != ttilesheet.spacing.y)
                throw std::invalid_argument(QT_TR_NOOP("Tilesheet must have equal spacings."));
            if (ttilesheet.margin.x != ttilesheet.margin.y)
                throw std::invalid_argument(QT_TR_NOOP("Tilesheet must have equal margins."));

            auto tilesheet = Tiled::Tileset::create(ttilesheet.id.c_str(), ttilesheet.tileSize.x, ttilesheet.tileSize.y, ttilesheet.spacing.x, ttilesheet.margin.x);
            tilesheet->setImageSource(Tiled::toUrl(QString::fromStdString(ttilesheet.image), fileDir));
            if (!tilesheet->loadImage()) {
                QList<Tiled::Tile*> tiles;
                for (int i = 0; i < ttilesheet.sheetSize.x * ttilesheet.sheetSize.y; ++i) {
                    tiles.append(new Tiled::Tile(i, tilesheet.data()));
                }
                tilesheet->addTiles(tiles);
            }
            tbinToTiledProperties(ttilesheet.props, tilesheet.data());

            for (auto prop : ttilesheet.props) {
                if (prop.first[0] != '@')
                    continue;

                QStringList strs = QString(prop.first.c_str()).split('@');
                if (strs[1] == "TileIndex") {
                    int index = strs[2].toInt();
                    tbin::Properties dummyProps;
                    dummyProps.insert(std::make_pair(strs[3].toStdString(), prop.second));
                    Tiled::Tile* tile = tilesheet->tileAt(index);
                    tbinToTiledProperties(dummyProps, tile);
                }
                // TODO: 'AutoTile' ?
                // Purely for map making. Appears to be similar to terrains
                // (In tIDE, right click a tilesheet and choose "Auto Tiles..."
            }

            map->addTileset(tilesheet);
        }
        for (const tbin::Layer& tlayer : tmap.layers) {
            if (tlayer.tileSize.x != tmap.layers[0].tileSize.x || tlayer.tileSize.y != tmap.layers[0].tileSize.y)
                throw std::invalid_argument(QT_TR_NOOP("Different tile sizes per layer are not supported."));

            QScopedPointer<Tiled::TileLayer> layer(new Tiled::TileLayer(tlayer.id.c_str(), 0, 0, tlayer.layerSize.x, tlayer.layerSize.y));
            tbinToTiledProperties(tlayer.props, layer.data());
            QScopedPointer<Tiled::ObjectGroup> objects(new Tiled::ObjectGroup(tlayer.id.c_str(), 0, 0));
            for (std::size_t i = 0; i < tlayer.tiles.size(); ++i) {
                const tbin::Tile& ttile = tlayer.tiles[i];
                int ix = i % tlayer.layerSize.x;
                int iy = i / tlayer.layerSize.x;

                if (ttile.isNullTile())
                    continue;

                Tiled::Cell cell;
                if (ttile.animatedData.frames.size() > 0) {
                    tbin::Tile tfirstTile = ttile.animatedData.frames[0];
                    Tiled::Tile* firstTile = map->tilesetAt(tmapTilesheetMapping[tfirstTile.tilesheet])->tileAt(tfirstTile.staticData.tileIndex);
                    QVector<Tiled::Frame> frames;
                    for (const tbin::Tile& tframe : ttile.animatedData.frames) {
                        if (tframe.isNullTile() || tframe.animatedData.frames.size() > 0 ||
                             tframe.tilesheet != tfirstTile.tilesheet)
                            throw std::invalid_argument(QT_TR_NOOP("Invalid animation frame."));

                        Tiled::Frame frame;
                        frame.tileId = tframe.staticData.tileIndex;
                        frame.duration = ttile.animatedData.frameInterval;
                        frames.append(frame);
                    }
                    firstTile->setFrames(frames);
                    cell = Tiled::Cell(firstTile);
                }
                else {
                    cell = Tiled::Cell(map->tilesetAt(tmapTilesheetMapping[ttile.tilesheet])->tileAt(ttile.staticData.tileIndex));
                }
                layer->setCell(ix, iy, cell);

                if (ttile.props.size() > 0) {
                    Tiled::MapObject* obj = new Tiled::MapObject("TileData", QString(), QPointF(ix * tlayer.tileSize.x, iy * tlayer.tileSize.y), QSizeF(tlayer.tileSize.x, tlayer.tileSize.y));
                    tbinToTiledProperties(ttile.props, obj);
                    objects->addObject(obj);
                }
            }
            map->addLayer(layer.take());
            map->addLayer(objects.take());
        }
    }
    catch (std::exception& e) {
        mError = tr((std::string("Exception: ") + e.what()).c_str());
    }

    return map;
}