Exemplo n.º 1
0
	bool MainWindow::first_draw(const Cairo::RefPtr<Cairo::Context>& cr)
	{
		Gtk::Allocation allocation = m_first.get_allocation();
		cr->set_source_rgba(0, 0, 0, 1);
		cr->rectangle(0, 0, allocation.get_width(), allocation.get_height());
		cr->fill();

		if(m_png)
		{
			cr->set_source(m_png, 0, 0);
			cr->paint();
		}

		return true;
	}
Exemplo n.º 2
0
//! Composited all layers into the first layer
void Renderer::compositeLayers(CairoLayer layers[]) const
{
	Cairo::RefPtr<Cairo::Context> cr = layers[0].cr;

	cr->save();

	for (int i = 1; i < LAYER_NUM; i++) {
		layers[i].surface->flush();
		cr->set_source(layers[i].surface, 0.0, 0.0);
		cr->paint();
		layers[i].clear();
	}

	cr->restore();
}
Exemplo n.º 3
0
      virtual bool on_expose_event(GdkEventExpose* event) {
        Glib::RefPtr<Gdk::Window> window = get_window();

        if (!window || !m_surface)
          return true;

        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
        cr->clip();

        cr->set_source(m_surface, 0, 0);
        cr->paint();

        return true;
      }
Exemplo n.º 4
0
  bool on_draw(const Cairo::RefPtr<Cairo::Context>& c) {
    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height();

    RefPtr<ImageSurface> img = gm.get_surface();
    double s = get_scale();
    if (s < 1.0)
      c->scale(s,s);
    c->set_source_rgb(0, 0, 0);
    c->paint();
    c->set_source(img, 0, 0);
    c->paint();

    return true;
  }
Exemplo n.º 5
0
void ItemView::drawInnerShadow(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
    cr->set_antialias(Cairo::ANTIALIAS_DEFAULT);

    const int SIZE = height * 0.1;
    const double ALPHA = 0.2;
    const int x = TIME_WIDTH - SIZE;
    const int y = 0;

    Cairo::RefPtr<Cairo::LinearGradient> linearGradient = Cairo::LinearGradient::create(x, y, x + SIZE, y);
    linearGradient->add_color_stop_rgba(0, 0.00, 0.00, 0.00, 0.0);
    linearGradient->add_color_stop_rgba(1, 0.00, 0.00, 0.00, ALPHA);

    cr->set_source(linearGradient);
    cr->rectangle(x, y, SIZE, height);
    cr->fill();
}
Exemplo n.º 6
0
bool ImageDrawable::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
	Gtk::Allocation allocation = get_allocation();

	//cout << "draw " << awidth << "x" << aheight << endl;

	auto surface = Cairo::ImageSurface::create(Cairo::Format::FORMAT_RGB24, allocation.get_width(), allocation.get_height());
	auto cr2 = Cairo::Context::create(surface);
	copyCairoClip(cr, cr2);
	drawImage(cr2, allocation);

	//auto start = chrono::steady_clock::now();
	cr->set_source(surface, 0, 0);
	cr->paint();
	//auto stop = chrono::steady_clock::now();
	//cout << "copy " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl;

	return true;
}
Exemplo n.º 7
0
void CairoPlugin::copy()
{
    if (m_init) {
        init();
    }

    if (m_need) {
        Cairo::RefPtr < Cairo::Context > ctx = Cairo::Context::create(m_store);

        ctx->save();
        ctx->set_source(m_img, 0.0, 0.0);
        ctx->paint();
        ctx->restore();

        m_need = false;
        m_copydone = true;
    }
}
Exemplo n.º 8
0
void CardWidget::Draw(Cairo::RefPtr<Cairo::Context> cr, int x, int y)
{
	bool highlight = highlightOnHover && isMouseInArea;
	Cairo::RefPtr<Cairo::ImageSurface> image = PrefSlots::getImagesStorage().GetCardImage(card);
	cr->save();
	cr->translate(x, y);
	cr->scale(1.0 * width / image->get_width(), 1.0 * height / image->get_height());
	cr->rectangle(0, 0, image->get_width(), image->get_height());
	cr->clip();
	if( highlight ) {
		cr->save();
		cr->set_source_rgb(0.1, 0.8, 0.1);
		cr->paint();
		cr->restore();
	}
	cr->set_source(image, 0, 0);
	cr->paint_with_alpha( highlight ? 0.7 : 1.0 );
	cr->restore();
}
Exemplo n.º 9
0
  /** Post-process files. Only valid for PNGs. */
  void postprocess()
  {
    printf("Post-processing PNG files, resizing to %fx%f\n", maxwidth, maxheight);
    struct dirent *d;
    DIR *output_dir = opendir(outdir.c_str());
    while ((d = readdir(output_dir)) != NULL) {
      if (fnmatch("*.png", d->d_name, FNM_PATHNAME | FNM_PERIOD) == 0) {
	infile = outdir + "/" + d->d_name;
	Cairo::RefPtr<Cairo::ImageSurface> imgs = Cairo::ImageSurface::create_from_png(infile);
	if ( (imgs->get_height() != maxheight) || (imgs->get_width() != maxwidth)) {
	  // need to re-create
	  char *tmpout = strdup((outdir + "/tmpXXXXXX").c_str());
	  FILE *f = fdopen(mkstemp(tmpout), "w");
	  outfile = tmpout;
	  free(tmpout);

	  Cairo::RefPtr<Cairo::ImageSurface> outs = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
										(int)ceilf(maxwidth),
										(int)ceilf(maxheight));
	  double tx = (maxwidth  - imgs->get_width()) / 2.0;
	  double ty = (maxheight - imgs->get_height()) / 2.0;
	  printf("Re-creating %s for post-processing, "
		 "resizing from %ix%i, tx=%f, ty=%f\n", infile.c_str(),
		 imgs->get_width(), imgs->get_height(), tx, ty);
	  Cairo::RefPtr<Cairo::Context> cc = Cairo::Context::create(outs);
	  if (white_bg) {
	    cc->set_source_rgb(1, 1, 1);
	    cc->paint();
	  }
	  cc->set_source(imgs, tx, ty);
	  cc->paint();
	  outs->write_to_png(&SkillGuiBatchRenderer::write_func, f);
	  imgs.clear();
	  cc.clear();
	  outs.clear();
	  fclose(f);
	  rename(outfile.c_str(), infile.c_str());
	}
      }
    }
    closedir(output_dir);
  }
Exemplo n.º 10
0
bool level_editor::tileset_display::on_expose_event(GdkEventExpose* event) {
  Glib::RefPtr<Gdk::Window> window = get_window();

  if (!window || !m_surface)
    return true;

  Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
  cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
  cr->clip();

  cr->set_source(m_surface, 0, 0);
  cr->paint();

  // Show selection rectangle when we are selecting
  if (m_selecting
      || ((m_select_x != m_select_end_x || m_select_y != m_select_end_y)
          && m_preferences.sticky_tile_selection)) {
    const int x = std::min(m_select_x, m_select_end_x) * m_tile_width;
    const int y = std::min(m_select_y, m_select_end_y) * m_tile_height;

    const int w = (std::abs(m_select_x - m_select_end_x))
                    * m_tile_width;
    const int h = (std::abs(m_select_y - m_select_end_y))
                    * m_tile_height;

    cr->save();
      cr->rectangle(x, y, w, h);
      // TODO: move selection color somewhere else (preferences?)
      cr->set_source_rgb(0.7, 1, 1);
      if (m_preferences.selection_background) {
        cr->stroke_preserve();
        cr->set_source_rgba(0.7, 1, 0, 0.2);
        cr->fill();
      } else {
        cr->stroke();
      }
    cr->restore();
  }

  return true;
}
Exemplo n.º 11
0
    void NodeSurface::DrawIcon( 
        Cairo::RefPtr<Cairo::Context> refCairo, 
        Cairo::RefPtr<Cairo::ImageSurface> refIconSurface,
        Glib::RefPtr<Gdk::Pixbuf> pixbufIcon,
        int x,
        int y )
    {
        refCairo->save();

        Cairo::RefPtr<Cairo::Context> refCairoIcon = Cairo::Context::create(refIconSurface);
        Gdk::Cairo::set_source_pixbuf( refCairoIcon, pixbufIcon, 0.0, 0.0 );
        refCairoIcon->paint();

        int width = pixbufIcon->get_width();
        int height = pixbufIcon->get_height();

        refCairo->set_source( refIconSurface, x - (width/2), y - (height/2) );
        refCairo->paint();

        refCairo->restore();
    }     
