ToolResult MouseDown(const PosInfo& info) override{ Canvas& canvas = info.canvas; HotSpot hotSpot(floored(info.pos)); if (info.modifiers.LeftMouse()){ // Command for setting the hot spot to the current frame. auto frameIndex = canvas.GetSelectedFrame(); const Image& frame = canvas.GetFrame(frameIndex); m_command.Set(set_frame_hotspot_command(frameIndex, New(hotSpot), Old(frame.GetHotSpot()))); m_hotSpot = hotSpot; return ToolResult::COMMIT; } else if (info.modifiers.RightMouse()){ // Command for setting the hot-spot to all frames. auto commands = make_vector(up_to(canvas.GetNumFrames()), [&](const auto& i){ const Image& frame = canvas.GetFrame(i); return set_frame_hotspot_command(i, New(hotSpot), Old(frame.GetHotSpot()));}); m_hotSpot = hotSpot; m_command.Set(perhaps_bunch(CommandType::FRAME, bunch_name("Set frame hot spots"), std::move(commands))); return ToolResult::COMMIT; } else{ return ToolResult::NONE; } }
void QEglFSCursor::initCursorAtlas() { static QByteArray json = qgetenv("QT_QPA_EGLFS_CURSOR"); if (json.isEmpty()) json = ":/cursor.json"; QFile file(json); file.open(QFile::ReadOnly); QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); QJsonObject object = doc.object(); QString atlas = object.value("image").toString(); Q_ASSERT(!atlas.isEmpty()); const int cursorsPerRow = object.value("cursorsPerRow").toDouble(); Q_ASSERT(cursorsPerRow); m_cursorAtlas.cursorsPerRow = cursorsPerRow; const QJsonArray hotSpots = object.value("hotSpots").toArray(); Q_ASSERT(hotSpots.count() == Qt::LastCursor); for (int i = 0; i < hotSpots.count(); i++) { QPoint hotSpot(hotSpots[i].toArray()[0].toDouble(), hotSpots[i].toArray()[1].toDouble()); m_cursorAtlas.hotSpots << hotSpot; } QImage image = QImage(atlas).convertToFormat(QImage::Format_ARGB32_Premultiplied); m_cursorAtlas.cursorWidth = image.width() / m_cursorAtlas.cursorsPerRow; m_cursorAtlas.cursorHeight = image.height() / ((Qt::LastCursor + cursorsPerRow - 1) / cursorsPerRow); m_cursorAtlas.width = image.width(); m_cursorAtlas.height = image.height(); m_cursorAtlas.image = image; }
static PassRefPtr<SharedCursor> loadCursorByName(char* name, int x, int y) { IntPoint hotSpot(x, y); RefPtr<Image> cursorImage(Image::loadPlatformResource(name)); if (cursorImage && !cursorImage->isNull()) return createSharedCursor(cursorImage.get(), hotSpot); return loadSharedCursor(0, IDC_ARROW); }
void RemoteViewerCore::processPseudoEncoding(const Rect *rect, int encodingType) { switch (encodingType) { case PseudoEncDefs::DESKTOP_SIZE: m_logWriter.info(_T("Changed size of desktop")); { AutoLock al(&m_fbLock); setFbProperties(&Dimension(rect), &m_frameBuffer.getPixelFormat()); } break; case PseudoEncDefs::RICH_CURSOR: { m_logWriter.detail(_T("New rich cursor")); UINT16 width = rect->getWidth(); UINT16 height = rect->getHeight(); UINT8 bytesPerPixel = m_frameBuffer.getBytesPerPixel(); vector<UINT8> cursor; vector<UINT8> bitmask; size_t cursorLen = width * height * bytesPerPixel; if (cursorLen != 0) { cursor.resize(cursorLen); m_input->readFully(&cursor.front(), cursorLen); size_t bitmaskLen = ((width + 7) / 8) * height; bitmask.resize(bitmaskLen); m_input->readFully(&bitmask.front(), bitmaskLen); } Point hotSpot(rect->left, rect->top); m_logWriter.debug(_T("Setting new rich cursor...")); m_fbUpdateNotifier.setNewCursor(&hotSpot, width, height, &cursor, &bitmask); } break; case PseudoEncDefs::POINTER_POS: { m_logWriter.detail(_T("Updating pointer position: [%d, %d]"), rect->left, rect->top); Point position(rect->left, rect->top); m_fbUpdateNotifier.updatePointerPos(&position); } break; default: StringStorage errorString; errorString.format(_T("Pseudo encoding %d is not supported"), encodingType); m_logWriter.error(_T("%s"), errorString.getString()); throw Exception(errorString.getString()); } }
static Cursor loadCursorByName(char* name, int x, int y) { IntPoint hotSpot(x, y); Cursor c; OwnPtr<Image> cursorImage(Image::loadPlatformResource(name)); if (cursorImage && !cursorImage->isNull()) c = Cursor(cursorImage.get(), hotSpot); else c = pointerCursor(); return c; }
bool SpriteSheet2D::EndLoadFromPListFile() { ResourceCache* cache = GetSubsystem<ResourceCache>(); texture_ = cache->GetResource<Texture2D>(loadTextureName_); if (!texture_) { LOGERROR("Could not load texture " + loadTextureName_); loadXMLFile_.Reset(); loadTextureName_.Clear(); return false; } const PListValueMap& root = loadPListFile_->GetRoot(); const PListValueMap& frames = root["frames"].GetValueMap(); for (PListValueMap::ConstIterator i = frames.Begin(); i != frames.End(); ++i) { String name = i->first_.Split('.')[0]; const PListValueMap& frameInfo = i->second_.GetValueMap(); if (frameInfo["rotated"].GetBool()) { LOGWARNING("Rotated sprite is not support now"); continue; } IntRect rectangle = frameInfo["frame"].GetIntRect(); Vector2 hotSpot(0.5f, 0.5f); IntVector2 offset(0, 0); IntRect sourceColorRect = frameInfo["sourceColorRect"].GetIntRect(); if (sourceColorRect.left_ != 0 && sourceColorRect.top_ != 0) { offset.x_ = -sourceColorRect.left_; offset.y_ = -sourceColorRect.top_; IntVector2 sourceSize = frameInfo["sourceSize"].GetIntVector2(); hotSpot.x_ = ((float)offset.x_ + sourceSize.x_ / 2) / rectangle.Width(); hotSpot.y_ = 1.0f - ((float)offset.y_ + sourceSize.y_/ 2) / rectangle.Height(); } DefineSprite(name, rectangle, hotSpot, offset); } loadXMLFile_.Reset(); loadTextureName_.Clear(); return true; }
bool SpriteSheet2D::EndLoadFromXMLFile() { ResourceCache* cache = GetSubsystem<ResourceCache>(); texture_ = cache->GetResource<Texture2D>(loadTextureName_); if (!texture_) { URHO3D_LOGERROR("Could not load texture " + loadTextureName_); loadXMLFile_.Reset(); loadTextureName_.Clear(); return false; } XMLElement rootElem = loadXMLFile_->GetRoot("TextureAtlas"); XMLElement subTextureElem = rootElem.GetChild("SubTexture"); while (subTextureElem) { String name = subTextureElem.GetAttribute("name"); int x = subTextureElem.GetInt("x"); int y = subTextureElem.GetInt("y"); int width = subTextureElem.GetInt("width"); int height = subTextureElem.GetInt("height"); IntRect rectangle(x, y, x + width, y + height); Vector2 hotSpot(0.5f, 0.5f); IntVector2 offset(0, 0); if (subTextureElem.HasAttribute("frameWidth") && subTextureElem.HasAttribute("frameHeight")) { offset.x_ = subTextureElem.GetInt("frameX"); offset.y_ = subTextureElem.GetInt("frameY"); int frameWidth = subTextureElem.GetInt("frameWidth"); int frameHeight = subTextureElem.GetInt("frameHeight"); hotSpot.x_ = ((float)offset.x_ + frameWidth / 2) / width; hotSpot.y_ = 1.0f - ((float)offset.y_ + frameHeight / 2) / height; } DefineSprite(name, rectangle, hotSpot, offset); subTextureElem = subTextureElem.GetNext("SubTexture"); } loadXMLFile_.Reset(); loadTextureName_.Clear(); return true; }
int QGesture::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< Qt::GestureState*>(_v) = state(); break; case 1: *reinterpret_cast< Qt::GestureType*>(_v) = gestureType(); break; case 2: *reinterpret_cast< QGesture::GestureCancelPolicy*>(_v) = gestureCancelPolicy(); break; case 3: *reinterpret_cast< QPointF*>(_v) = hotSpot(); break; case 4: *reinterpret_cast< bool*>(_v) = hasHotSpot(); break; } _id -= 5; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 2: setGestureCancelPolicy(*reinterpret_cast< QGesture::GestureCancelPolicy*>(_v)); break; case 3: setHotSpot(*reinterpret_cast< QPointF*>(_v)); break; } _id -= 5; } else if (_c == QMetaObject::ResetProperty) { switch (_id) { case 3: unsetHotSpot(); break; } _id -= 5; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 5; } #endif // QT_NO_PROPERTIES return _id; }
QCursor::QCursor(const QPixmap &pixmap) : cursor(NULL) { ERROR("not yet implemented"); GdkPixbuf* buf = pixmap.image()->handle(); QPoint hotSpot(0,0); #if (GTK_MAJOR_VERSION >= 2) && (GTK_MINOR_VERSION >=4) cursor = gdk_cursor_new_from_pixbuf(GDK_DISPLAY(), buf, hotSpot.x(), hotSpot.y()); #else GdkPixmap *gdkpixmap; GdkBitmap *mask; gdk_pixbuf_render_pixmap_and_mask(buf, &gdkpixmap, &mask, 100); GdkColor fg = { 0, 65535, 65535, 65535 }; /* White. */ GdkColor bg = { 0, 0, 0, 0 }; /* Black. */ cursor = gdk_cursor_new_from_pixmap(mask, mask, &fg, &bg, hotSpot.x(), hotSpot.y()); g_object_unref(gdkpixmap); g_object_unref(mask); #endif }
bool SpriteSheet2D::Load(Deserializer& source) { spriteMapping_.Clear(); SharedPtr<XMLFile> xmlFile(new XMLFile(context_)); if(!xmlFile->Load(source)) { LOGERROR("Could not load sprite sheet"); return false; } SetMemoryUse(source.GetSize()); XMLElement rootElem = xmlFile->GetRoot(); if (!rootElem) { LOGERROR("Invalid sprite sheet"); return false; } if (rootElem.GetName() == "spritesheet") { ResourceCache* cache = GetSubsystem<ResourceCache>(); String textureFileName = rootElem.GetAttribute("texture"); texture_ = cache->GetResource<Texture2D>(textureFileName, false); // If texture not found, try get in current directory if (!texture_) texture_ = cache->GetResource<Texture2D>(GetParentPath(GetName()) + textureFileName); if (!texture_) { LOGERROR("Cound not load texture"); return false; } XMLElement spriteElem = rootElem.GetChild("sprite"); while (spriteElem) { String name = spriteElem.GetAttribute("name"); IntRect rectangle = spriteElem.GetIntRect("rectangle"); Vector2 hotSpot(0.5f, 0.5f); if (spriteElem.HasAttribute("hotspot")) hotSpot = spriteElem.GetVector2("hotspot"); DefineSprite(name, rectangle, hotSpot); spriteElem = spriteElem.GetNext("sprite"); } } // Sparrow Starling texture atlas else if (rootElem.GetName() == "TextureAtlas") { String textureFileName = rootElem.GetAttribute("imagePath"); ResourceCache* cache = GetSubsystem<ResourceCache>(); texture_ = cache->GetResource<Texture2D>(textureFileName, false); // If texture not found, try get in current directory if (!texture_) texture_ = cache->GetResource<Texture2D>(GetParentPath(GetName()) + textureFileName); if (!texture_) { LOGERROR("Cound not load texture"); return false; } XMLElement subTextureElem = rootElem.GetChild("SubTexture"); while (subTextureElem) { String name = subTextureElem.GetAttribute("name"); int x = subTextureElem.GetInt("x"); int y = subTextureElem.GetInt("y"); int width = subTextureElem.GetInt("width"); int height = subTextureElem.GetInt("height"); IntRect rectangle(x, y, x + width, y + height); Vector2 hotSpot(0.5f, 0.5f); if (subTextureElem.HasAttribute("frameWidth") && subTextureElem.HasAttribute("frameHeight")) { int frameX = subTextureElem.GetInt("frameX"); int frameY = subTextureElem.GetInt("frameY"); int frameWidth = subTextureElem.GetInt("frameWidth"); int frameHeight = subTextureElem.GetInt("frameHeight"); hotSpot.x_ = ((float)frameX + frameWidth / 2) / width; hotSpot.y_ = 1.0f - ((float)frameY + frameHeight / 2) / height; } DefineSprite(name, rectangle, hotSpot); subTextureElem = subTextureElem.GetNext("SubTexture"); } } else { LOGERROR("Invalid sprite sheet file"); return false; } return true; }
bool TmxFile2D::LoadTileSet(const XMLElement& element) { int firstgid = element.GetInt("firstgid"); XMLElement tileSetElem; if (element.HasAttribute("source")) { String source = element.GetAttribute("source"); HashMap<String, SharedPtr<XMLFile> >::Iterator i = tsxXMLFiles_.Find(source); if (i == tsxXMLFiles_.End()) { SharedPtr<XMLFile> tsxXMLFile = LoadTSXFile(source); if (!tsxXMLFile) return false; // Add to napping to avoid release tsxXMLFiles_[source] = tsxXMLFile; tileSetElem = tsxXMLFile->GetRoot("tileset"); } else tileSetElem = i->second_->GetRoot("tileset"); } else tileSetElem = element; XMLElement imageElem = tileSetElem.GetChild("image"); String textureFilePath = GetParentPath(GetName()) + imageElem.GetAttribute("source"); ResourceCache* cache = GetSubsystem<ResourceCache>(); SharedPtr<Texture2D> texture(cache->GetResource<Texture2D>(textureFilePath)); if (!texture) { URHO3D_LOGERROR("Could not load texture " + textureFilePath); return false; } tileSetTextures_.Push(texture); int tileWidth = tileSetElem.GetInt("tilewidth"); int tileHeight = tileSetElem.GetInt("tileheight"); int spacing = tileSetElem.GetInt("spacing"); int margin = tileSetElem.GetInt("margin"); int imageWidth = imageElem.GetInt("width"); int imageHeight = imageElem.GetInt("height"); // Set hot spot at left bottom Vector2 hotSpot(0.0f, 0.0f); if (tileSetElem.HasChild("tileoffset")) { XMLElement offsetElem = tileSetElem.GetChild("tileoffset"); hotSpot.x_ += offsetElem.GetFloat("x") / (float)tileWidth; hotSpot.y_ += offsetElem.GetFloat("y") / (float)tileHeight; } int gid = firstgid; for (int y = margin; y + tileHeight <= imageHeight - margin; y += tileHeight + spacing) { for (int x = margin; x + tileWidth <= imageWidth - margin; x += tileWidth + spacing) { SharedPtr<Sprite2D> sprite(new Sprite2D(context_)); sprite->SetTexture(texture); sprite->SetRectangle(IntRect(x, y, x + tileWidth, y + tileHeight)); sprite->SetHotSpot(hotSpot); gidToSpriteMapping_[gid++] = sprite; } } for (XMLElement tileElem = tileSetElem.GetChild("tile"); tileElem; tileElem = tileElem.GetNext("tile")) { if (tileElem.HasChild("properties")) { SharedPtr<PropertySet2D> propertySet(new PropertySet2D()); propertySet->Load(tileElem.GetChild("properties")); gidToPropertySetMapping_[firstgid + tileElem.GetInt("id")] = propertySet; } } return true; }
bool AnimationSet2D::LoadFolders(const XMLElement& rootElem) { ResourceCache* cache = GetSubsystem<ResourceCache>(); bool async = GetAsyncLoadState() == ASYNC_LOADING; String parentPath = GetParentPath(GetName()); String spriteSheetFilePath = parentPath + GetFileName(GetName()) + ".xml"; SpriteSheet2D* spriteSheet = 0; bool hasSpriteSheet = false; // When async loading, request the sprite sheet for background loading but do not actually get it if (!async) spriteSheet = cache->GetResource<SpriteSheet2D>(spriteSheetFilePath, false); else { hasSpriteSheet = cache->Exists(spriteSheetFilePath); if (hasSpriteSheet) cache->BackgroundLoadResource<SpriteSheet2D>(spriteSheetFilePath, false, this); } for (XMLElement folderElem = rootElem.GetChild("folder"); folderElem; folderElem = folderElem.GetNext("folder")) { unsigned folderId = folderElem.GetUInt("id"); for (XMLElement fileElem = folderElem.GetChild("file"); fileElem; fileElem = fileElem.GetNext("file")) { unsigned fileId = fileElem.GetUInt("id"); String fileName = fileElem.GetAttribute("name"); // When async loading, request the sprites for background loading but do not actually get them if (!async) { SharedPtr<Sprite2D> sprite; if (spriteSheet) sprite = spriteSheet->GetSprite(GetFileName(fileName)); else sprite = (cache->GetResource<Sprite2D>(parentPath + fileName)); if (!sprite) { LOGERROR("Could not load sprite " + fileName); return false; } Vector2 hotSpot(0.0f, 1.0f); if (fileElem.HasAttribute("pivot_x")) hotSpot.x_ = fileElem.GetFloat("pivot_x"); if (fileElem.HasAttribute("pivot_y")) hotSpot.y_ = fileElem.GetFloat("pivot_y"); // If sprite is trimmed, recalculate hot spot const IntVector2& offset = sprite->GetOffset(); if (offset != IntVector2::ZERO) { int width = fileElem.GetInt("width"); int height = fileElem.GetInt("height"); float pivotX = width * hotSpot.x_; float pivotY = height * (1.0f - hotSpot.y_); const IntRect& rectangle = sprite->GetRectangle(); hotSpot.x_ = (offset.x_ + pivotX) / rectangle.Width(); hotSpot.y_ = 1.0f - (offset.y_ + pivotY) / rectangle.Height(); } sprite->SetHotSpot(hotSpot); sprites_[(folderId << 16) + fileId] = sprite; } else if (!hasSpriteSheet) cache->BackgroundLoadResource<Sprite2D>(parentPath + fileName, true, this); } } return true; }