#include "Graphics.hpp" #include #include using namespace std; using namespace net::lliurex::apt; using namespace net::lliurex::apt::graphics; SourceLineBubble::SourceLineBubble(SourceLine line, float width,float height) { this->width=width; this->height=height; this->line=line; /* creating a surface */ surface = Cairo::ImageSurface::create(Cairo::Format::FORMAT_ARGB32,width,height); /* creating a cairo context */ context = Cairo::Context::create(surface); Update(); } SourceLineBubble::~SourceLineBubble() { } void SourceLineBubble::DrawRoundSquare(float x,float y,float width,float height) { float w=3.0f; float v=5.0f; float rwidth = width - (w*2.0f) - (v*2.0f); float rheight = height - (w*2.0f) - (v*2.0f); if(width<6.0)return; //top context->move_to(x,y+w+v); context->curve_to(x,y+w,x+w,y,x+w+v,y); context->line_to(x+w+v+rwidth,y); context->curve_to(x+w+v+rwidth+v,y,x+width,y+w,x+width,y+w+v); //right side context->line_to(x+width,y+w+v+rheight); //bottom context->curve_to(x+width,y+w+v+rheight+v,x+w+v+rwidth+w,y+height,x+w+v+rwidth,y+height); context->line_to(x+w+v,y+height); context->curve_to(x+w,y+height,x,y+w+v+rheight+v,x,y+w+v+rheight); //left side context->line_to(x,y+w+v); } void SourceLineBubble::Update() { double width; double height; double x=5.0; double y=5.0; double f=1.0/256.0; Cairo::TextExtents te; Cairo::FontExtents fe; string source_type; if(line.source_type==SourceType::Deb) source_type="deb"; else source_type="deb-src"; string uri = line.uri; bool special_uri=false; switch(line.uri_type) { case UriType::Http: uri="http://"+uri; break; case UriType::Https: uri="https://"+uri; break; case UriType::Ftp: uri="ftp://"+uri; break; case UriType::Cdrom: uri="cdrom://"+uri; special_uri=true; break; case UriType::File: uri="file://"+uri; special_uri=true; break; } string dist = line.dist; //white background context->set_source_rgb(1.0,1.0,1.0); context->paint(); //black square /* context->set_source_rgb(0.0,0.0,0.0); context->rectangle(1,1,this->width-1,this->height-1); context->stroke(); */ //deb type quare context->select_font_face("Ubuntu", Cairo::FontSlant::FONT_SLANT_NORMAL, Cairo::FontWeight::FONT_WEIGHT_NORMAL); context->set_font_size(12.0); context->get_text_extents(source_type,te); context->get_font_extents(fe); width=te.width; height=(fe.height); width+=20.0f; // 10+10 margins height+=(height*0.8f); y=(this->height/2.0)-(height/2.0); context->set_source_rgb(173*f,255*f,153*f); DrawRoundSquare(x,y,width,height); context->fill(); context->set_source_rgb(0.0,0.0,0.0); context->move_to (x+((width-te.width)/2.0),y+(height)-((height-fe.height)/2.0)-fe.descent); context->show_text(source_type); //uri square x=x+width+5.0; context->get_text_extents(uri,te); context->get_font_extents(fe); width=te.width; height=(fe.height); width+=20.0f; // 10+10 margins height+=(height*0.8f); y=(this->height/2.0)-(height/2.0); if(special_uri) context->set_source_rgb(102*f,153*f,255*f); else context->set_source_rgb(153*f,207*f,255*f); DrawRoundSquare(x,y,width,height); context->fill(); context->set_source_rgb(0.0,0.0,0.0); context->move_to (x+((width-te.width)/2.0),y+(height)-((height-fe.height)/2.0)-fe.descent); context->show_text(uri); //dist x=x+width+5.0; context->get_text_extents(dist,te); context->get_font_extents(fe); width=te.width; height=(fe.height); width+=20.0f; // 10+10 margins height+=(height*0.8f); y=(this->height/2.0)-(height/2.0); context->set_source_rgb(255*f,153*f,180*f); DrawRoundSquare(x,y,width,height); context->fill(); context->set_source_rgb(0.0,0.0,0.0); context->move_to (x+((width-te.width)/2.0),y+(height)-((height-fe.height)/2.0)-fe.descent); context->show_text(dist); //components for(int n=0;nget_text_extents(line.components[n],te); context->get_font_extents(fe); width=te.width; height=(fe.height); width+=20.0f; // 10+10 margins height+=(height*0.8f); y=(this->height/2.0)-(height/2.0); context->set_source_rgb(255*f,214*f,153*f); DrawRoundSquare(x,y,width,height); context->fill(); context->set_source_rgb(0.0,0.0,0.0); context->move_to (x+((width-te.width)/2.0),y+(height)-((height-fe.height)/2.0)-fe.descent); context->show_text(line.components[n]); } }