Newer
Older
60001
60002
60003
60004
60005
60006
60007
60008
60009
60010
60011
60012
60013
60014
60015
60016
60017
60018
60019
60020
60021
60022
60023
60024
60025
60026
60027
60028
60029
60030
60031
60032
60033
60034
60035
60036
60037
60038
60039
60040
60041
60042
60043
60044
60045
60046
60047
60048
60049
60050
60051
60052
60053
60054
60055
60056
60057
60058
60059
60060
60061
60062
60063
60064
60065
60066
60067
60068
60069
60070
60071
60072
60073
60074
60075
60076
60077
60078
60079
60080
60081
60082
60083
60084
60085
60086
60087
60088
60089
60090
60091
60092
60093
60094
60095
60096
60097
60098
60099
60100
60101
60102
60103
60104
60105
60106
60107
60108
60109
60110
60111
60112
60113
60114
60115
60116
60117
60118
60119
60120
60121
60122
60123
60124
60125
60126
60127
60128
60129
60130
60131
60132
60133
60134
60135
60136
60137
60138
60139
60140
60141
60142
60143
60144
60145
60146
60147
60148
60149
60150
60151
60152
60153
60154
60155
60156
60157
60158
60159
60160
60161
60162
60163
60164
60165
60166
60167
60168
60169
60170
60171
cbutton.draw_rectangle(0,0,bw - 1,bh - 1,black).draw_rectangle(1,1,bw - 2,bh - 2,gray2).
draw_rectangle(2,2,bw - 3,bh - 3,gray);
cbutton.draw_line(4,4,bw - 5,4,black,1,0xAAAAAAAA,true).draw_line(bw - 5,4,bw - 5,bh - 5,black,1,0xAAAAAAAA,false);
cbutton.draw_line(bw - 5,bh - 5,4,bh - 5,black,1,0xAAAAAAAA,false).draw_line(4,bh - 5,4,4,black,1,0xAAAAAAAA,false);
cimglist_for(buttons,ll) {
CImg<unsigned char>(cbutton).
draw_image(1 + (bw -buttons[ll].width())/2,1 + (bh - buttons[ll].height())/2,buttons[ll]).
move_to(cbuttons);
CImg<unsigned char>(sbutton).
draw_image((bw - buttons[ll].width())/2,(bh - buttons[ll].height())/2,buttons[ll]).
move_to(sbuttons);
CImg<unsigned char>(button).
draw_image((bw - buttons[ll].width())/2,(bh - buttons[ll].height())/2,buttons[ll]).
move_to(buttons[ll]);
}
CImg<unsigned char> canvas;
if (msg)
((CImg<unsigned char>().draw_text(0,0,"%s",gray,0,1,13,msg)*=-1)+=200).resize(-100,-100,1,3).move_to(canvas);
const unsigned int
bwall = (buttons._width - 1)*(12 + bw) + bw,
w = cimg::max(196U,36 + logo._width + canvas._width,24 + bwall),
h = cimg::max(96U,36 + canvas._height + bh,36 + logo._height + bh),
lx = 12 + (canvas._data?0:((w - 24 - logo._width)/2)),
ly = (h - 12 - bh - logo._height)/2,
tx = lx + logo._width + 12,
ty = (h - 12 - bh - canvas._height)/2,
bx = (w - bwall)/2,
by = h - 12 - bh;
if (canvas._data)
canvas = CImg<unsigned char>(w,h,1,3).
draw_rectangle(0,0,w - 1,h - 1,gray).
draw_line(0,0,w - 1,0,white).draw_line(0,h - 1,0,0,white).
draw_line(w - 1,0,w - 1,h - 1,black).draw_line(w - 1,h - 1,0,h - 1,black).
draw_image(tx,ty,canvas);
else
canvas = CImg<unsigned char>(w,h,1,3).
draw_rectangle(0,0,w - 1,h - 1,gray).
draw_line(0,0,w - 1,0,white).draw_line(0,h - 1,0,0,white).
draw_line(w - 1,0,w - 1,h - 1,black).draw_line(w - 1,h - 1,0,h - 1,black);
if (logo._data) canvas.draw_image(lx,ly,logo);
unsigned int xbuttons[6] = { 0 };
cimglist_for(buttons,lll) { xbuttons[lll] = bx + (bw + 12)*lll; canvas.draw_image(xbuttons[lll],by,buttons[lll]); }
// Open window and enter events loop
CImgDisplay disp(canvas,title?title:" ",0,false,is_centered?true:false);
if (is_centered) disp.move((CImgDisplay::screen_width() - disp.width())/2,
(CImgDisplay::screen_height() - disp.height())/2);
bool stop_flag = false, refresh = false;
int oselected = -1, oclicked = -1, selected = -1, clicked = -1;
while (!disp.is_closed() && !stop_flag) {
if (refresh) {
if (clicked>=0)
CImg<unsigned char>(canvas).draw_image(xbuttons[clicked],by,cbuttons[clicked]).display(disp);
else {
if (selected>=0)
CImg<unsigned char>(canvas).draw_image(xbuttons[selected],by,sbuttons[selected]).display(disp);
else canvas.display(disp);
}
refresh = false;
}
disp.wait(15);
if (disp.is_resized()) disp.resize(disp,false);
if (disp.button()&1) {
oclicked = clicked;
clicked = -1;
cimglist_for(buttons,l)
if (disp.mouse_y()>=(int)by && disp.mouse_y()<(int)(by + bh) &&
disp.mouse_x()>=(int)xbuttons[l] && disp.mouse_x()<(int)(xbuttons[l] + bw)) {
clicked = selected = l;
refresh = true;
}
if (clicked!=oclicked) refresh = true;
} else if (clicked>=0) stop_flag = true;
if (disp.key()) {
oselected = selected;
switch (disp.key()) {
case cimg::keyESC : selected = -1; stop_flag = true; break;
case cimg::keyENTER : if (selected<0) selected = 0; stop_flag = true; break;
case cimg::keyTAB :
case cimg::keyARROWRIGHT :
case cimg::keyARROWDOWN : selected = (selected + 1)%buttons.width(); break;
case cimg::keyARROWLEFT :
case cimg::keyARROWUP : selected = (selected + buttons.width() - 1)%buttons.width(); break;
}
disp.set_key();
if (selected!=oselected) refresh = true;
}
}
if (!disp) selected = -1;
return selected;
#endif
}
//! Display a simple dialog box, and wait for the user's response \specialization.
inline int dialog(const char *const title, const char *const msg,
const char *const button1_label, const char *const button2_label, const char *const button3_label,
const char *const button4_label, const char *const button5_label, const char *const button6_label,
const bool is_centered) {
return dialog(title,msg,button1_label,button2_label,button3_label,button4_label,button5_label,button6_label,
CImg<unsigned char>::_logo40x38(),is_centered);
}
//! Evaluate math expression.
/**
\param expression C-string describing the formula to evaluate.
\param x Value of the pre-defined variable \c x.
\param y Value of the pre-defined variable \c y.
\param z Value of the pre-defined variable \c z.
\param c Value of the pre-defined variable \c c.
\return Result of the formula evaluation.
\note Set \c expression to \c 0 to keep evaluating the last specified \c expression.
\par Example
\code
const double
res1 = cimg::eval("cos(x)^2 + sin(y)^2",2,2), // will return '1'.
res2 = cimg::eval(0,1,1); // will return '1' too.
\endcode
**/
inline double eval(const char *const expression, const double x, const double y, const double z, const double c) {
static const CImg<float> empty;
return empty.eval(expression,x,y,z,c);
}
template<typename t>
inline CImg<typename cimg::superset<double,t>::type> eval(const char *const expression, const CImg<t>& xyzc) {
static const CImg<float> empty;
return empty.eval(expression,xyzc);
}
// End of cimg:: namespace
}
// End of cimg_library:: namespace
}
//! Short alias name.
namespace cil = cimg_library_suffixed;
#ifdef _cimg_redefine_False
#define False 0
#endif
#ifdef _cimg_redefine_True
#define True 1
#endif
#ifdef _cimg_redefine_None
#define None 0
#endif
#ifdef _cimg_redefine_min
#define min(a,b) (((a)<(b))?(a):(b))
#endif
#ifdef _cimg_redefine_max
#define max(a,b) (((a)>(b))?(a):(b))
#endif
#ifdef _cimg_redefine_PI
#define PI 3.141592653589793238462643383
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif
// Local Variables:
// mode: c++
// End: