LumaSystem.cpp
Go to the documentation of this file.
1 #include "LumaSystem.hpp"
2 #include "Defs.hpp"
3 
4 namespace iv
5 {
6 
7 //-------------- LumaStyleId -------------------------
9 
10 //----------------------------
12  surface( 1, 1, 1, 1 ),
13  highlight( 0.384, 0, 0.93, 1 ),
14  error( 0.69, 0, 0.13, 1 ),
15  on_surface( 0, 0, 0, 1 ),
16  on_highlight( 1, 1, 1, 1 ),
17  on_error( 1, 1, 1, 1 ),
18  font_normal( "/ivorium_UI/fonts/DejaVuSansMono/font.index" ),
19  font_monospace( "/ivorium_UI/fonts/DejaVuSansMono/font.index" )
20 {
21 }
22 
23 //------------- LumaListener ------------------------------------
25  cm( inst, this, "LumaListener" ),
26  inst( inst ),
27  id( id )
28 {
29  auto ls = this->inst->getSystem< LumaSystem >();
30  if( ls )
31  {
32  ls->AddListener( this );
33  if( !this->id.valid() )
34  this->id = ls->current_style();
35  }
36 }
37 
39 {
40  auto ls = this->inst->getSystem< LumaSystem >();
41  if( ls )
42  ls->RemoveListener( this );
43 }
44 
46 {
47  return this->inst;
48 }
49 
51 {
52  return this->id;
53 }
54 
55 
57 {
58  auto ls = this->inst->getSystem< LumaSystem >();
59  if( !ls )
60  {
61  static LumaStyle _v;
62  return _v;
63  }
64 
65  return ls->style( this->id );
66 }
67 
68 //------------- LumaStyler ------------------------------------
70  cm( inst, this, "LumaStyler" ),
71  inst( inst ),
72  ls( this->instance()->getSystem< LumaSystem >() )
73 {
74 }
75 
77 {
78  return this->inst;
79 }
80 
82 {
83  if( !this->ls )
84  return;
85  this->ls->current_style( id );
86 }
87 
89 {
90  if( !this->ls )
91  return LumaStyleId();
92  return this->ls->current_style();
93 }
94 
95 void LumaStyler::style( LumaStyleId id, LumaStyle const & style )
96 {
97  if( !this->ls )
98  return;
99 
100  if( !id.valid() )
101  {
102  this->cm.warning( SRC_INFO, "Invalid LumaStyleId can not be set. Setting Default StyleId instead." );
104  }
105 
106  this->ls->style( id, style );
107 }
108 
110 {
111  if( !this->ls )
112  {
113  static LumaStyle _v;
114  return _v;
115  }
116  return this->ls->style( id );
117 }
118 
119 //------------- LumaSystem ------------------------------------
121  iv::System( sc ),
122  _current_style( Defs::Style::Default )
123 {
124  // default style colors
126  this->_styles[ this->_current_style ] = style;
127 }
128 
130 {
131  this->_current_style = id;
132 }
133 
135 {
136  return this->_current_style;
137 }
138 
139 void LumaSystem::style( LumaStyleId id, LumaStyle const & style )
140 {
141  LumaStyle & stored_style = this->_styles[ id ];
142  stored_style = style;
143  this->_listeners.foreach(
144  [&]( LumaListener * listener )
145  {
146  if( listener->style_id() == id )
147  listener->LumaStyleChanged( stored_style );
148  }
149  );
150 }
151 
153 {
154  auto it = this->_styles.find( id );
155  if( it == this->_styles.end() )
156  return this->_styles.at( Defs::Style::Default );
157  return it->second;
158 }
159 
161 {
162  this->_listeners.erase( listener );
163 }
164 
166 {
167  this->_listeners.erase( listener );
168 }
169 
170 }