mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-05 12:25:05 +00:00
GUI: implement Gradient2D::fromString()
WE ARE CLOSE
This commit is contained in:
parent
7586db9a1b
commit
aa511d2718
1 changed files with 33 additions and 3 deletions
|
@ -40,9 +40,39 @@ String Gradient2D::toString() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// TODO: this one please
|
||||
bool Gradient2D::fromString(String val) {
|
||||
return false;
|
||||
std::vector<String> split;
|
||||
String cur;
|
||||
for (char i: val) {
|
||||
if (i==' ') {
|
||||
if (!cur.empty()) {
|
||||
split.push_back(cur);
|
||||
cur="";
|
||||
}
|
||||
} else {
|
||||
cur+=i;
|
||||
}
|
||||
}
|
||||
|
||||
if (split.size()<2) return false;
|
||||
|
||||
if (split[0]!="GRAD") return false;
|
||||
|
||||
ImU32 bgColorH=0;
|
||||
if (sscanf(split[1].c_str(),"#%X",&bgColorH)!=1) return false;
|
||||
|
||||
bgColor=ImGui::ColorConvertU32ToFloat4(bgColorH);
|
||||
|
||||
for (size_t i=2; i<split.size(); i++) {
|
||||
Gradient2DPoint point;
|
||||
ImU32 colorH=0;
|
||||
if (sscanf(split[i].c_str(),"%f,%f:%f,%f:#%X",&point.x,&point.y,&point.distance,&point.spread,&colorH)!=5) {
|
||||
return false;
|
||||
}
|
||||
point.color=ImGui::ColorConvertU32ToFloat4(colorH);
|
||||
points.push_back(point);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Gradient2D::render() {
|
||||
|
@ -91,4 +121,4 @@ void Gradient2D::render() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue