]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Client/src/item_tank.cpp
El tanque ahora es mas "simpatico" :-D
[z.facultad/75.42/plaqui.git] / Client / src / item_tank.cpp
1
2 #include "item_tank.h"
3 #include <sstream>
4
5 ViewTank::ViewTank(Glib::ustring _name, int orientacion):ViewItem(_name)
6 {
7         switch (orientacion) {
8                 case 0:
9                         image.set(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/tanque_e.png");
10                         in_x = 5;
11                         in_y = 16;
12                         out_x = 64-16;
13                         out_y = 64;
14                         offset_x = 0;
15                         offset_y = 0;
16                         item_offset_x = 0;
17                         item_offset_y = 0;
18                 break;
19                 case 1:
20                         image.set(PACKAGE_DATA_DIR"/plaqui-client/pixmaps/tanque_o.png");
21                         in_x = 64-5;
22                         in_y = 16;
23                         out_x = 16;
24                         out_y = 64;
25                         offset_x = 0;
26                         offset_y = 0;
27                         item_offset_x = 0;
28                         item_offset_y = 0;
29         }
30         image.show();
31         m_or = orientacion;
32         set_size_request();
33 }
34
35 ViewTank::~ViewTank()
36 {
37 }
38
39 std::string ViewTank::get_extra()
40 {
41         std::stringstream ss;
42         std::string s;
43         ss << extra;
44         ss >> s;
45         return s;
46 }
47
48 bool ViewTank::on_image_expose_event(GdkEventExpose *e)
49 {
50         Glib::RefPtr<Gdk::Colormap> colormap = Gtk::Widget::get_default_colormap();
51         Gdk::Color negro = Gdk::Color("black");
52         Gdk::Color blanco = Gdk::Color("white");
53         colormap->alloc_color(negro);
54         colormap->alloc_color(blanco);
55         colormap->alloc_color(color);
56         gc->set_line_attributes(1, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
57         int w,h,x,y,h_offset,y_offset;
58         w = image.get_width();
59         h = image.get_height();
60         
61         if (actual_flow == 0) return true;
62
63         switch (m_or) {
64                 case 0:
65                         x = 5;
66                 break;
67                 case 1:
68                         x = w-w/2-5;
69         }
70         y = 15;
71         w = w/2;
72         h = h/2;
73         y_offset = static_cast<int>(h*(1.0f-extra/actual_flow));
74         h_offset = static_cast<int>(h*(1.0f-extra/actual_flow));
75         gc->set_foreground(negro);
76         gc->set_background(negro);
77         image.get_window()->draw_rectangle(gc, 1, x, y, w, h);
78         gc->set_foreground(color);
79         gc->set_background(color);
80         image.get_window()->draw_rectangle(gc, 1, x, y+y_offset, w, h-h_offset);
81
82         /* Un borde para que se vea bien */
83         gc->set_foreground(blanco);
84         gc->set_background(blanco);
85         image.get_window()->draw_rectangle(gc, 0, x-1, y-1, w+1, h+1);
86         return true;
87 }