コード例 #1
0
ファイル: Canvas.cpp プロジェクト: crazyscot/brot2
bool Canvas::on_expose_event(GdkEventExpose * evt) {
	Glib::RefPtr<Gdk::Window> window = get_window();
	if (!window) return false; // no window yet?

	if (!seen_first_expose_event) {
		seen_first_expose_event = true;
		main->controlsWindow().starting_position();
	}

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

	if (!surface) return true; // Haven't rendered yet? Nothing we can do
	if (evt) {
		cr->rectangle(evt->area.x, evt->area.y, evt->area.width, evt->area.height);
		cr->clip();
	}

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

	if (main->dragrect.is_active() && main->dragrect.surface_valid()) {
		cr->save();
		cr->set_source(main->dragrect.get_surface(), 0, 0);
		cr->paint();
		cr->restore();
	}

	if (main->hud_active()) {
		Cairo::RefPtr<Cairo::Surface>& sfc = main->get_hud_surface();
		if (sfc)
			cr->set_source(sfc, 0, 0); // TODO HUD position
		cr->paint();
	}
	return true;
}
コード例 #2
0
bool guiRenderer2D::on_expose_event(GdkEventExpose* event) {

	Glib::RefPtr<Gdk::Window> window = get_window();
	if(window) {
		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
			//printf("event->area.x: %d, event->area.y: %d, event->area.width: %d, event->area.height: %d\n", event->area.x, event->area.y, event->area.width, event->area.height );
			cr->rectangle(event->area.x, event->area.y,	event->area.width, event->area.height);
			cr->clip();
		}

		// Background
		// cr->set_source_rgb(0.0, 0.0, 0.0);
		cr->set_source_rgb(1.0, 1.0, 1.0);
		cr->paint();

		if(m_isRendering && m_layoutAvailable) {
			Gtk::Allocation allocation = get_allocation();
			int width = allocation.get_width();
			int height = allocation.get_height();

			if(width != m_widgetWidth || height != m_widgetHeight ) { // Allocation changed
				rescaleSensorLayout(width, height);
			}

			drawMatrices(cr, width, height, false);
		}
	}

	return true;
}
コード例 #3
0
ファイル: circuitwidget.cpp プロジェクト: ti1024/QCViewer
bool CircuitWidget::on_expose_event(GdkEventExpose* event)
{

    (void)event; // placate compiler..
    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();
        double xc = width/2.0;
        double yc = height/2.0;

        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        circuitDrawer.renderCairo(cr->cobj());
        cr->rectangle(event->area.x, event->area.y,
                      event->area.width, event->area.height);
        cr->clip();
        cr->rectangle (0, 0, width, height);
        cr->set_source_rgb (1,1,1);
        cr->fill ();
        cr->translate (xc-ext.width/2.0-cx*scale, yc-ext.height/2.0-cy*scale);
        if (circuit) {
            rects = circuitDrawer.draw(*circuit, drawarch, drawparallel, ext, wirestart, wireend, scale, selections, ft_default, wirelabels);
            generate_layout_rects ();
        }
    }

    return true;
}
コード例 #4
0
/// Same as draw_buffer, with only the curr_item's full text
void
ViewDrawingArea::render_full_article()
{
	// Dimensions of drawing area
	Gtk::Allocation allocation = get_allocation();
	const int height = allocation.get_height();
	const int width = allocation.get_width();

	Cairo::RefPtr<Cairo::Context> cr = _pixmap->create_cairo_context();
	cr->reset_clip();
	cr->rectangle (0.0, 0.0, width, height);
	cr->clip();
	cr->set_source_rgb (1.0, 1.0, 1.0);
	cr->paint();
	cr->set_source_rgb (0.0, 0.0, 0.0);

	Item *item = AppContext::get().get_curr_item();
	item->make_display_unit();
	ItemDisplayUnit *du = item->get_display_unit();
	du->render (cr, 0, -_vadj->get_value());
	cr->show_page();
	
	double h = du->get_height();
	if (h > height)
		_vadj->set_upper (h - height);
	else
		_vadj->set_upper (0);

	_vadj->set_page_size (height);
	_vadj->set_step_increment (height * 1.0/16.0);
	_vadj->set_page_increment (height * 15.0/16.0);
	_vadj->changed();
}
コード例 #5
0
bool HelloWorld::on_canvas_expose(GdkEventExpose* event) {
    Cairo::RefPtr<Cairo::Context> context = ara_canvas.get_window()->create_cairo_context();
    context->rectangle(event->area.x, event->area.y, event->area.width, 
            event->area.height);
    context->clip();
    update_canvas();
    return true;
}
コード例 #6
0
bool AdvEnvGUIScope::on_expose_event(GdkEventExpose* event)
{
	Glib::RefPtr<Gdk::Window> window = get_window();
	if (window)
	{
		float len, x, y, xscale, yscale;

		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();
		cr->set_line_width(2.0);
		cr->set_source_rgb(0.0, 0.0, 0.0);
		cr->paint();

		cr->set_source_rgb(0.0, 0.8, 0.0);

		cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
		cr->clip();

		cr->move_to(width, height);

		len = m_valueDelay + m_valueAttackTime1 + m_valueAttackTime2 + m_valueAttackTime3 + m_valueAttackTime4 + m_valueReleaseTime1 + m_valueReleaseTime2 + m_valueReleaseTime3 + SUSTAIN_LEN;
		xscale = (float) width / len;
		yscale = (float) (height - 6);

		x = m_valueDelay * xscale;
		cr->line_to((int) x, height);
		x += m_valueAttackTime1 * xscale;
		y = m_valueAttackLevel1 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime2 * xscale;
		y = m_valueAttackLevel2 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime3 * xscale;
		y = m_valueAttackLevel3 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime4 * xscale;
		y = m_valueSustain * yscale;
		cr->line_to((int) x, height - (int) y);
		x += SUSTAIN_LEN * xscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime1 * xscale;
		y = m_valueReleaseLevel1 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime2 * xscale;
		y = m_valueReleaseLevel2 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime3 * xscale;
		cr->line_to((int) x, height);
		x = m_valueDelay * xscale;
		cr->line_to((int) x, height);
		cr->stroke();
	}

	return true;
}
コード例 #7
0
ファイル: liveplay.cpp プロジェクト: unclechu/guitarix
bool MyPaintBox::on_expose_event(GdkEventExpose *event) {
    call_paint_func(event);
    Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
    gdk_cairo_region(cr->cobj(), event->region);
    cr->clip();
    cr->set_source_rgba(0.0, 0.0, 0.0, 1-background_adj->get_value());
    cr->paint();
    foreach(sigc::bind(sigc::mem_fun(this, &MyPaintBox::propagate_expose), event));
    return true;
}
コード例 #8
0
ファイル: ImageDrawable.cpp プロジェクト: lp0/fiv
static void copyCairoClip(const Cairo::RefPtr<Cairo::Context> &src, const Cairo::RefPtr<Cairo::Context> &dst) {
	try {
		vector<Cairo::Rectangle> rects;
		src->copy_clip_rectangle_list(rects);
		for (auto& rect : rects) {
			//cout << "clip " << rect.x << "x" << rect.y << "+" << rect.width << "+" << rect.height << endl;
			dst->rectangle(rect.x, rect.y, rect.width, rect.height);
		}
		dst->clip();
	} catch (...) {
		Cairo::Rectangle rect;
		src->get_clip_extents(rect.x, rect.y, rect.width, rect.height);
		rect.width -= rect.x;
		rect.height -= rect.y;
		//cout << "clip " << rect.x << "x" << rect.y << "+" << rect.width << "+" << rect.height << endl;
		dst->rectangle(rect.x, rect.y, rect.width, rect.height);
		dst->clip();
	}
}
コード例 #9
0
bool VistaDiagrama::on_expose_event(GdkEventExpose* event) {
	this->set_size_request(this->ancho, this->alto);

	// Gonzalo : TEST
	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();

		// 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(10.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();

		// draw red lines out from the center of the window
		cr->set_line_cap(Cairo::LINE_CAP_ROUND);
		cr->set_source_rgb(0.8, 0.0, 0.0);
		cr->move_to(20, 20);
		cr->line_to(xc, yc);
		cr->line_to(20, height - 20);

		cr->move_to(xc, yc);
		cr->line_to(width - 20, yc);
		cr->stroke();

		//RefPtr<Context> cr = this->get_window()->create_cairo_context();
		/*cr->set_source_rgba(1, 1, 1, 1); // white
		 cr->paint();
		 cr->set_source_rgba(0, 0, 0, 1); // negro

		 cr->move_to(0, 0);
		 cr->line_to(this->ancho, this->alto);

		 VistaEntidad * entidad = new VistaEntidad();

		 entidad->setposfin(10, 10);
		 entidad->setposfin(20, 20);

		 entidad->dibujar(cr);*/
	}

	//delete entidad;
	return true;
}
コード例 #10
0
ファイル: emblemcellrenderer.cpp プロジェクト: egore/meld
void EmblemCellRenderer::do_render(const Cairo::RefPtr<Cairo::Context>& context, int widget, int background_area, Gdk::Rectangle &cell_area, int flags) {
    context->translate(cell_area.get_x(), cell_area.get_y());
    context->rectangle(0, 0, cell_area.get_width(), cell_area.get_height());
    context->clip();

    // TODO: Incorporate padding
    context->push_group();
    if (!this->_icon_name.empty()) {
        Glib::RefPtr<Gdk::Pixbuf> pixbuf = this->_get_pixbuf(this->_icon_name, this->_icon_size);
        context->set_operator(Cairo::OPERATOR_SOURCE);
        // Assumes square icons; may break if we don't get the requested size
        int height_offset = int((cell_area.get_height() - pixbuf->get_height())/2);
        Gdk::Cairo::set_source_pixbuf(context, pixbuf, 0, height_offset);
        context->rectangle(0, height_offset,
                          pixbuf->get_width(), pixbuf->get_height());
        context->fill();

        if (this->_tint_color) {
            Gdk::RGBA* c = this->_tint_color;
            gushort r = c->get_red();
            gushort g = c->get_green();
            gushort b = c->get_blue();
            // Figure out the difference between our tint colour and an
            // empirically determined (i.e., guessed) satisfying luma and
            // adjust the base colours accordingly
            double luma = (r + r + b + g + g + g) / 6.;
            double extra_luma = (1.2 - luma) / 3.;
            r = std::min(r + extra_luma, 1.);
            g = std::min(g + extra_luma, 1.);
            b = std::min(b + extra_luma, 1.);
            context->set_source_rgba(r, g, b, 0.4);
            context->set_operator(Cairo::OPERATOR_ATOP);
            context->paint();
        }

        if (!this->_emblem_name.empty()) {
            Glib::RefPtr<Gdk::Pixbuf> pixbuf = this->_get_pixbuf(this->_emblem_name, this->_emblem_size);
            int x_offset = this->_icon_size - this->_emblem_size;
            context->set_operator(Cairo::OPERATOR_OVER);
            Gdk::Cairo::set_source_pixbuf(context, pixbuf, x_offset, 0);
            context->rectangle(x_offset, 0,
                              cell_area.get_width(), this->_emblem_size);
            context->fill();
        }
    }

    context->pop_group_to_source();
    context->set_operator(Cairo::OPERATOR_OVER);
    context->paint();
}
コード例 #11
0
Cairo::RefPtr<Cairo::ImageSurface> ImagesStorage::loadFrenchCard(Cairo::RefPtr<Cairo::ImageSurface> sourceImages, Preference::Card card)
{
	Cairo::RefPtr<Cairo::ImageSurface> cardImage = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 
		sourceImages->get_width() / 13.0, sourceImages->get_height() / 5.0);
	Cairo::RefPtr<Cairo::Context> cardsImagesDrawer = Cairo::Context::create( cardImage );
	cardsImagesDrawer->set_source_rgb(1, 1, 1);
	double x = getFrenchCardCoord(card, CT_X, sourceImages->get_width());
	double y = getFrenchCardCoord(card, CT_Y, sourceImages->get_height());
	cardsImagesDrawer->set_source(sourceImages, -x, -y);
	cardsImagesDrawer->rectangle(0, 0, sourceImages->get_width() / 13.0, sourceImages->get_height() / 5.0);
	cardsImagesDrawer->clip();
	cardsImagesDrawer->paint();
	return cardImage;
}
コード例 #12
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;
      }
