Skip to content
Snippets Groups Projects
Commit 6630bf40 authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

fixed broken scene bg color in GUI; cleaned up by_chain_color_op

parent 4f12ba1b
No related branches found
No related tags found
No related merge requests found
...@@ -152,6 +152,10 @@ void export_color() ...@@ -152,6 +152,10 @@ void export_color()
def("RGBh",rgbh); def("RGBh",rgbh);
def("RGBb",RGBb); def("RGBb",RGBb);
def("RGBi",RGBi); def("RGBi",RGBi);
def("RGBA",RGBA);
def("RGBAh",rgbah);
def("RGBAb",RGBAb);
def("RGBAi",RGBAi);
def("HSV",HSV); def("HSV",HSV);
def("HSVi",HSVi); def("HSVi",HSVi);
def("HSVA",HSVA); def("HSVA",HSVA);
......
...@@ -59,22 +59,37 @@ void ByChainColorOp::ApplyTo(GfxObjP& objP) const{ ...@@ -59,22 +59,37 @@ void ByChainColorOp::ApplyTo(GfxObjP& objP) const{
} }
} }
gfx::Color ByChainColorOp::GetColor(String ident) const{ /*
if(colors_.find(ident) == colors_.end()) The first chain will be assigned a gradient stop of 0.
{ The next chain will be assigned a gradient stop of n/(N-1), where
colors_[ident] = GenerateColor(ident); n is the number of chains assigned so far, and N is the total
number of chains; thus for 3 total chains, the second gets a stop
of 0.5 (1/(3-1)), and the third gets a stop of 1.0 (2/(3-1))
*/
gfx::Color ByChainColorOp::GetColor(const String& ident) const
{
std::map<String,Color>::const_iterator cit = colors_.find(ident);
if(cit == colors_.end()) {
float f = static_cast<float>(colors_.size())*cm_;
Color c = color_grad_.GetColorAt(f);
colors_[ident] = c;
return c;
} else {
return cit->second;
} }
return colors_[ident];
} }
int ByChainColorOp::GetChainCount() const unsigned int ByChainColorOp::GetChainCount() const
{ {
return chain_count_; return chain_count_;
} }
void ByChainColorOp::SetChainCount(int chain_count) void ByChainColorOp::SetChainCount(unsigned int chain_count)
{ {
chain_count_ = chain_count; chain_count_ = chain_count;
cm_=chain_count>1 ? 1.0/static_cast<float>(chain_count_-1) : 0.0;
// invalidate all assigned colors so far
colors_.clear();
} }
gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){ gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){
...@@ -84,16 +99,5 @@ gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){ ...@@ -84,16 +99,5 @@ gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){
return gfx::ByChainColorOp(wrapper, mask); return gfx::ByChainColorOp(wrapper, mask);
} }
gfx::Color ByChainColorOp::GenerateColor(String& ident) const{
unsigned int size=colors_.size()-1;
if(size<=0){
colors_[ident] = color_grad_.GetColorAt(0.0);
}
else{
colors_[ident] = color_grad_.GetColorAt(float(size) / chain_count_);
}
return colors_[ident];
}
}} }}
...@@ -38,13 +38,14 @@ public: ...@@ -38,13 +38,14 @@ public:
ByChainColorOp(const String& selection, int mask=DETAIL_COLOR|MAIN_COLOR); ByChainColorOp(const String& selection, int mask=DETAIL_COLOR|MAIN_COLOR);
ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask=DETAIL_COLOR|MAIN_COLOR); ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask=DETAIL_COLOR|MAIN_COLOR);
// Color Op interface
virtual bool CanApplyTo(const GfxObjP& obj) const; virtual bool CanApplyTo(const GfxObjP& obj) const;
virtual void ApplyTo(GfxObjP& obj) const; virtual void ApplyTo(GfxObjP& obj) const;
virtual gfx::Color GetColor(String ident) const; // this interface
Color GetColor(const String& ident) const;
virtual int GetChainCount() const; unsigned int GetChainCount() const;
virtual void SetChainCount(int chain_count); void SetChainCount(unsigned int chain_count);
//virtual void ToInfo(info::InfoGroup& group) const; //virtual void ToInfo(info::InfoGroup& group) const;
static gfx::ByChainColorOp FromInfo(info::InfoGroup& group); static gfx::ByChainColorOp FromInfo(info::InfoGroup& group);
...@@ -53,8 +54,9 @@ private: ...@@ -53,8 +54,9 @@ private:
void Init(); void Init();
gfx::Color GenerateColor(String& ident) const; gfx::Color GenerateColor(String& ident) const;
mutable int chain_count_; unsigned int chain_count_;
mutable std::map<String,gfx::Color> colors_; float cm_; // 1 over chain_count
mutable std::map<String,Color> colors_;
gfx::Gradient color_grad_; gfx::Gradient color_grad_;
}; };
......
...@@ -59,7 +59,7 @@ def PickColor(default=gfx.WHITE): ...@@ -59,7 +59,7 @@ def PickColor(default=gfx.WHITE):
qt_color=dialog.getColor(qt_color) qt_color=dialog.getColor(qt_color)
if not qt_color.isValid(): if not qt_color.isValid():
return None return None
return gfx.RGBAb(qt_color.red(), qt_color.green(),qt_color.blue()) return gfx.RGBb(qt_color.red(), qt_color.green(),qt_color.blue())
def GetMenu(menu_name, create=False): def GetMenu(menu_name, create=False):
persp=GostyApp.Instance().perspective persp=GostyApp.Instance().perspective
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment