void Alpha::draw_section(clan::Canvas &canvas, clan::Font &font, int yoffset, const clan::Colorf &background, const clan::Colorf &vertex_colour, const clan::Colorf &image_colour) { // Draw the background without blending to set the specified RGBA canvas.set_blend_state(blend_disabled); const int outer_area_size = 32; const int outer_xoffset = 8; canvas.fill_rect( outer_xoffset, yoffset, outer_xoffset + outer_area_size, yoffset + outer_area_size, background); canvas.set_blend_state(blend_enabled); // Create the image clan::Image image = create_block(canvas, image_colour); // Draw the image image.set_color(vertex_colour); image.draw(canvas, outer_xoffset + (outer_area_size - image.get_width())/2, yoffset + (outer_area_size - image.get_height())/2); // Get the composited pixel buffer clan::Rect rect(outer_xoffset + outer_area_size / 2, (yoffset + outer_area_size / 2), clan::Size(64,64)); clan::PixelBuffer pbuff = canvas.get_pixeldata(rect, clan::tf_rgba8); pbuff.lock(canvas, clan::access_read_only); clan::ImageProviderFactory::save(pbuff, "test.png"); clan::Colorf output = pbuff.get_pixel(0,0); pbuff.unlock(); // Create the information string std::string info(clan::string_format("Initial Destination Colour: RGBA = %1, %2, %3, %4", background.r , background.g, background.b, background.a)); int xpos = outer_xoffset + outer_area_size + 8; int ypos = yoffset - 4; font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Vertex Colour: RGBA = %1, %2, %3, %4", vertex_colour.r , vertex_colour.g, vertex_colour.b, vertex_colour.a)); ypos += 16; font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Image Colour: RGBA = %1, %2, %3, %4", image_colour.r , image_colour.g, image_colour.b, image_colour.a)); ypos += 16; font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Destination Colour: RGBA = %1, %2, %3, %4", output.r , output.g, output.b, output.a)); ypos += 16; font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black); }
void Alpha::draw_section(clan::Canvas &canvas, clan::Font &font, int yoffset, const clan::Colorf &background, const clan::Colorf &vertex_colour, const clan::Colorf &image_colour) { // Draw the background without blending to set the specified RGBA canvas.set_blend_state(blend_disabled); const int outer_area_size = 32; const int outer_xoffset = 8; canvas.fill_rect( outer_xoffset, yoffset, outer_xoffset + outer_area_size, yoffset + outer_area_size, background); canvas.set_blend_state(blend_enabled); // Create the image clan::Image image = create_block(canvas, image_colour); // Draw the image image.set_color(vertex_colour); image.draw(canvas, outer_xoffset + (outer_area_size - image.get_width())/2, yoffset + (outer_area_size - image.get_height())/2); clan::Colorf output; // Get the composited pixel buffer clan::Rectf rect(outer_xoffset + outer_area_size / 2, (yoffset + outer_area_size / 2), clan::Sizef(64,64)); if (rect.is_inside(canvas.get_size())) { clan::PixelBuffer pbuff = canvas.get_pixeldata(rect, clan::tf_rgba8); pbuff.lock(canvas, clan::access_read_only); //clan::ImageProviderFactory::save(pbuff, "test.png"); clan::Colorf output = pbuff.get_pixel(0, 0); pbuff.unlock(); } // Create the information string std::string info(clan::string_format("Background = %1, %2, %3, %4", get_text(background.r), get_text(background.g), get_text(background.b), get_text(background.a))); int xpos = outer_xoffset + outer_area_size + 8; int ypos = yoffset + 12; font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Vertex = %1, %2, %3, %4", get_text(vertex_colour.r), get_text(vertex_colour.g), get_text(vertex_colour.b), get_text(vertex_colour.a))); font.draw_text(canvas, xpos + 250, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Image = %1, %2, %3, %4", get_text(image_colour.r), get_text(image_colour.g), get_text(image_colour.b), get_text(image_colour.a))); font.draw_text(canvas, xpos + 500, ypos, info, clan::Colorf::black); ypos += 20; clan::Colorf source(vertex_colour * image_colour); clan::Colorf calculated; calculated.r = source.a * source.r + (1.0f - source.a) * background.r; calculated.g = source.a * source.g + (1.0f - source.a) * background.g; calculated.b = source.a * source.b + (1.0f - source.a) * background.b; calculated.a = source.a + (1.0f - source.a) * background.a; info = std::string(clan::string_format("Source = %1, %2, %3, %4", get_text(source.r), get_text(source.g), get_text(source.b), get_text(source.a))); font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Calculated = %1, %2, %3, %4", get_text(calculated.r), get_text(calculated.g), get_text(calculated.b), get_text(calculated.a))); font.draw_text(canvas, xpos + 250, ypos, info, clan::Colorf::black); info = std::string(clan::string_format("Actual = %1, %2, %3, %4", get_text(output.r), get_text(output.g), get_text(output.b), get_text(output.a))); font.draw_text(canvas, xpos + 500, ypos, info, clan::Colorf::black); }