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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (hide annotations) (download)
Mon Dec 3 07:49:42 2007 UTC (16 years, 6 months ago) by torben
File size: 2463 byte(s)
Finally, made bullet behaviour as expected

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

  ViewVC Help
Powered by ViewVC 1.1.20