コード例 #13
0
ファイル: liveplay.cpp プロジェクト: unclechu/guitarix
bool Liveplay::window_expose_event(GdkEventExpose *event) {
    Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
    Gtk::Allocation a = liveplay_canvas->get_allocation();
    Gdk::Region region(a);
    region.intersect(Glib::wrap(event->region, true));
    Gdk::Cairo::add_region_to_path(cr, region);
    cr->clip();
    cr->set_operator(Cairo::OPERATOR_SOURCE);
    cr->set_source_rgb(0,0,0);
    cr->paint();
    //gdk_cairo_set_source_window(cr->cobj(), liveplay_canvas->get_window()->gobj(), a.get_x(), a.get_y()); gtk 2.24
    gdk_cairo_set_source_pixmap(cr->cobj(), liveplay_canvas->get_window()->gobj(), a.get_x(), a.get_y());
    cr->paint_with_alpha(pow(brightness_adj->get_value(),2.2));
    return false;
}
コード例 #14
0
bool CompVis::on_expose_event(GdkEventExpose* event) {
    Glib::RefPtr<Gdk::Window> window = get_window();
    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();
        
    // 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();
           
    rms_dB = 20*log10(rms);
    thresh_fraction = (threshold -  p_ports[p_threshold].min)/threshold_range;
    rms_dB_fraction = (rms_dB - p_ports[p_threshold].min)/threshold_range;

    // Draw the graph
    cr->set_source_rgb(0.5,0.1,0.1);
    cr->set_line_width(2);
    cr->move_to(0,height);

    if (rms_dB <= threshold) {
        cr->line_to(rms_dB_fraction*width, height-rms_dB_fraction*height);
        cr->line_to(rms_dB_fraction*width, height);
        cr->line_to(0,height);
    } else {
        cr->line_to(thresh_fraction*width, height-thresh_fraction*height);
        cr->line_to(rms_dB_fraction*width, height-(thresh_fraction*height + height*(rms_dB_fraction-thresh_fraction)/ratio));
        cr->line_to(rms_dB_fraction*width, height);
        cr->line_to(0,height);
    }
    cr->fill();

    // draw the compression curve:
    cr->set_source_rgb(0.1,0.1,0.1);
    cr->move_to(0, height);
    cr->line_to(thresh_fraction*width, height-thresh_fraction*height);
    cr->line_to(width, height-(thresh_fraction*height + height*(1-thresh_fraction)/ratio));
    cr->stroke();

    // Draw the gain
    cr->set_source_rgb(0.1,0.8,0.1);
    cr->rectangle(0,(float)height - (float)height*gain, 10, height);
    cr->fill();
    return true;
}
コード例 #15
0
bool TrackOutput::on_expose_event(GdkEventExpose* event)
{
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  
  if(window)    // Only run if Window does exist
  {
    // clip to the area indicated by the expose event so that we only redraw
    // the portion of the window that needs to be redrawn
    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->rectangle(event->area.x, event->area.y,
        event->area.width, event->area.height);
    cr->set_source_rgb(0.1 , 0.1 , 0.1 );
    cr->fill();
    
    
    TrackOutputState* state = &stateStore->trackoutputState.at(ID);
    
    if ( state->selected )
      setColour(cr, COLOUR_GREY_3 );
    else
      setColour(cr, COLOUR_GREY_4 );
    
    cr->rectangle(0, 0, 74, 102);
    cr->fill();
    
    Dial(cr,true, 7,4,state->pan,DIAL_MODE_PAN); // pan
    Mute(cr, 9  , 41 , state->ID, state->mute ); // mute button
    Solo(cr, 9  , 68 , state->ID, state->solo ); // solo button
    Rec (cr, 9  , 85 , state->ID, state->recEnable); // rec button
    Fader(cr,46 , 4  , state->volume, state->rms, state->falloff ); // fader
    
    if ( state->selected )
    {
      cr->rectangle(0, -10, 74, 200);
      setColour( cr, COLOUR_PURPLE_1 );
      cr->set_line_width(1);
      cr->stroke();
    }
    
  }
  return true;
}
コード例 #16
0
ファイル: Mediator.cpp プロジェクト: VaysseB/openfluid
void Mediator::redraw()
{
  Glib::RefPtr<Gdk::Window> Window = mref_DrawingArea.get_window();

  if (Window)
  {
    Window->clear();

    if (!m_Layers.empty())
    {
      Cairo::RefPtr<Cairo::Context> Context = Window->create_cairo_context();
      Gtk::Allocation allocation = mref_DrawingArea.get_allocation();
      const int width = allocation.get_width();
      const int height = allocation.get_height();

      Context->rectangle(0, 0, width, height);
      Context->clip();
      Context->set_antialias(Cairo::ANTIALIAS_SUBPIXEL);
      Context->scale(mref_DrawingArea.getScale(), -mref_DrawingArea.getScale());
      Context->translate(-mref_DrawingArea.getXTranslate(),
          -mref_DrawingArea.getYTranslate());
      std::vector<Layer*>::reverse_iterator rit;
      for (rit = m_Layers.rbegin(); rit < m_Layers.rend(); ++rit)
      {
        if ((*rit)->getIsDisplay())
        {
          (*rit)->initialiseLayerContext(Context, mref_DrawingArea.getScale());
          if ((*rit)->getClassName() == m_SelectedClassName)
          {
            (*rit)->draw(Context, mref_DrawingArea.getScale(),
                m_SelectedUnitIds, (*rit)->getDisplayID());
          }
          else
          {
            std::set<int> tempVoidVector;
            (*rit)->draw(Context, mref_DrawingArea.getScale(), tempVoidVector,
                (*rit)->getDisplayID());
          }
        }
      }
    }
  }
}
コード例 #17
0
ファイル: CardWidget.cpp プロジェクト: eshavlyugin/Preferans
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();
}
コード例 #18
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;
}
コード例 #19
0
ファイル: imagewidget.cpp プロジェクト: pkgw/aoflagger
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);
	}
}
コード例 #20
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;
}
コード例 #21
0
ファイル: huitu___.cpp プロジェクト: zzzzzzzzzzz0/zhscript
bool area___::expose_evt__(GdkEventExpose* event){
	if(code_.size()>0){
		Glib::RefPtr<Gdk::Window> window=da_->get_window();
		if(window){
			cr_ = window->create_cairo_context();
			if(event){
				cr_->rectangle(event->area.x, event->area.y,
						event->area.width, event->area.height);
				cr_->clip();
			}

#ifdef debug_
			test__();
#else
			char buf[32];
			l2s__((long)this,buf);
			d_(sh_,on_,code_.c_str(),NULL,3,ht_->name__(),"重绘",buf);
#endif
		}
		return true;
	}
	return false;
}
コード例 #22
0
bool GMasterReturn::on_expose_event(GdkEventExpose* event)
{
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  
  if(window)    // Only run if Window does exist
  {
    // clip to the area indicated by the expose event so that we only redraw
    // the portion of the window that needs to be redrawn
    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->rectangle(event->area.x, event->area.y,
        event->area.width, event->area.height);
    cr->set_source_rgb(0.1 , 0.1 , 0.1 );
    cr->fill();
    
    
    Dial(cr, true, 35 , 0, value, DIAL_MODE_SEND ); // fader
    
    // Dial text "A"
    cr->select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD);
    cr->set_font_size ( 20 );
    cr->move_to ( 10, 28);
    switch ( ID )
    {
      case 0: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "A" ); break;
      case 1: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "B" ); break;
      case 2: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "C" ); break;
    }
    
  }
  return true;
}
コード例 #23
0
ファイル: plotter.cpp プロジェクト: VDrift/pacejka
bool Plotter::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();

    	// 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();
		
		// 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();

		//draw curve
		cr->set_line_width(1.0);
	
		float zoom = adjustmentmap["zoom"]->GetValue();
		float camber = adjustmentmap["camber"]->GetValue();
		float load = adjustmentmap["load"]->GetValue();
		zoom = (1.0-zoom)*4.0+0.1;
		load = load * 0.001;
		
		if (UpdateTire())
		{
			{
				//draw lateral line
				cr->set_source_rgb(1.0, 0.0, 0.0);
				float x0 = -zoom*0.5*20.0;
				float xn = zoom*0.5*20.0;
				float ymin = -1000.0;
				float ymax = 1000.0;
				int points = 500;
				
				for (float x = x0; x <= xn; x += (xn-x0)/points)
				{
					float maxforce;
					float yval = tire.Pacejka_Fy(x, load, camber, 1.0, maxforce)/load;
					float xval = width*(x-x0)/(xn-x0);
					yval /= ymax-ymin;
					yval = (yval+1.0)*0.5;
					yval = 1.0 - yval;
					yval *= height;
					if (x == x0)
						cr->move_to(xval, yval);
					else
						cr->line_to(xval, yval);
					//std::cout << xval << ", " << yval << std::endl;
				}
				cr->stroke();
			}
			
			{
				//draw longitudinal line
				cr->set_source_rgb(0.0, 1.0, 0.0);
				float x0 = -zoom*0.5;
				float xn = zoom*0.5;
				float ymin = -1000.0;
				float ymax = 1000.0;
				int points = 500;
				
				for (float x = x0; x <= xn; x += (xn-x0)/points)
				{
					float maxforce;
					float yval = tire.Pacejka_Fx(x, load, 1.0, maxforce)/load;
					float xval = width*(x-x0)/(xn-x0);
					yval /= ymax-ymin;
					yval = (yval+1.0)*0.5;
					yval = 1.0 - yval;
					yval *= height;
					if (x == x0)
						cr->move_to(xval, yval);
					else
						cr->line_to(xval, yval);
					//std::cout << xval << ", " << yval << std::endl;
				}
				cr->stroke();
			}
			
			{
				//draw aligning line
				cr->set_source_rgb(0.0, 0.0, 1.0);
				float x0 = -zoom*0.5*10.0;
				float xn = zoom*0.5*10.0;
				float ymin = -60.0;
				float ymax = 60.0;
				int points = 500;
				
				for (float x = x0; x <= xn; x += (xn-x0)/points)
				{
					float maxforce;
					float yval = tire.Pacejka_Mz(0, x, load, camber*(180.0/3.141593), 1.0, maxforce)/load;
					float xval = width*(x-x0)/(xn-x0);
					yval /= ymax-ymin;
					yval = (yval+1.0)*0.5;
					yval = 1.0 - yval;
					yval *= height;
					if (x == x0)
						cr->move_to(xval, yval);
					else
						cr->line_to(xval, yval);
					//std::cout << xval << ", " << yval << std::endl;
				}
				cr->stroke();
			}
			
			// draw grid lines
			cr->set_line_width(1.0);
			cr->set_source_rgb(0.0, 0.0, 0.0);
			cr->move_to(xc, 0);
			cr->line_to(xc, yc*2);
			cr->move_to(0, yc);
			cr->line_to(xc*2, yc);
			cr->stroke();
		}
	}

	return true;
}
コード例 #24
0
bool CPagePreview::on_expose_event(GdkEventExpose *event)
	{
	std::cout << "Fired!\n";
			
	Glib::RefPtr<Gdk::Window> window = get_window();
	if(window)
		{
		// get the cairo context amd allocation
		Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
		Gtk::Allocation allocation = get_allocation();
		const int width = allocation.get_width();
		const int height = allocation.get_height();
		
		// coordinates for the center of the window
		int xc, yc;
		xc = width / 2;
		yc = height / 2;

		
		// 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();
		
		double border = 0.05;
		double offset = 2.0;
		
		// draw a neat shadow
		cr->set_source_rgba(0.0,0.0,0.0,0.4);
		cr->begin_new_path();
		cr->move_to( width*border+offset,height*border+offset );
		cr->line_to( width*(1.0-border)+offset,height*border+offset );
		cr->line_to( width*(1.0-border)+offset,height*(1.0-border)+offset );
		cr->line_to( width*border+offset,height*(1.0-border)+offset );
		cr->close_path();
		cr->fill();

		// draw the page outline
		cr->set_source_rgb(0.0,0.0,0.0); // black
		cr->set_line_width( 1.0 );
		cr->begin_new_sub_path();
		cr->move_to( width*border-offset,height*border-offset );
		cr->line_to( width*(1.0-border)-offset,height*border-offset );
		cr->line_to( width*(1.0-border)-offset,height*(1.0-border)-offset );
		cr->line_to( width*border-offset,height*(1.0-border)-offset );
		cr->close_path();
		cr->stroke_preserve();
		
		// fill the page with white
		cr->save();
		cr->set_source_rgb(1.0,1.0,1.0); // white
		cr->fill_preserve();
		cr->restore();

		// and the image preview
		ImagePixbuf->render_to_drawable( get_window(),
									get_style()->get_black_gc(),
									0,
									0,
									(width-ImagePixbuf->get_width())/2,
									(height-ImagePixbuf->get_height())/2,
									ImagePixbuf->get_width(), //image->get_width(),
									ImagePixbuf->get_height(), //image->get_height(),
									Gdk::RGB_DITHER_NONE,0,0 ); // */
									
		return true;
		}
	}
