Skip to content

Commit

Permalink
Backport improvements made for objects panel
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Sep 12, 2024
1 parent 1bce13f commit 2804e56
Show file tree
Hide file tree
Showing 11 changed files with 389 additions and 37 deletions.
8 changes: 6 additions & 2 deletions Core/GDCore/Project/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace gd {
*/
class GD_CORE_API Effect {
public:
Effect(){};
virtual ~Effect(){};
Effect() : folded(false) {};
virtual ~Effect() {};

void SetName(const gd::String& name_) { name = name_; }
const gd::String& GetName() const { return name; }
Expand All @@ -32,6 +32,9 @@ class GD_CORE_API Effect {
}
const gd::String& GetEffectType() const { return effectType; }

void SetFolded(bool fold = true) { folded = fold; }
bool IsFolded() const { return folded; }

void SetDoubleParameter(const gd::String& name, double value) {
doubleParameters[name] = value;
}
Expand Down Expand Up @@ -85,6 +88,7 @@ class GD_CORE_API Effect {
void UnserializeFrom(const SerializerElement& element);

private:
bool folded;
gd::String name; ///< The name of the layer.
gd::String effectType; ///< The name of the effect to apply.
std::map<gd::String, double> doubleParameters; ///< Values of parameters being doubles, keyed by names.
Expand Down
96 changes: 96 additions & 0 deletions Extensions/PanelSpriteObject/PanelSpriteObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,102 @@ PanelSpriteObject::PanelSpriteObject()

PanelSpriteObject::~PanelSpriteObject() {}

bool PanelSpriteObject::UpdateProperty(const gd::String& propertyName,
const gd::String& newValue) {
if (propertyName == "texture") {
textureName = newValue;
return true;
}
if (propertyName == "width") {
SetWidth(newValue.To<double>());
return true;
}
if (propertyName == "height") {
SetHeight(newValue.To<double>());
return true;
}
if (propertyName == "leftMargin") {
SetLeftMargin(newValue.To<double>());
return true;
}
if (propertyName == "topMargin") {
SetTopMargin(newValue.To<double>());
return true;
}
if (propertyName == "rightMargin") {
SetRightMargin(newValue.To<double>());
return true;
}
if (propertyName == "bottomMargin") {
SetBottomMargin(newValue.To<double>());
return true;
}
if (propertyName == "tiled") {
SetTiled(newValue == "1");
return true;
}

return false;
}

std::map<gd::String, gd::PropertyDescriptor> PanelSpriteObject::GetProperties() const {
std::map<gd::String, gd::PropertyDescriptor> objectProperties;

objectProperties["texture"]
.SetValue(textureName)
.SetType("resource")
.AddExtraInfo("image")
.SetLabel(_("Texture"));

objectProperties["width"]
.SetValue(gd::String::From(width))
.SetType("number")
.SetLabel(_("Width"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Default size"));

objectProperties["height"]
.SetValue(gd::String::From(height))
.SetType("number")
.SetLabel(_("Height"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Default size"));

objectProperties["leftMargin"]
.SetValue(gd::String::From(leftMargin))
.SetType("number")
.SetLabel(_("Left"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Margins"));

objectProperties["topMargin"]
.SetValue(gd::String::From(topMargin))
.SetType("number")
.SetLabel(_("Top"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Margins"));

objectProperties["rightMargin"]
.SetValue(gd::String::From(rightMargin))
.SetType("number")
.SetLabel(_("Right"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Margins"));

objectProperties["bottomMargin"]
.SetValue(gd::String::From(bottomMargin))
.SetType("number")
.SetLabel(_("Bottom"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Margins"));

objectProperties["tiled"]
.SetValue(tiled ? "true" : "false")
.SetType("boolean")
.SetLabel(_("Repeat borders and center textures (instead of stretching them)"));

return objectProperties;
}
void PanelSpriteObject::DoUnserializeFrom(
gd::Project& project, const gd::SerializerElement& element) {
textureName = element.GetStringAttribute("texture");
Expand Down
18 changes: 12 additions & 6 deletions Extensions/PanelSpriteObject/PanelSpriteObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ class GD_EXTENSION_API PanelSpriteObject : public gd::ObjectConfiguration {
public:
PanelSpriteObject();
virtual ~PanelSpriteObject();
virtual std::unique_ptr<gd::ObjectConfiguration> Clone() const {
virtual std::unique_ptr<gd::ObjectConfiguration> Clone() const override {
return std::unique_ptr<gd::ObjectConfiguration>(
new PanelSpriteObject(*this));
}

virtual void ExposeResources(gd::ArbitraryResourceWorker &worker);
virtual void ExposeResources(gd::ArbitraryResourceWorker &worker) override;

virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties()
const override;

virtual bool UpdateProperty(const gd::String& name,
const gd::String& value) override;

double GetWidth() const { return width; };
double GetHeight() const { return height; };
Expand Down Expand Up @@ -63,15 +69,15 @@ class GD_EXTENSION_API PanelSpriteObject : public gd::ObjectConfiguration {
};
const gd::String &GetTexture() const { return textureName; };

gd::String textureName; ///< deprecated. Use Get/SetTexture instead.

private:
virtual void DoUnserializeFrom(gd::Project &project,
const gd::SerializerElement &element);
const gd::SerializerElement &element) override;
#if defined(GD_IDE_ONLY)
virtual void DoSerializeTo(gd::SerializerElement &element) const;
virtual void DoSerializeTo(gd::SerializerElement &element) const override;
#endif

gd::String textureName;

double width;
double height;

Expand Down
Loading

0 comments on commit 2804e56

Please sign in to comment.