From 16f64e28170d4473eebaa309d3082785c32b809c Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Sun, 30 Nov 2003 22:03:25 +0000 Subject: [PATCH] Se corrige el bug en la union (del modelo) que probablemente era el error de visualizacion del color en la union. Queda algo en el tanque que ahora vere. --- Client/src/item_codo.cpp | 2 +- Client/src/item_exclusa.cpp | 2 +- Client/src/item_pump.cpp | 7 +++++-- Client/src/item_union.cpp | 10 ++++++++-- Client/src/principal.cpp | 1 + Model/src/main.cpp | 2 +- Model/src/simulator.cpp | 6 +++++- Model/src/union.cpp | 9 +++------ 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Client/src/item_codo.cpp b/Client/src/item_codo.cpp index e0a1a1c..73dee42 100644 --- a/Client/src/item_codo.cpp +++ b/Client/src/item_codo.cpp @@ -27,7 +27,7 @@ ViewCodo::~ViewCodo() bool ViewCodo::on_image_expose_event(GdkEventExpose *e) { - Glib::RefPtr colormap = image.get_colormap(); + Glib::RefPtr colormap = Gtk::Widget::get_default_colormap(); Gdk::Color blanco = Gdk::Color("white"); colormap->alloc_color(color); gc->set_foreground(color); diff --git a/Client/src/item_exclusa.cpp b/Client/src/item_exclusa.cpp index d09ad8a..4a3e7b4 100644 --- a/Client/src/item_exclusa.cpp +++ b/Client/src/item_exclusa.cpp @@ -37,7 +37,7 @@ ViewExclusa::~ViewExclusa() bool ViewExclusa::on_image_expose_event(GdkEventExpose *e) { - Glib::RefPtr colormap = image.get_colormap(); + Glib::RefPtr colormap = Gtk::Widget::get_default_colormap(); colormap->alloc_color(color); gc->set_foreground(color); gc->set_background(color); diff --git a/Client/src/item_pump.cpp b/Client/src/item_pump.cpp index 536a884..70201be 100644 --- a/Client/src/item_pump.cpp +++ b/Client/src/item_pump.cpp @@ -37,8 +37,11 @@ ViewPump::~ViewPump() bool ViewPump::on_image_expose_event(GdkEventExpose *e) { - Glib::RefPtr colormap = image.get_colormap(); - colormap->alloc_color(color); + Glib::RefPtr colormap = Gtk::Widget::get_default_colormap(); + if (!colormap->alloc_color(color, true, true)) { + std::cout << name << ": Error alocando color!" << std::endl; + } + gc->set_foreground(color); gc->set_background(color); gc->set_line_attributes(6, Gdk::LINE_SOLID, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER); diff --git a/Client/src/item_union.cpp b/Client/src/item_union.cpp index 4bfd2ff..eee974e 100644 --- a/Client/src/item_union.cpp +++ b/Client/src/item_union.cpp @@ -28,10 +28,16 @@ ViewUnion::~ViewUnion() bool ViewUnion::on_image_expose_event(GdkEventExpose *e) { - Glib::RefPtr colormap = image.get_colormap(); - colormap->alloc_color(color); + Glib::RefPtr colormap = Gtk::Widget::get_default_colormap(); + if (!colormap->alloc_color(color, false, false)) { + std::cout << "ERROR ALOCANDO COLOR!" << std::endl; + } gc->set_foreground(color); gc->set_background(color); + + if (name == "union6") { + std::cout << color.get_red() << " " << color.get_green() << " " << color.get_blue() << std::endl; + } int w,h; w = image.get_width(); h = image.get_height(); diff --git a/Client/src/principal.cpp b/Client/src/principal.cpp index 870c06a..c73f2c8 100644 --- a/Client/src/principal.cpp +++ b/Client/src/principal.cpp @@ -816,6 +816,7 @@ Gdk::Color Principal::get_rgb_from_xml(xmlNodePtr nodo) b = static_cast(65535 * (b / 255.0f)); Gdk::Color c; c.set_rgb(r,g,b); + return c; } diff --git a/Model/src/main.cpp b/Model/src/main.cpp index 7c7f1e3..8671daa 100644 --- a/Model/src/main.cpp +++ b/Model/src/main.cpp @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) } i++; sim->simulate(); - //std::cout << sim->get_state_as_xml() << std::endl << std::endl; + std::cout << sim->get_state_as_xml() << std::endl << std::endl; } delete sim; diff --git a/Model/src/simulator.cpp b/Model/src/simulator.cpp index 981b546..66148f2 100644 --- a/Model/src/simulator.cpp +++ b/Model/src/simulator.cpp @@ -545,7 +545,7 @@ std::string Simulator::get_state_as_xml() RGB Simulator::loadRGB(xmlNodePtr nodo) { - unsigned r,g,b; + unsigned long r,g,b; while (nodo != NULL) { if (nodo->type == XML_ELEMENT_NODE) { if (xmlStrcmp(nodo->name, BAD_CAST"rojo")==0) @@ -557,6 +557,10 @@ RGB Simulator::loadRGB(xmlNodePtr nodo) } nodo = nodo->next; } + r = static_cast(255 * (r / 65535.0f)); + g = static_cast(255 * (g / 65535.0f)); + b = static_cast(255 * (b / 65535.0f)); + return RGB(r,g,b); } diff --git a/Model/src/union.cpp b/Model/src/union.cpp index 65b1e7b..450b6e6 100644 --- a/Model/src/union.cpp +++ b/Model/src/union.cpp @@ -109,12 +109,9 @@ void Union::recieve_msg(int msg, IConector *who, void *data) if (flow2 == 0) n--; float suma = flow1+flow2; if (n != 0) { - r = (int)(color1.r()*flow1/suma + color2.r()*flow2/suma)/n; - g = (int)(color1.g()*flow1/suma + color2.g()*flow2/suma)/n; - b = (int)(color1.b()*flow1/suma + color2.b()*flow2/suma)/n; - r %= 256; - g %= 256; - b %= 256; + r = (int)(color1.r()*flow1/suma + color2.r()*flow2/suma); + g = (int)(color1.g()*flow1/suma + color2.g()*flow2/suma); + b = (int)(color1.b()*flow1/suma + color2.b()*flow2/suma); set_color(RGB(r,g,b)); } else { set_color(RGB(0,0,0)); -- 2.43.0