コード例 #25
0
/** Expose event handler.
 * @param event event info structure.
 * @return signal return value
 */
bool
LaserDrawingArea::on_expose_event(GdkEventExpose* event)
#endif
{
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window) {
    Gtk::Allocation allocation = get_allocation();

    if(__first_draw)
    {
      __first_draw = false;
      const int width = allocation.get_width();
      const int height = allocation.get_height();
    
      // coordinates for the center of the window
      __xc = width / 2;
      __yc = height / 2;
    }
#if GTK_VERSION_LT(3,0)
    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
#endif
    cr->set_line_width(1.0);

    cr->set_source_rgb(1, 1, 1);
#if GTK_VERSION_LT(3,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->fill_preserve();
    cr->clip();
#else
    cr->paint();
#endif
    cr->set_source_rgb(0, 0, 0);
    //cr->set_source_rgba(0,0,0,1);

    //    __last_xc += __translation_x;
    //    __last_yc += __translation_y;
    cr->translate(__xc, __yc);
  
    cr->save();
    if (! __connected) {
      Cairo::TextExtents te;
      std::string t = "Not connected to BlackBoard";
      cr->set_source_rgb(1, 0, 0);
      cr->set_font_size(20);
      cr->get_text_extents(t, te);
      cr->move_to(- te.width / 2, -te.height / 2);
      cr->show_text(t);
    } else if ( __laser_ifs.empty() ) {
      Cairo::TextExtents te;
      std::string t = "No interface opened";
      cr->set_source_rgb(1, 0, 0);
      cr->set_font_size(20);
      cr->get_text_extents(t, te);
      cr->move_to(- te.width / 2, -te.height / 2);
      cr->show_text(t);
    } else if (! all_laser_ifs_have_writer() ) {
      Cairo::TextExtents te;
      std::string t = "No writer for ";
      for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
           it != __laser_ifs.end(); ++it) {
        fawkes::Interface* itf = it->first;
        if (!itf->has_writer()) {
          t += itf->uid();
          t += ' ';
        }
      }
      cr->set_source_rgb(1, 0, 0);
      cr->set_font_size(20);
      cr->get_text_extents(t, te);
      cr->move_to(- te.width / 2, -te.height / 2);
      cr->show_text(t);
    } else {
      if (! __break_drawing) {
        for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
             it != __laser_ifs.end(); ++it) {
          fawkes::Interface* laser_if = it->first;
          laser_if->read();
        }
      }

      for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
           it != __laser_ifs.end(); ++it) {
        const fawkes::Interface* laser_if = it->first;
        const Color& color = it->second;
        cr->save();
        cr->set_source_rgb(color.r, color.g, color.b);
        draw_beams(laser_if, window, cr);
        cr->restore();
      }
      if (__robot_drawer)  __robot_drawer->draw_robot(window, cr);
      for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
           it != __laser_ifs.end(); ++it) {
        const fawkes::Interface* laser_if = it->first;
        const Color& color = it->second;
        cr->save();
        cr->set_source_rgb(color.r, color.g, color.b);
        draw_segments(laser_if, window, cr);
        cr->restore();
      }
      draw_persons_legs(window, cr);

      if(__switch_if != NULL && __switch_if->has_writer()){
	SwitchInterface::EnableSwitchMessage *esm = new SwitchInterface::EnableSwitchMessage();
	__switch_if->msgq_enqueue(esm);
      }
    }
    cr->restore();

    cr->save();
    cr->rotate(0.5 * M_PI + __rotation);
    cr->scale(-__zoom_factor, __zoom_factor);
    cr->set_line_width(1. / __zoom_factor);
    if (__visdisp_if) {
      __visdisp->process_messages();
      __visdisp->draw(cr);
    }

    const float radius = 0.01;
    if (__line_if) {
      __line_if->read();
      if (__line_if->has_writer() &&
	  __line_if->is_valid() && __line_if->is_visible()) {

	cr->set_source_rgb(1, 0, 0);
	/*
	std::vector<double> dashes(1);
	dashes[0] = 0.1;
	cr->set_dash(dashes, 0);
	*/
	cr->rectangle(__line_if->world_x() - radius * 0.5, __line_if->world_y() - radius * 0.5, radius, radius);
	cr->rectangle(__line_if->relative_x() - radius * 0.5, __line_if->relative_y() - radius * 0.5, radius, radius);
	cr->fill_preserve();
	cr->stroke();
	cr->move_to(__line_if->world_x(), __line_if->world_y());
	cr->line_to(__line_if->relative_x(), __line_if->relative_y());
	cr->stroke();
      }
    }
    cr->restore();
  }

  return true;
}
コード例 #26
0
void 
ViewDrawingArea::draw_buffer()
{
#ifdef DEBUG
std::cerr << "VA->val:"<<_vadj->get_value() <<" VA->upper:"<<_vadj->get_upper() << std::endl << std::flush;
#endif

	Feed *feed = AppContext::get().get_feed();
	if (feed == NULL) 
		return;

	if (AppContext::get().get_display_type() == FULL)
	{
		render_full_article();
		return;
	}

	// Dimensions of drawing area
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();

	// First determine start item
	Cairo::RefPtr<Cairo::Context> cr = _pixmap->create_cairo_context();

#ifdef DEBUG
	/// This code was meant to investigate the 500ms delay with pango
	/// at start of rendering.
	if (!_layout_prepared)
	{
Glib::Timer sw;
sw.start();
		Glib::RefPtr<Pango::Layout> pl = Pango::Layout::create (cr);
		const char *fonts[] = {"Sans 10", "Sans 14"};
		for (unsigned i = 0; i < sizeof(fonts)/sizeof(const char*); ++i)
		{
			Pango::FontDescription fdesc (fonts[i]);
			pl->set_font_description (fdesc);
			pl->set_width (10 * Pango::SCALE); // force line break
			pl->set_markup ("<b>Show Us Your Freaky Geek Costumes</b>\nHitting the streets in a scary, tech-themed outfit this Halloween? We want to see it. Find out how your Sergey Brin costume (or is it David Duchovny?) could be featured on Wired News. test\n test");
			Pango::Rectangle irect, lrect;
			pl->get_extents (irect, lrect);
		}
		_layout_prepared = true;
sw.stop();
unsigned long l;
sw.elapsed(l);
std::cerr << "Time spent rendering: " << l << " us" << std::endl << std::flush;
	}
#endif

	const item_list_t items = feed->get_items();
	item_list_t::const_iterator start_item;
	const int n_items = items.size();
	double y = 0.0;

	if (n_items == 0)
		start_item = items.end();
	else
	{
		// Set start_item and h
		int start = static_cast<int> (_vadj->get_value());
		double h = 0.0;
		if (_vadj->get_value() > 0 && _vadj->get_value() == _vadj->get_upper())
		{
			// This will give a blank page when pulling the handle
			// full down. While unusual, it might make sense with
			// an ever-growing newslist.
			y = 0.0;
			start_item = items.end();
		}
		else
		{
			start_item = items.begin();
			for (int i = 0; i < start; ++i)
				++start_item;
			if (start < 0)
				start = 0;

			double prop = _vadj->get_value() - start;
			if (prop > 0.0)
			{
				(*start_item)->make_display_unit();
				ItemDisplayUnit *du = (*start_item)->get_display_unit();
				du->layout (cr);
				h = du->get_height();
			}
			y = - h * prop;
#ifdef DEBUG
std::cerr << "prop:"<<prop <<" y:"<<y << std::endl << std::flush;
#endif

		}
	}

	// 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->reset_clip();
	cr->rectangle (0.0, 0.0, width, height);
	cr->clip();

	// Black on white
	cr->set_source_rgb (1.0, 1.0, 1.0);
	cr->paint();
	cr->set_source_rgb (0.0, 0.0, 0.0);

	// Render text
	item_list_t::const_iterator it = start_item;
	_top_item = *start_item;
	_topitem_y = y;
	int count = 0;
	for (; it != items.end() && y < height; ++it, ++count)
	{
		(*it)->make_display_unit();
		ItemDisplayUnit *du = (*it)->get_display_unit();
		du->render (cr, 0, y);
		y += du->get_height();
	}

	cr->show_page();

	// Scrollbar settings can now be specified
	_vadj->set_upper (n_items);
	//_vadj->set_page_size (count - 1 + );
	_vadj->set_step_increment (1);
	_vadj->set_page_increment (count);
	_vadj->changed();

}
コード例 #27
0
ファイル: gui_gtkmm.cpp プロジェクト: an1ka/xinput_calibrator
bool CalibrationArea::on_expose_event(GdkEventExpose *event)
{
    // check that screensize did not change
    if (display_width != get_width() ||
         display_height != get_height()) {
        set_display_size(get_width(), get_height());
    }

    Glib::RefPtr<Gdk::Window> window = get_window();
    if (window) {
        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        cr->save();

        cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
        cr->clip();

        // Print the text
        cr->set_font_size(font_size);
        double text_height = -1;
        double text_width = -1;
        Cairo::TextExtents extent;
        for (int i = 0; i != help_lines; i++) {
            cr->get_text_extents(help_text[i], extent);
            text_width = std::max(text_width, extent.width);
            text_height = std::max(text_height, extent.height);
        }
        text_height += 2;

        double x = (display_width - text_width) / 2;
        double y = (display_height - text_height) / 2 - 60;
        cr->set_line_width(2);
        cr->rectangle(x - 10, y - (help_lines*text_height) - 10,
                text_width + 20, (help_lines*text_height) + 20);

        // Print help lines
        y -= 3;
        for (int i = help_lines-1; i != -1; i--) {
            cr->get_text_extents(help_text[i], extent);
            cr->move_to(x + (text_width-extent.width)/2, y);
            cr->show_text(help_text[i]);
            y -= text_height;
        }
        cr->stroke();

        // Draw the points
        for (int i = 0; i <= calibrator->get_numclicks(); i++) {
            // set color: already clicked or not
            if (i < calibrator->get_numclicks())
                cr->set_source_rgb(1.0, 1.0, 1.0);
            else
                cr->set_source_rgb(0.8, 0.0, 0.0);

            cr->set_line_width(1);
            cr->move_to(X[i] - cross_lines, Y[i]);
            cr->rel_line_to(cross_lines*2, 0);
            cr->move_to(X[i], Y[i] - cross_lines);
            cr->rel_line_to(0, cross_lines*2);
            cr->stroke();

            cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI);
            cr->stroke();
        }

        // Draw the clock background
        cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI);
        cr->set_source_rgb(0.5, 0.5, 0.5);
        cr->fill_preserve();
        cr->stroke();

        cr->set_line_width(clock_line_width);
        cr->arc(display_width/2, display_height/2, (clock_radius - clock_line_width)/2,
             3/2.0*M_PI, (3/2.0*M_PI) + ((double)time_elapsed/(double)max_time) * 2*M_PI);
        cr->set_source_rgb(0.0, 0.0, 0.0);
        cr->stroke();


        // Draw the message (if any)
        if (message != NULL) {
            // Frame the message
            cr->set_font_size(font_size);
            Cairo::TextExtents extent;
            cr->get_text_extents(this->message, extent);
            text_width = extent.width;
            text_height = extent.height;

            x = (display_width - text_width) / 2;
            y = (display_height - text_height + clock_radius) / 2 + 60;
            cr->set_line_width(2);
            cr->rectangle(x - 10, y - text_height - 10,
                    text_width + 20, text_height + 25);

            // Print the message
            cr->move_to(x, y);
            cr->show_text(this->message);
            cr->stroke();
        }

        cr->restore();
    }

    return true;
}
コード例 #28
0
bool HistogramDrawingArea::on_expose_event( GdkEventExpose* event )
{    
    Glib::RefPtr<Gdk::Window> window = get_window();
    if( window == NULL)
    {
        return true;
    }

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

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

    // Clear the background
    refCairo->set_source_rgb( 255, 255, 255 );
    refCairo->paint();

    Glib::Mutex::Lock pixBufLock(statsMutex, Glib::NOT_LOCK );
    if ( pixBufLock.try_acquire() != true )
    {
        return true;
    }

    if ( m_drawMode == Histogram::MODE_HISTOGRAM )
    {
        for ( int i=0; i < ImageStatistics::NUM_STATISTICS_CHANNELS; i++ )
        {            
            DrawSingleHistogramLine( 
                refCairo, 
                static_cast<ImageStatistics::StatisticsChannel>(i) );
        }
        
        DrawHistogramGridLabels( refCairo );
    }
    else if ( m_drawMode == Histogram::MODE_ROWCOL )
    {
        double red, green, blue;

        if ( m_dispOptions.showGrey == true )
        {            
            GetLineColor( ImageStatistics::GREY, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.grey, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        if ( m_dispOptions.showRed == true )
        {
            GetLineColor( ImageStatistics::RED, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.red, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        if ( m_dispOptions.showGreen == true )
        {
            GetLineColor( ImageStatistics::GREEN, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.green, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        if ( m_dispOptions.showBlue == true )
        {
            GetLineColor( ImageStatistics::BLUE, red, green, blue );

            DrawSingleRowColChannel( 
                refCairo, 
                m_rowColStats.blue, 
                m_rowColStats.numPixelValues,
                red, 
                green, 
                blue );
        }

        DrawRowColGridLabels( 
            refCairo, 
            m_rowColStats.numPixelValues, 
            m_rowColStats.imageDimension );
    }    

    DrawBackgroundGrid( refCairo );

    return true;
}
コード例 #29
0
    bool Format7DrawingArea::on_expose_event( GdkEventExpose* event )
    {
        Glib::RefPtr<Gdk::Window> window = get_window();
        if( window == NULL)
        {
            return true;
        }

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

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

        // Get width / height of widget
        int width;
        int height;
        window->get_size( width, height );        

        // Figure out which scale to use (horizontal or vertical)
        const float horzScale = m_maxWidth / (float)width;
        const float vertScale = m_maxHeight / (float)height;
                
        m_previewScale = (horzScale < vertScale) ? vertScale : horzScale;

        Gtk::AspectFrame* pFrame = (Gtk::AspectFrame*)get_parent();
        float fRatio = m_maxWidth / (float)m_maxHeight;       
        if ( fRatio != pFrame->property_ratio())
        {
            pFrame->set( 0.0, 0.0, fRatio, false );
        } 

        unsigned int scaledLeft = static_cast<unsigned int>(ToScaled( m_left ));
        unsigned int scaledTop = static_cast<unsigned int>(ToScaled( m_top ));
        unsigned int scaledWidth = static_cast<unsigned int>(ToScaled( m_width ));
        unsigned int scaledHeight = static_cast<unsigned int>(ToScaled( m_height ));        

        // Fill the background with the PGR color
        FillBackground( 
            refCairo, 
            event->area.x, 
            event->area.y,
            event->area.width, 
            event->area.height);

        // Draw the data on top of the filled background
        DrawRectangle( refCairo, scaledLeft, scaledTop, scaledWidth, scaledHeight );
        DrawDashedLines( refCairo, scaledLeft, scaledTop, scaledWidth, scaledHeight );        
        DrawImageDimensionsText( refCairo, m_left, m_top, m_width, m_height );
        DrawCurrentCursorPositionText( refCairo, m_currX, m_currY );       

        if ( m_imageSizeChanged == true )
        {
            if ( m_left != m_lastFiredLeft ||
                m_top != m_lastFiredTop ||
                m_width != m_lastFiredWidth ||
                m_height != m_lastFiredHeight )
            {
                m_signal_image_size_changed( m_left, m_top, m_width, m_height );     

                m_lastFiredLeft = m_left;
                m_lastFiredTop = m_top;
                m_lastFiredWidth = m_width;
                m_lastFiredHeight = m_height;
            }
            
            m_imageSizeChanged = false;
        }

        return true;
    }
コード例 #30
0
ファイル: huitu___.cpp プロジェクト: zzzzzzzzzzz0/zhscript
void area___::test__(){
	int width, height;
	width=da_->get_allocation().get_width();
	height=da_->get_allocation().get_height();

	double m_radius=0.42;
	double m_line_width=0.05;

	// 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_->save();
	cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
	cr_->paint();
	cr_->restore();
	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;
	cout<<timeinfo->tm_min<<","<<timeinfo->tm_hour<<","<<timeinfo->tm_sec<<endl;

	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();
}