forked from klavinslab/gro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Themes.cpp
165 lines (110 loc) · 4.17 KB
/
Themes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/////////////////////////////////////////////////////////////////////////////////////////
//
// gro is protected by the UW OPEN SOURCE LICENSE, which is summarized here.
// Please see the file LICENSE.txt for the complete license.
//
// THE SOFTWARE (AS DEFINED BELOW) AND HARDWARE DESIGNS (AS DEFINED BELOW) IS PROVIDED
// UNDER THE TERMS OF THIS OPEN SOURCE LICENSE (“LICENSE”). THE SOFTWARE IS PROTECTED
// BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THIS SOFTWARE OTHER THAN AS
// AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
//
// BY EXERCISING ANY RIGHTS TO THE SOFTWARE AND/OR HARDWARE PROVIDED HERE, YOU ACCEPT AND
// AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE
// CONSIDERED A CONTRACT, THE UNIVERSITY OF WASHINGTON (“UW”) GRANTS YOU THE RIGHTS
// CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
//
// TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
//
//
#include "Micro.h"
void World::set_theme ( Value * v ) {
theme.set ( v );
}
Theme::Theme ( void ) {
// default values
background = "#000000";
ecoli_edge = "#ffffff";
ecoli_selected = "#ff000";
mouse = "#333333";
message = "#000000";
chemostat_edge = "#000000";
signal_colors.resize(2);
signal_colors[0].resize(3);
signal_colors[1].resize(3);
signal_colors[0][0] = 1;
signal_colors[0][1] = 0;
signal_colors[0][2] = 1;
signal_colors[1][0] = 0;
signal_colors[1][1] = 1;
signal_colors[1][2] = 1;
}
void Theme::set ( Value * rec ) {
Value * v;
v = rec->getField( "background" );
if ( v && v->get_type() == Value::STRING ) {
background = v->string_value();
}
QColor c ( background.c_str() );
br = c.red() / 255.0;
bg = c.green() / 255.0;
bb = c.blue() / 255.0;
v = rec->getField( "ecoli_edge" );
if ( v && v->get_type() == Value::STRING ) {
ecoli_edge = v->string_value();
}
v = rec->getField( "message" );
if ( v && v->get_type() == Value::STRING ) {
message = v->string_value();
}
v = rec->getField( "chemostat" );
if ( v && v->get_type() == Value::STRING ) {
chemostat_edge = v->string_value();
}
v = rec->getField( "mouse" );
if ( v && v->get_type() == Value::STRING ) {
mouse = v->string_value();
}
v = rec->getField( "ecoli_selected" );
if ( v && v->get_type() == Value::STRING ) {
ecoli_selected = v->string_value();
}
v = rec->getField( "signals" );
int n, m;
if ( v && v->get_type() == Value::LIST ) {
std::list<Value *>::iterator i,j;
signal_colors.resize(v->list_value()->size());
for ( n=0, i=v->list_value()->begin(); i!=v->list_value()->end(); n++, i++) {
Value * col = *i;
signal_colors[n].resize(3);
for ( m=0, j=col->list_value()->begin(); m<3 && j!=col->list_value()->end(); m++, j++) {
signal_colors[n][m] = (*j)->num_value();
}
}
}
}
void Theme::apply_background ( GroPainter * painter ) {
painter->setBackground(QBrush(QColor(background.c_str())));
painter->clear();
}
void Theme::apply_ecoli_edge_color ( GroPainter * painter, bool is_selected ) {
if ( is_selected )
painter->setPen ( QColor ( ecoli_selected.c_str() ) );
else
painter->setPen ( QColor ( ecoli_edge.c_str() ) );
}
void Theme::apply_message_color ( GroPainter * painter ) {
painter->setPen ( QColor ( message.c_str() ) );
}
void Theme::apply_chemostat_edge_color ( GroPainter * painter ) {
painter->setPen ( QPen ( QBrush ( QColor ( chemostat_edge.c_str() ) ), 8, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin ) );
}
void Theme::apply_mouse_color ( QPainter *painter ) {
painter->setPen ( QPen(QBrush(QColor( mouse.c_str() ),Qt::SolidPattern), 1, Qt::DashDotLine ) );
}
void Theme::accumulate_color ( int index, float val, float * r, float * g, float * b ) {
double tval = min ( 1.0, max ( 0.0, val ) );
int k = index%signal_colors.size();
*r += br*(1-tval)+tval*signal_colors[k][0];
*g += bg*(1-tval)+tval*signal_colors[k][1];
*b += bb*(1-tval)+tval*signal_colors[k][2];
}