Exemplo n.º 12
0
void NodeRenderer::icon(const Cairo::RefPtr<Cairo::Context>& cr, IconCache& cache)
{
	// path to icon not set
	if (s->icon.str().size() == 0 || s->icon_width == 0.0 || s->icon_height == 0.0)
		return;

	cr->save();

	Cairo::RefPtr<Cairo::ImageSurface> image = cache.getIcon(s->icon.str());
	double width = s->icon_width < 0 ? image->get_width() : s->icon_width;
	double height = s->icon_height < 0 ? image->get_height() : s->icon_height;
	double x0 = floor(location.x - width/2.0);
	double y0 = floor(location.y - height/2.0);
	cr->translate(x0, y0);
	cr->scale(width / image->get_width(),
			  height / image->get_height());
	cr->set_source(image, 0, 0);
	cr->paint();

	cr->restore();
}
Exemplo n.º 13
0
bool avatar::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
    Glib::RefPtr<Gtk::StyleContext> style = get_style_context();

    int w = get_allocated_width();
    int h = get_allocated_height();

    auto surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, w * get_scale_factor(), h * get_scale_factor());
    auto tmp_cr = Cairo::Context::create(surface);
    tmp_cr->scale(get_scale_factor(), get_scale_factor());

    // Render image
    Glib::RefPtr<Gdk::Pixbuf> pix = property_pixbuf();
    if (pix) {
        tmp_cr->save();
        double pw = pix->get_width();
        double ph = pix->get_height();
        tmp_cr->scale(w/pw, h/ph);
        Gdk::Cairo::set_source_pixbuf(tmp_cr, pix);
        tmp_cr->paint();
        tmp_cr->restore();
    }

    // Render the background
    tmp_cr->set_operator(Cairo::OPERATOR_DEST_ATOP);
    style->render_background(tmp_cr, 0, 0, w, h);

    // Change to default operator
    tmp_cr->set_operator(Cairo::OPERATOR_OVER);

    // Render frame
    style->render_frame(tmp_cr, 0, 0, w, h);

    // Render to the right surface
    cr->scale(1.0/get_scale_factor(), 1.0/get_scale_factor());
    cr->set_source(surface, 0, 0);
    cr->paint();

    return false;
}
Exemplo n.º 14
0
void ImageWidget::redrawWithoutChanges(Cairo::RefPtr<Cairo::Context> cairo, unsigned width, unsigned height)
{
	if(_isInitialized) {
		cairo->set_source_rgb(1.0, 1.0, 1.0);
		cairo->set_line_width(1.0);
		cairo->rectangle(0, 0, width, height);
		cairo->fill();
		
		int
			destWidth = width - (int) floor(_leftBorderSize + _rightBorderSize),
			destHeight = height - (int) floor(_topBorderSize + _bottomBorderSize),
			sourceWidth = _imageSurface->get_width(),
			sourceHeight = _imageSurface->get_height();
		cairo->save();
		cairo->translate((int) round(_leftBorderSize), (int) round(_topBorderSize));
		cairo->scale((double) destWidth / (double) sourceWidth, (double) destHeight / (double) sourceHeight);
		Cairo::RefPtr<Cairo::SurfacePattern> pattern = Cairo::SurfacePattern::create(_imageSurface);
		pattern->set_filter(_cairoFilter);
		cairo->set_source(pattern);
		cairo->rectangle(0, 0, sourceWidth, sourceHeight);
		cairo->clip();
		cairo->paint();
		cairo->restore();
		cairo->set_source_rgb(0.0, 0.0, 0.0);
		cairo->rectangle(round(_leftBorderSize), round(_topBorderSize), destWidth, destHeight);
		cairo->stroke();

		if(_showColorScale)
			_colorScale->Draw(cairo);
		if(_showXYAxes)
		{
			_vertScale->Draw(cairo);
			_horiScale->Draw(cairo);
		}
		if(_plotTitle != 0)
			_plotTitle->Draw(cairo);
	}
}
Exemplo n.º 15
0
void
FourdThumbnailer::receive_frame(Cairo::RefPtr<Cairo::ImageSurface> img, gint64 pos)
{
  if (!m_buffer)
  {
    m_buffer = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24,
                                           img->get_width() * 10,
                                           img->get_height());
  }

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(m_buffer);

  int slice_width = m_buffer->get_width() / m_slices;
  cr->rectangle((slice_width * m_count), 0,
                slice_width, m_buffer->get_height());
  cr->clip();

  cr->begin_new_path();
  cr->set_source(img, m_count * (m_buffer->get_width() - img->get_width()) / (m_slices-1), 0);
  cr->paint();

  m_count += 1;
}
Exemplo n.º 16
0
void ImageDrawable::drawImage(const Cairo::RefPtr<Cairo::Context> &cr, const Gtk::Allocation &allocation) {
	auto image = images->current();
	auto surface = image->getPrimary();
	int rwidth, rheight;
	double rscale;
	double rx, ry;

	//cout << "image " << iwidth << "x" << iheight << " " << iorientation.first << "," << iorientation.second << endl;

	calcRenderedImage(image, allocation, rwidth, rheight, rscale, rx, ry);

	cr->translate(rx, ry);
	cr->scale(rscale, rscale);

	waiting = !surface;

	if (image->isPrimaryFailed()) {
		// TODO display fancy failed indicator
		cr->set_source_rgb(0.75, 0.5, 0.5);
		cr->rectangle(0, 0, rwidth, rheight);
		cr->clip();
		cr->paint();
		return;
	} else if (!surface) {
		// TODO display fancy loading animation
		cr->set_source_rgb(0.5, 0.75, 0.5);
		cr->rectangle(0, 0, rwidth, rheight);
		cr->clip();
		cr->paint();
		return;
	}

	switch (image->getOrientation().first) {
	case Image::Rotate::ROTATE_NONE:
		break;

	case Image::Rotate::ROTATE_90:
		cr->translate(image->height(), 0);
		cr->rotate_degrees(90);
		break;

	case Image::Rotate::ROTATE_180:
		cr->translate(image->width(), image->height());
		cr->rotate_degrees(180);
		break;

	case Image::Rotate::ROTATE_270:
		cr->translate(0, image->width());
		cr->rotate_degrees(270);
		break;
	}

	if (image->getOrientation().second) {
		cr->translate(image->width(), 0);
		cr->scale(-1, 1);
	}

	auto pattern = Cairo::SurfacePattern::create(surface);
	pattern->set_filter(Cairo::Filter::FILTER_FAST);
	cr->set_source(pattern);

	//auto start = chrono::steady_clock::now();
	cr->paint();
	//auto stop = chrono::steady_clock::now();
	//cout << "paint " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl;

	if (afPoints) {
		//start = chrono::steady_clock::now();
		auto properties = image->getProperties();
		valarray<double> dashes(5.0 / rscale, 5.0 / rscale);

		cr->save();
		cr->set_operator(static_cast<Cairo::Operator>(CAIRO_OPERATOR_DIFFERENCE));

		for (auto &rect : properties.focusPoints) {
			if (properties.focusPointsActive.find(rect) != properties.focusPointsActive.cend()) {
				cr->set_source_rgb(1, 0, 1);
				cr->set_line_width(4.0 / rscale);
				cr->unset_dash();
			} else if (properties.focusPointsSelected.find(rect) != properties.focusPointsSelected.cend()) {
				cr->set_source_rgb(1, 0, 0);
				cr->set_line_width(2.0 / rscale);
				cr->unset_dash();
			} else {
				cr->set_source_rgb(1, 1, 1);
				cr->set_line_width(1.0 / rscale);
				cr->set_dash(dashes, 0);
			}
			cr->rectangle(rect.x, rect.y, rect.width, rect.height);
			cr->stroke();
		}

		cr->restore();

		//stop = chrono::steady_clock::now();
		//cout << "afpaint " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl;
	}
}
Exemplo n.º 17
0
Cairo::RefPtr<Cairo::ImageSurface>
TextSurface::create_cairo_surface(const std::string& text, const TextProperties& text_props,
                                  Cairo::TextExtents& out_text_extents,
                                  Cairo::FontExtents& out_font_extents)
{
  { // get TextExtents and FontExtents
    Cairo::RefPtr<Cairo::ImageSurface> tmp_surface = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, 0, 0);
    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(tmp_surface);
    cr->set_font_size(text_props.get_font_size());
    cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
    cr->get_text_extents(text, out_text_extents);
    cr->get_font_extents(out_font_extents);
  }

  Cairo::RefPtr<Cairo::ImageSurface>
    surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
                                          static_cast<int>(out_text_extents.width  + text_props.get_line_width()),
                                          static_cast<int>(out_text_extents.height + text_props.get_line_width()));

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  // set the font
  cr->set_font_size(text_props.get_font_size());
  cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);

  if (text_props.get_line_width() != 0)
  {
    // create path
    cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0,
                -out_text_extents.y_bearing + text_props.get_line_width()/2.0);
    cr->text_path(text);

    // paint
    cr->set_line_width(text_props.get_line_width());
    cr->set_line_join(Cairo::LINE_JOIN_ROUND);
    cr->set_source_rgb(0.0, 0.0, 0.0);
    cr->stroke();
  }

  // print text
  cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0,
              -out_text_extents.y_bearing + text_props.get_line_width()/2.0);
  cr->set_source_rgb(1.0, 1.0, 0.0);

  double y = -out_text_extents.y_bearing - out_font_extents.ascent;

  // toying around with color gradients
  if (false)
  {
    Cairo::RefPtr<Cairo::LinearGradient> gradient = Cairo::LinearGradient::create(0, y,
                                                                                  0, y + out_font_extents.ascent + out_font_extents.descent);
    gradient->add_color_stop_rgb(0.0, 1.0, 1.0, 0.0);
    gradient->add_color_stop_rgb(0.5, 1.0, 1.0, 1.0);
    gradient->add_color_stop_rgb(0.5, 0.4, 0.4, 0.2);
    gradient->add_color_stop_rgb(1.0, 1.0, 1.0, 0.0);
    cr->set_source(gradient);
  }

  cr->show_text(text);

  return surface;
}
Exemplo n.º 18
0
void level_editor::tileset_display::update_tileset(const std::string& level_name) {
  // find the main tileset and draw it first, then the others
  level_editor::tileset_list_type::iterator main_iter;
  level_editor::tileset_list_type::iterator iter, end;
  end = m_preferences.tilesets.end();
  main_iter = m_preferences.tilesets.end();

  for (iter = m_preferences.tilesets.begin();
       iter != end;
       iter ++) {
    // prefix matches level name
    if (iter->main && iter->active && level_name.find(iter->prefix) != std::string::npos) {
      // prefer tilesets with a longer prefix
      if (main_iter == end || main_iter->prefix.size() < iter->prefix.size()) {
        main_iter = iter;
      }
    }
  }
  
  Cairo::RefPtr<Cairo::ImageSurface> main;
  if (main_iter == m_preferences.tilesets.end()) {
    // No matching main tileset, use default image and display error
    // TODO: actually display an error box here
    //std::cerr <<
    //  "No valid tileset found, please add atleast one main tileset to the "
    //  "tileset list that matches the current level." << std::endl;
    main = m_image_cache.get_image("internal/no_img.png");
  } else {
    main = m_image_cache.get_image(main_iter->name);
  }
  //std::cout << "creating surface" << std::endl;
  const int main_width = main->get_width();
  const int main_height = main->get_height();
  m_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, main_width, main_height);

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(m_surface);

  cr->set_source(main, 0, 0);
  cr->paint();

  // now draw the rest
  end = m_preferences.tilesets.end();
  for (iter = m_preferences.tilesets.begin();
       iter != end;
       iter ++) {
    // prefix matches level name
    if (level_name.find(iter->prefix) != std::string::npos && !iter->main) {
      Cairo::RefPtr<Cairo::ImageSurface> ts = m_image_cache.get_image(iter->name);
      // Ignore other matching main tilesets
      if (!iter->main && iter->active) {
        cr->set_source(ts, iter->x, iter->y);
      }
      cr->paint();
    }
  }

  set_size_request(main_width, main_height);

  queue_draw();
  // Fire signal to users
  m_signal_tileset_updated(m_surface);
}
Exemplo n.º 19
0
bool knob::on_expose_event(GdkEventExpose* event)
{

  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window)
  {
    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height() - (allocation.get_height()/3);
    const int height_offset = allocation.get_height()/6;

    // coordinates for the center of the window
    int xc, yc;
    xc = width / 2;
    yc = height / 2;

    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
    cr->set_line_width(6.0);

    // clip to the area indicated by the expose event so that we only redraw
    // the portion of the window that needs to be redrawn
    cr->rectangle(event->area.x, event->area.y,
            event->area.width, event->area.height);
    cr->clip();
    
    // background grad

	Cairo::RefPtr<Cairo::LinearGradient> back_grad =
	Cairo::LinearGradient::create( 0,0,0,allocation.get_height() );

	switch (pos_mode)
	{
		case 0:
	        back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
	        back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
		break;

		case 1:
	        back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
	        back_grad->add_color_stop_rgba(1,
			(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
			(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
			(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
			1);
		break;

		case 2:
	        back_grad->add_color_stop_rgba(0,
			(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
			(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
			(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
			1);
	        back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
		break;
	}

	// fill background
	if (rounded<5)
	{
		rounded_rectangle(cr,rounded, grad_top_colour,
			grad_bottom_colour, event->area.x, event->area.y,
			event->area.width, event->area.height,pos_mode,
			top_colour.to_string(),bottom_colour.to_string() );
	}
	else 
	{
		cr->rectangle(event->area.x, event->area.y,
			event->area.width, event->area.height);
	}


	cr->set_source(back_grad);
	cr->fill();
    
    // ------------------------------------------------------------------

	float cos_x =  (allocation.get_width()/5) * (cos(((((1-knob_value)*0.75)-0.3)*2) * M_PI));
	float sin_y =  (allocation.get_width()/5) * (sin(((((1-knob_value)*0.75)-0.3)*2) * M_PI));

     Cairo::RefPtr<Cairo::RadialGradient> grad1 =
Cairo::RadialGradient::create( (allocation.get_width()/2) + sin_y, (allocation.get_height()/2) + cos_x, 0, (allocation.get_width()/2) , (allocation.get_height()/2) ,(allocation.get_width()/2.5));
        grad1->add_color_stop_rgba(0,0.4,0.4,0.4,1);
        grad1->add_color_stop_rgba(0.5,0.2,0.2,0.2,1);
        grad1->add_color_stop_rgba(0.8,0.17,0.17,0.17,1);
        grad1->add_color_stop_rgba(1.0,0.0,0.0,0.0,1);

	cos_x =  (allocation.get_width()/5) * (cos((((knob_value*0.75)-0.61)*2) * M_PI));
	sin_y =  (allocation.get_width()/5) * (sin((((knob_value*0.75)-0.61)*2) * M_PI));

	cr->set_source(grad1);
	cr->arc(allocation.get_width()/2, allocation.get_height()/2, (allocation.get_width()/2.5), 0.0, 2 * M_PI);
	cr->fill();
	cr->set_source_rgb(0.0, 0.0, 0.0);
	cr->arc((allocation.get_width()/2) +cos_x, (allocation.get_height()/2)+sin_y, (allocation.get_width()/16), 0.0, 2 * M_PI);
	cr->fill();

    // draw text label
    cr->select_font_face("Bitstream Vera Sans", Cairo::FONT_SLANT_NORMAL,
     Cairo::FONT_WEIGHT_NORMAL);
    cr->set_font_size(width/4.5);
    cr->set_source_rgba(0.9,0.9,0.9,0.8);
    Cairo::FontOptions font_options;
    font_options.set_hint_style(Cairo::HINT_STYLE_NONE);
    font_options.set_hint_metrics(Cairo::HINT_METRICS_OFF);
    font_options.set_antialias(Cairo::ANTIALIAS_GRAY);
	
    int x_font_centre = (width/2) - ((width/5) * (label.length()/3.5));

    cr->set_font_options(font_options);
    cr->move_to(x_font_centre,height/3.5);
    cr->show_text(label);
    cr->move_to(x_font_centre,allocation.get_height()  - (height_offset/3) );

    ostringstream slider_value;
    slider_value.str("");

    if (invert)
    {
	slider_value << max - value;
    }
    else
    {
    	slider_value << value;
    }

    slider_value.str(slider_value.str().substr(0,5));

    x_font_centre = (width/2) - ((width/5) * (slider_value.str().length()/3.5));
    cr->move_to(x_font_centre,allocation.get_height() - (height_offset/1.5) );

    cr->show_text(slider_value.str());

  }

  return true;
}
Exemplo n.º 20
0
	void set_source__(Glib::ustring& src,Glib::ustring& x,Glib::ustring& y){
		Cairo::RefPtr< Cairo::ImageSurface > is;
		is = Cairo::ImageSurface::create_from_png (src);
		cr_->set_source(is,s2f__(x),s2f__(y));
	}
Exemplo n.º 21
0
void MyWidget::drawWidget()
{
    Painter p(this);

    if (m_color) {
        p.setSourceRGB(1.0, 0, 0);
    } else {
        p.setSourceRGB(0, 0, 0);
    }

    p.translate(minimumSize().width() / 2.0, minimumSize().height() / 2.0);
    p.setLineWidth(m_lineWidth);
    p.arc(0, 0, m_radius, 0, 2 * M_PI);
    p.save();

    p.setSourceRGBA(1.0, 1.0, 1.0, 0.8);
    p.fillPreserve();
    p.restore();
    p.strokePreserve();
    p.clip();

    for (int i = 0; i < 12; ++i) {
        double inset = 30;

        p.save();
        p.setLineCap(Painter::RoundLineCap);

        if(i % 3 != 0) {
            inset *= 0.8;
            p.setLineWidth(1.0);
        }

        p.moveTo((m_radius - inset) * cos (i * M_PI / 6.0),
                 (m_radius - inset) * sin (i * M_PI / 6.0));
        p.lineTo(m_radius * cos (i * M_PI / 6.0),
                 m_radius * sin (i * M_PI / 6.0));
        p.stroke();
        p.restore();
    }

    // store the current time
    time_t rawtime;
    time(&rawtime);
    struct tm * timeinfo = localtime (&rawtime);

    // compute the angles of the indicators of our clock
    double minutes = timeinfo->tm_min * M_PI / 30;
    double hours = timeinfo->tm_hour * M_PI / 6;
    double seconds= timeinfo->tm_sec * M_PI / 30;

    p.save();
    p.setLineCap(Painter::RoundLineCap);

    // draw the seconds hand
    p.save();
    p.setLineWidth(m_lineWidth);
    p.setSourceRGBA(0.7, 0.7, 0.7, 0.8);
    p.moveTo(0, 0);
    p.lineTo(sin(seconds) * (m_radius * 0.9),
             -cos(seconds) * (m_radius * 0.9));
    p.stroke();
    p.restore();

    // draw the minutes hand
    p.setSourceRGBA(0.117, 0.337, 0.612, 0.9);
    p.moveTo(0, 0);
    p.lineTo(sin(minutes + seconds / 60.0) * (m_radius * 0.8),
             -cos(minutes + seconds / 60.0) * (m_radius * 0.8));
    p.stroke();

    // draw the hours hand
    p.setSourceRGBA(0.337, 0.612, 0.117, 0.9);
    p.moveTo(0, 0);
    p.lineTo(sin(hours + minutes / 12.0) * (m_radius * 0.5),
             -cos(hours + minutes / 12.0) * (m_radius * 0.5));
    p.stroke();
    p.restore();

    p.setSourceRGBA(1, 0, 0, 0.5);
    p.arc(0, 0, m_lineWidth * 2.0, 0, 2.0 * M_PI);
    p.fill();

#if 0
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window)
  {
    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height();

    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();

    if(event)
    {
        // clip to the area indicated by the expose event so that we only
        // redraw the portion of the window that needs to be redrawn
        cr->rectangle(event->area.x, event->area.y,
                event->area.width, event->area.height);
        cr->clip();
    }

    // background gradient
    {
        Cairo::RefPtr<Cairo::LinearGradient> pat = Cairo::LinearGradient::create(0.0, 0.0, 0.0, height);
        pat->add_color_stop_rgb(1.0, 1.0, 1.0, 1.0);
        pat->add_color_stop_rgb(0.0, 0.0, 0.0, 0.0);
        cr->rectangle(0, 0, width, height);
        cr->set_source(pat);
        cr->fill();
    }

    // scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
    // the center of the window
    cr->scale(width, height);
    cr->translate(0.5, 0.5);
    cr->set_line_width(m_line_width);

    cr->arc(0, 0, m_radius, 0, 2 * M_PI);
    cr->save();
    cr->set_source_rgba(1.0, 1.0, 1.0, 0.8);
    cr->fill_preserve();
    cr->restore();
    cr->stroke_preserve();
    cr->clip();

    //clock ticks
    for (int i = 0; i < 12; i++)
    {
        double inset = 0.05;

        cr->save();
        cr->set_line_cap(Cairo::LINE_CAP_ROUND);

        if(i % 3 != 0)
        {
            inset *= 0.8;
            cr->set_line_width(0.03);
        }

        cr->move_to(
                (m_radius - inset) * cos (i * M_PI / 6),
                (m_radius - inset) * sin (i * M_PI / 6));
        cr->line_to (
                m_radius * cos (i * M_PI / 6),
                m_radius * sin (i * M_PI / 6));
        cr->stroke();
        cr->restore(); /* stack-pen-size */
    }

    // store the current time
    time_t rawtime;
    time(&rawtime);
    struct tm * timeinfo = localtime (&rawtime);

    // compute the angles of the indicators of our clock
    double minutes = timeinfo->tm_min * M_PI / 30;
    double hours = timeinfo->tm_hour * M_PI / 6;
    double seconds= timeinfo->tm_sec * M_PI / 30;

    cr->save();
    cr->set_line_cap(Cairo::LINE_CAP_ROUND);

    // draw the seconds hand
    cr->save();
    cr->set_line_width(m_line_width / 3);
    cr->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray
    cr->move_to(0, 0);
    cr->line_to(sin(seconds) * (m_radius * 0.9), 
            -cos(seconds) * (m_radius * 0.9));
    cr->stroke();
    cr->restore();

    // draw the minutes hand
    cr->set_source_rgba(0.117, 0.337, 0.612, 0.9);   // blue
    cr->move_to(0, 0);
    cr->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8),
            -cos(minutes + seconds / 60) * (m_radius * 0.8));
    cr->stroke();

    // draw the hours hand
    cr->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
    cr->move_to(0, 0);
    cr->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5),
            -cos(hours + minutes / 12.0) * (m_radius * 0.5));
    cr->stroke();
    cr->restore();

    // draw a little dot in the middle
    cr->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI);
    cr->fill();
  }
#endif
}