/[H9]/trunk/tntnet/dynamic/bullet.ecpp
ViewVC logotype

Contents of /trunk/tntnet/dynamic/bullet.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations) (download)
Sun Dec 2 20:26:43 2007 UTC (16 years, 5 months ago) by torben
File size: 2422 byte(s)
Silenced compiler warnings

1 <%pre>
2
3 #include "gd-cpp/gdpp.h"
4
5 inline int validColor(int val)
6 {
7 if (val<0)
8 return 0;
9
10 if (val > 255)
11 return 255;
12
13 return val;
14 }
15
16 inline void decodeRGBString(const std::string& rgb, int& red, int& green, int& blue)
17 {
18
19 char *rend=0,*gend=0,*bend=0;
20 int tmpred = strtol( rgb.substr(0,2).c_str(), &rend, 16);
21 int tmpgreen = strtol( rgb.substr(2,2).c_str(), &rend, 16);
22 int tmpblue = strtol( rgb.substr(4,2).c_str(), &rend, 16);
23
24 if (*rend == 0 && *gend==0 && *bend==0)
25 {
26 red = tmpred;
27 green = tmpgreen;
28 blue = tmpblue;
29 }
30 }
31
32 </%pre>
33 <{
34
35 int red = validColor(atoi(qparam.param("r").c_str()));
36 int green = validColor(atoi(qparam.param("g").c_str()));
37 int blue = validColor(atoi(qparam.param("b").c_str()));
38
39 int bg_red = 255;
40 int bg_green = 255;
41 int bg_blue = 255;
42
43 if (qparam.param("bg_r").size() >0)
44 bg_red = validColor(atoi(qparam.param("bg_r").c_str()));
45
46 if (qparam.param("bg_g").size() >0)
47 bg_green = validColor(atoi(qparam.param("bg_g").c_str()));
48
49 if (qparam.param("bg_b").size() >0)
50 bg_blue = validColor(atoi(qparam.param("bg_b").c_str()));
51
52 int size = 20;
53 if (qparam.param("size").size() >0)
54 size = atoi(qparam.param("size").c_str());
55
56
57 if (qparam.param("rgb").size() == 6)
58 {
59 decodeRGBString(qparam.param("rgb"), red, green, blue);
60 }
61
62 if (qparam.param("bg_rgb").size() == 6)
63 {
64 decodeRGBString(qparam.param("bg_rgb"), bg_red, bg_green, bg_blue);
65 }
66
67
68 GD::Image image;
69 image.CreateTrueColor( GD::Size(70,70));
70
71 GD::TrueColor background(bg_red, bg_green, bg_blue);
72 GD::TrueColor grey(128,128,128);
73 GD::TrueColor black(10,10,10);
74 GD::TrueColor status(red,green,blue);
75 GD::TrueColor light(validColor(red+155),validColor(green+155),validColor(blue+155));
76 GD::TrueColor dark(validColor(red-75),validColor(green-75),validColor(blue-75));
77
78
79 image.FilledRectangle( GD::Point(0,0), GD::Point(69,69), background.Int());
80 image.FilledEllipse( 38,38,60,60, grey.Int());
81 image.FilledEllipse( 32,32,60,60, black.Int());
82 image.FilledEllipse( 31,31,50,50, status.Int());
83
84 image.FilledArc(31,31,40,40,0,90,dark.Int(), gdPie);
85 image.FilledArc(31,31,40,40,180,270,light.Int(), gdPie);
86 image.FilledEllipse(31,31,20,20,status.Int());
87
88 GD::Image out;
89 out.CreateTrueColor(size,size);
90 out.CopyResampled(image,0,0,0,0,size,size,70,70);
91
92
93 reply.setContentType("image/png");
94 int img_size;
95 unsigned char* ptr = (unsigned char*) out.Png(&img_size);
96
97 for (int i=0; i<img_size; i++)
98 reply.out() << ptr[i];
99
100 gdFree(ptr);
101
102 }>

  ViewVC Help
Powered by ViewVC 1.1.20