Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start control positioning in Skin Engine #1685

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 0 additions & 165 deletions resources/data/skins/dark-mode.surge-skin/skin.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<surge-skin name="Test: Minimal Position Change" author="Surge Synth Team" authorURL="https://surge-synth-team.org/">
<globals>
</globals>
<component-classes>
</component-classes>
<controls>
<!--
Swap the location of the character.
Original was y=11 h=27; y=41. So 41 = 11 + 27 + 3 so margin is 3
Since height of character is 12, 11 + 12 + 3 = 26 so char y == 11 and bybass y is 26

To make the relative position clearer, enclose them in a group
-->
<group name="fx and char" x="607" y="11">
<control ui_identifier="global.character" x="0" y="0" w="135" h="12" subpixmaps="3" rows="1" columns="3" class="CHSwitch2" bg_id="161" />
<control ui_identifier="global.fx_bypass" x="0" y="15" w="135" h="27" subpixmaps="4" rows="1" columns="4" class="CHSwitch2" bg_id="144" />
</group>

</controls>
</surge-skin>
8 changes: 7 additions & 1 deletion src/common/gui/CLFOGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,10 @@ void CLFOGui::drawVectorized(CDrawContext* dc)
CRect tb(leftpanel);
tb.top = leftpanel.top + 10 * i;
tb.bottom = tb.top + 10;
//std::cout << std::hex << this << std::dec << " CHECK " << i << " " << lfodata->shape.val.i;
if (i == lfodata->shape.val.i)
{
//std::cout << " ON" << std::endl;
CRect tb2(tb);
tb2.left++;
tb2.top += 0.5;
Expand All @@ -475,6 +477,7 @@ void CLFOGui::drawVectorized(CDrawContext* dc)
}
else
{
//std::cout << " OFF" << std::endl;
dc->setFontColor(skin->getColor( "lfo.type.unselected.foreground", kBlackCColor) );
}
// else dc->setFillColor(cgray);
Expand Down Expand Up @@ -858,7 +861,10 @@ void CLFOGui::drawStepSeq(VSTGUI::CDrawContext *dc, VSTGUI::CRect &maindisp, VST
v.bottom = max(p1, p2) + 1;
}
// if (p1 == p2) p2++;
cdisurf->fillRect(v, stepMarker);
if ((i >= ss->loop_start) && (i <= ss->loop_end))
cdisurf->fillRect(v, stepMarker);
else
cdisurf->fillRect(v, disStepMarker);
}


Expand Down
171 changes: 124 additions & 47 deletions src/common/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,47 +309,11 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
return std::string( av );
};

for (auto gchild = controlsxml->FirstChild(); gchild; gchild = gchild->NextSibling())
{
auto lkid = TINYXML_SAFE_TO_ELEMENT(gchild);
if (!lkid)
continue;

if (std::string(lkid->Value()) != "control")
{
FIXMEERROR << "INVALID CONTROL" << std::endl;
continue;
}

Skin::Control c;
c.x = attrint(lkid, "x");
c.y = attrint(lkid, "y");
c.w = attrint(lkid, "w");
c.h = attrint(lkid, "h");
c.posx = attrint(lkid, "posx");
c.posy = attrint(lkid, "posy");
c.posy_offset = attrint(lkid, "posy_offset");

c.classname = attrstr(lkid, "class" );
if( lkid->Attribute( "tag_value" ) )
{
c.type = Control::Type::ENUM;
c.enum_id = attrint( lkid, "tag_value" );
c.enum_name = attrstr( lkid, "tag_name" );
}
else
{
c.type = Control::Type::UIID;
c.ui_id = attrstr( lkid, "ui_identifier" );
}

for (auto a = lkid->FirstAttribute(); a; a = a->Next())
c.allprops[a->Name()] = a->Value();

controls.push_back(c);
}
controls.clear();
rootControl = std::make_shared<ControlGroup>();
recursiveGroupParse( rootControl, controlsxml );

// TODO: add component-classes section
componentClasses.clear();
for (auto gchild = componentclassesxml->FirstChild(); gchild; gchild = gchild->NextSibling())
{
auto lkid = TINYXML_SAFE_TO_ELEMENT(gchild);
Expand All @@ -362,27 +326,27 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
continue;
}

Skin::ComponentClass c;
auto c = std::make_shared<Skin::ComponentClass>();

c.name = attrstr( lkid, "name" );
if( c.name == "" )
c->name = attrstr( lkid, "name" );
if( c->name == "" )
{
FIXMEERROR << "INVALUD NAME" << std::endl;
}

if( componentClasses.find( c.name ) != componentClasses.end() )
if( componentClasses.find( c->name ) != componentClasses.end() )
{
FIXMEERROR << "Double Definition" << std::endl;
}

for (auto a = lkid->FirstAttribute(); a; a = a->Next())
c.allprops[a->Name()] = a->Value();
c->allprops[a->Name()] = a->Value();

componentClasses[c.name] = c;
componentClasses[c->name] = c;

};

// process the images
// process the images and colors
for (auto g : globals)
{
if (g.first == "defaultimage")
Expand Down Expand Up @@ -457,6 +421,96 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
}
}
}

// Resolve the ultimate parent classes
for( auto &c : controls )
{
c->ultimateparentclassname = c->classname;
while( componentClasses.find( c->ultimateparentclassname ) != componentClasses.end() )
{
auto comp = componentClasses[c->ultimateparentclassname];
if( comp->allprops.find( "parent" ) != comp->allprops.end() )
{
c->ultimateparentclassname = componentClasses[c->ultimateparentclassname]->allprops["parent"];
}
else
{
FIXMEERROR << "PARENT CLASS DOESN'T RESOLVE FOR " << c->ultimateparentclassname << std::endl;
break;
}
}
}

}

void Skin::recursiveGroupParse( ControlGroup::ptr_t parent, TiXmlElement *controlsxml, std::string pfx )
{
// I know I am gross for copying these
auto attrint = [](TiXmlElement* e, const char* a) {
const char* av = e->Attribute(a);
if (!av)
return -1;
return std::atoi(av);
};

auto attrstr = [](TiXmlElement *e, const char* a ) {
const char* av = e->Attribute(a);
if( !av )
return std::string();
return std::string( av );
};

for (auto gchild = controlsxml->FirstChild(); gchild; gchild = gchild->NextSibling())
{
auto lkid = TINYXML_SAFE_TO_ELEMENT(gchild);
if (!lkid)
continue;

if( std::string( lkid->Value()) == "group" )
{
auto g = std::make_shared<Skin::ControlGroup>();

g->x = attrint( lkid, "x" ); if( g->x < 0 ) g->x = 0; g->x += parent->x;
g->y = attrint( lkid, "y" ); if( g->y < 0 ) g->y = 0; g->y += parent->y;
g->w = attrint( lkid, "w" );
g->h = attrint( lkid, "h" );

parent->childGroups.push_back(g);
recursiveGroupParse( g, lkid, pfx + "|--" );
}
else if (std::string(lkid->Value()) == "control")
{
auto c = std::make_shared<Skin::Control>();
c->x = attrint(lkid, "x") + parent->x;
c->y = attrint(lkid, "y") + parent->y;
c->w = attrint(lkid, "w");
c->h = attrint(lkid, "h");

c->classname = attrstr(lkid, "class" );
if( lkid->Attribute( "tag_value" ) )
{
c->type = Control::Type::ENUM;
c->enum_id = attrint( lkid, "tag_value" );
c->enum_name = attrstr( lkid, "tag_name" );
}
else
{
c->type = Control::Type::UIID;
c->ui_id = attrstr( lkid, "ui_identifier" );
}

for (auto a = lkid->FirstAttribute(); a; a = a->Next())
c->allprops[a->Name()] = a->Value();

controls.push_back(c);
parent->childControls.push_back(c);
}
else
{
FIXMEERROR << "INVALID CONTROL" << std::endl;
}
}

}

bool Skin::hasColor(std::string id)
Expand Down Expand Up @@ -491,5 +545,28 @@ VSTGUI::CColor Skin::getColor(std::string id, const VSTGUI::CColor& def, std::un
}
return def;
}


CScalableBitmap *Skin::backgroundBitmapForControl( Skin::Control::ptr_t c, std::shared_ptr<SurgeBitmaps> bitmapStore )
{
CScalableBitmap *bmp = nullptr;
auto ms = propertyValue( c, "bg_id" );
if( ms.isJust() )
{
bmp = bitmapStore->getBitmap(std::atoi(ms.fromJust().c_str()));
}
else
{
auto mr = propertyValue( c, "bg_resource" );
if( mr.isJust() )
{
bmp = bitmapStore->getBitmapByStringID( mr.fromJust() );
if( ! bmp )
bmp = bitmapStore->loadBitmapByPathForStringID( resourceName( mr.fromJust() ), mr.fromJust() );
}
}
return bmp;
}

} // namespace UI
} // namespace Surge
Loading