예제 #1
0
void GraphicalItem::drawRoundedRectangle(
    const Cairo::RefPtr<Cairo::Context>& context,
    int x, int y,
    int width, int height,
    double aspect,
    double corner_radius,
    double red, double green, double blue)
{
    double radius = corner_radius / aspect;
    double degrees = M_PI / 180.0;

    context->begin_new_sub_path();
    context->arc(x + width - radius, y + radius, radius,
        -90 * degrees, 0 * degrees);
    context->arc(x + width - radius, y + height - radius,
        radius, 0 * degrees, 90 * degrees);
    context->arc(x + radius, y + height - radius, radius,
        90 * degrees, 180 * degrees);
    context->arc(x + radius, y + radius, radius,
        180 * degrees, 270 * degrees);
    context->close_path();

    context->set_source_rgb(red, green, blue);
    context->fill_preserve();
    setColor(Settings::settings().getForegroundColor(), context);
    context->stroke();
}
예제 #2
0
void
ColorSlider::draw_arrow(
	const Cairo::RefPtr<Cairo::Context> &cr,
	double x, double y,
	double width, double height,
	int size,
	bool fill)
{
	//TODO hardcoded colors
	Color dark(0, 0, 0);
	Color light(1, 1, 1);

	//!TODO FActorize ! (Duplicate code with "Widget_Keyframe_List::draw_arrow")
	//! Upper black pointing down arrow
	cr->set_source_rgb(dark.get_r(), dark.get_g(), dark.get_b());
	cr->set_line_width(1.0);
	cr->move_to(x, y);
	cr->line_to(x - 0.5*width, y - height);
	cr->line_to(x + 0.5*width, y - height);
	cr->close_path();
	if (fill)
	{
/*		//! Draw on outline
		cr->fill_preserve();
		cr->set_source_rgb(light.get_r(), light.get_g(), light.get_b());
		cr->stroke();
*/
		cr->fill();
	}else cr->stroke();

	//! Bottom light pointing up arrow
	cr->set_source_rgb(light.get_r(), light.get_g(), light.get_b());
	cr->set_line_width(1.0);
	cr->move_to(x, size - height);
	cr->line_to(x - 0.5*width, size);
	cr->line_to(x + 0.5*width, size);
	cr->close_path();
	if (fill)
	{
/*		//! Draw on outline
		cr->fill_preserve();
		cr->set_source_rgb(dark.get_r(), dark.get_g(), dark.get_b());
		cr->stroke();
*/
		cr->fill();
	}else cr->stroke();
}
예제 #3
0
		bool on_expose_event(GdkEventExpose* ev) {
			Glib::RefPtr< Gdk::Window > window = get_window();
			if (window) {
				Cairo::RefPtr< Cairo::Context > ctx = window->create_cairo_context();
				Gtk::Allocation alloc = get_allocation();
				const int height = alloc.get_height();
				const int width = alloc.get_width();

				ctx->scale(width, height); //escala para que ocupe siempre toda la pantalla. Notar que es ancho y después alto.
				ctx->set_line_width(ANCHO_LINEA);
				
				// contorno
				ctx->move_to(0.0, 1.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda abajo
				ctx->line_to(0.0, 0.0); // línea hacia el punto de arriba a la izquierda
				ctx->line_to(1.0, 0.0); // línea hacia el punto de arriba a la derecha
				ctx->line_to(1.0, 1.0); // línea hacia el punto de abajo a la derecha
				ctx->close_path(); // cierro el camino
				ctx->save(); // salvo porque voy a cambiar el color
					ctx->set_source_rgb(1.0, 1.0, 1.0); // seteo el color al blanco
					ctx->fill_preserve(); // relleno todo el cuadrado, preservando el camino para dibujar el contorno
				ctx->restore();
				ctx->stroke(); // pinto el camino en negro

				// triángulo azul de abajo
				ctx->move_to(0.0, 1.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda
				ctx->line_to(0.5, 0.5); // línea hacia el punto del medio
				ctx->line_to(1.0, 1.0); // línea hacia el punto de abajo a la derecha
				ctx->close_path(); // cierro el camino
				ctx->save(); // salvo porque voy a cambiar el color
					ctx->set_source_rgb(0.0, 0.0, 1.0); // seteo el color al azul
					ctx->fill_preserve(); // relleno todo triángulo, preservando el camino para dibujar el contorno
				ctx->restore();
				ctx->stroke(); // pinto el camino en negro

				// triángulo azul de arriba
				ctx->move_to(0.0, 0.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda
				ctx->line_to(0.5, 0.5); // línea hacia el punto del medio
				ctx->line_to(1.0, 0.0); // línea hacia el punto de arriba a la derecha
				ctx->close_path(); // cierro el camino
				ctx->save(); // salvo porque voy a cambiar el color
					ctx->set_source_rgb(0.0, 0.0, 1.0); // seteo el color al azul
					ctx->fill_preserve(); // relleno todo triángulo, preservando el camino para dibujar el contorno
				ctx->restore();
				ctx->stroke(); // pinto el camino en negro				
			}
			return true;			
		}
예제 #4
0
void GraficoDeTorta::dibujarArco(const Cairo::RefPtr<Cairo::Context>& c,int x, int y, int radio, float angulo0, float angulo1,float r, float g, float b){
	c->set_source_rgb(1,1,1);
	c->set_line_width(2);
	c->arc(x,y,radio, angulo0, angulo1);
	c->line_to(x,y);
	c->close_path();
	c->stroke_preserve();
	c->set_source_rgb(r,g,b);
	c->fill();
}
예제 #5
0
//! Only renders the shield background, the text is rendered in renderLabels
void Renderer::renderShields(const Cairo::RefPtr<Cairo::Context>& cr,
							 std::vector<shared_ptr<Shield> >& shields) const
{
	cr->save();

	cr->set_line_join(Cairo::LINE_JOIN_ROUND);

	for (auto& shield : shields)
	{
		const Style* s = shield->style;

		double x0, y0, height, width;
		double border = ceil(s->shield_frame_width/2.0 + s->shield_casing_width);
		x0 = shield->shield.minX + border;
		y0 = shield->shield.minY + border;
		width = shield->shield.getWidth() - 2*border;
		height = shield->shield.getHeight() - 2*border;
		if ((int) s->shield_frame_width % 2 == 1) {
			x0 -= 0.5;
			y0 -= 0.5;
		}
		if (s->shield_shape == Style::ShieldShape::ROUNDED) {
			cr->arc(x0 + height/2.0, y0 + height/2.0,
					height/2.0, boost::math::constants::pi<double>()/2.0, 3.0*boost::math::constants::pi<double>()/2.0);
			cr->arc(x0 + width - height/2.0, y0 + height/2.0,
					height/2.0, 3.0*boost::math::constants::pi<double>()/2.0, boost::math::constants::pi<double>()/2.0);
			cr->close_path();
		} else
			cr->rectangle(x0, y0, width, height);

		// shield casing
		if (s->shield_casing_width > 0) {
			cr->set_source_color(s->shield_casing_color),
			cr->set_line_width(s->shield_frame_width + s->shield_casing_width * 2.0);
			cr->stroke_preserve();
		}

		// shield background
		cr->set_source_color(s->shield_color),
		cr->fill_preserve();

		// shield frame
		cr->set_source_color(s->shield_frame_color),
		cr->set_line_width(s->shield_frame_width);
		cr->stroke();
	}

	cr->restore();
}
예제 #6
0
    void NodeSurface::DrawRoundedRectangle( 
        Cairo::RefPtr<Cairo::Context> refCairo, 
        double x, 
        double y, 
        double width, 
        double height, 
        double radius,
        double red,
        double green,
        double blue,
        bool selected )
    {
        refCairo->save();

        if ( (radius > height/2.0) || (radius > width/2.0) )
        {
            radius = std::min<double>(height / 2, width / 2);
        }

        refCairo->move_to( x, y + radius );
        refCairo->arc( x + radius, y + radius, radius, sk_pi, -sk_pi / 2.0 );
        refCairo->line_to( x + width - radius, y );
        refCairo->arc( x + width - radius, y + radius, radius, -sk_pi / 2.0, 0 );
        refCairo->line_to( x + width, y + height - radius );
        refCairo->arc( x + width - radius, y + height - radius, radius, 0, sk_pi / 2.0 );
        refCairo->line_to( x + radius, y + height );
        refCairo->arc( x + radius, y + height - radius, radius, sk_pi / 2.0, sk_pi );
        refCairo->close_path();

        refCairo->set_source_rgb( red, green, blue );
        refCairo->fill_preserve();

        if ( selected == true )
        {
            refCairo->set_source_rgb( 1.0, 0.0, 0.0 );
            refCairo->set_line_width( 2 );
            refCairo->stroke();   
        }
        else
        {
            refCairo->set_source_rgb( 0.0, 0.0, 0.0 );
            refCairo->set_line_width( 1 );
            refCairo->stroke();   
        }            

        refCairo->restore();
    }
예제 #7
0
void Turtle::triangle(Cairo::RefPtr<Cairo::Context> cr, double x, double y, double size, double a) {
    cr->save();
//    cr->set_source_rgb(0, 0, 0);
/*    
    if (first) {
        first = false;
        sand->set_source_rgb(0, 0, 1);
    }
*/    
    cr->move_to(x + size * cosd(a), y + size * sind(a));
    cr->line_to(x + size * cosd(a + 120), y + size * sind(a + 120));
    cr->line_to(x + size * cosd(a + 240), y + size * sind(a + 240));
    cr->fill();
    cr->close_path();
    cr->stroke();
    cr->restore();
    
    colored_area += sqrt(3) / 2 * size * size;
}
예제 #8
0
void GraphicalItem::drawRectangle(const Cairo::RefPtr<Cairo::Context>& context,
    int x, int y,
    int width, int height,
    double red, double green, double blue)
{
    context->begin_new_sub_path();

    context->move_to(x, y);
    context->line_to(x + width, y);
    context->line_to(x + width, y + height);
    context->line_to(x, y + height);
    context->line_to(x, y);

    context->close_path();

    context->set_source_rgb(red, green, blue);
    context->fill_preserve();
    setColor(Settings::settings().getForegroundColor(), context);
    context->stroke();
}
예제 #9
0
static void
skillgui_cairo_render_polygon(GVJ_t *job, pointf *A, int n, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_polygon);
  ++__num_polygon;
#endif
  //printf("Polygon\n");
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  skillgui_cairo_set_penstyle(cairo, job);

  cairo->move_to(A[0].x, -A[0].y);
  for (int i = 1; i < n; ++i) {
    cairo->line_to(A[i].x, -A[i].y);
  }
  cairo->close_path();

  if (filled) {
    skillgui_cairo_set_color(cairo, &(obj->fillcolor));
    cairo->fill_preserve();
  }

  // HACK to workaround graphviz bug any get the Tim style...
  if ( obj->type == CLUSTER_OBJTYPE ) {
    obj->pencolor.u.RGBA[0] = 0.666;
    obj->pencolor.u.RGBA[1] = 0.666;
    obj->pencolor.u.RGBA[2] = 1.0;
    obj->pencolor.u.RGBA[3] = 1.0;
  }
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->stroke();

#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_polygon);
#endif
}
예제 #10
0
static void
skillgui_cairo_render_ellipse(GVJ_t *job, pointf *A, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_ellipse);
  ++__num_ellipse;
#endif
  //printf("Render ellipse\n");
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  Cairo::Matrix old_matrix;
  cairo->get_matrix(old_matrix);

  skillgui_cairo_set_penstyle(cairo, job);

  cairo->translate(A[0].x, -A[0].y);

  double rx = A[1].x - A[0].x;
  double ry = A[1].y - A[0].y;
  cairo->scale(1, ry / rx);
  cairo->move_to(rx, 0);
  cairo->arc(0, 0, rx, 0, 2 * M_PI);
  cairo->close_path();

  cairo->set_matrix(old_matrix);

  if (filled) {
    skillgui_cairo_set_color(cairo, &(obj->fillcolor));
    cairo->fill_preserve();
  }
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->stroke();

#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_ellipse);
#endif
}
예제 #11
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;
		}
	}
예제 #12
0
 void Fader(Cairo::RefPtr<Cairo::Context> cr, float x, float y, float value, float rms, float falloff)
 {
   // draw invisible from the last widget
   cr->set_source_rgba(0,0,0,0);
   cr->move_to( x, y );
   cr->stroke();
   
   x = x + 4; // global move widget relative to positioning
   
   // Create the linear gradient diagonal
   //Cairo::RefPtr< Cairo::LinearGradient > linGrad = Cairo::LinearGradient::create (x, y, 100, 100);
   
   // Set grandient colors
   //linGrad->add_color_stop_rgb (0, 10 / 255.f, 246 / 255.f, 98 / 255.f );
   //linGrad->add_color_stop_rgb (1, 192 / 255.f, 246 / 255.f, 98 / 255.f );
   
   // Draw rectangle and fill with gradient
   cairo_pattern_t *pat;
   pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, 400.0);
   cairo_pattern_add_color_stop_rgb(pat, 0,   0 / 255.f, 153 / 255.f, 255 / 255.f );
   cairo_pattern_add_color_stop_rgb(pat, 1,  26 / 255.f,  26 / 255.f,  26 / 255.f );
   cr->rectangle   (x, y, 12, 94);
   cairo_set_source(cr->cobj(), pat);
   cairo_fill      (cr->cobj());
   cairo_pattern_destroy (pat);
   
   // red area on top of fader graphic
   cr->rectangle ( x, y, 12, 25 );
   setColour(cr, COLOUR_ORANGE_1 );
   cr->fill();
   
   float tmpRms = (1-rms);
   
   //std::cout << "Falloff: " << falloff << " RMS " << rms << std::endl;
   
   if ( falloff > rms )
   {
     //std::cout << "Falloff > RMS" << std::endl;
     tmpRms = (1-falloff);
     falloff -= 0.1;
   }
   else
   {
     falloff = rms;
   }
   
   //std::cout << " tmpRms " << tmpRms << "  drawPx:  " << tmpRms * 94 << std::endl;
   
   cr->rectangle ( x, y, 12, 94 * tmpRms );
   setColour(cr, COLOUR_GREY_2 );
   cr->fill();
   
   // draw fader  <|
   float playheadX = x + 12;
   float playheadY = y + (92 * ( 1.f - value));
   
   setColour(cr, COLOUR_ORANGE_1 );
   cr->set_line_width(0.8);
   cr->move_to( playheadX, playheadY );
   cr->line_to( playheadX + 10, playheadY + 5.5 );
   cr->line_to( playheadX + 10, playheadY - 5.5 );
   cr->close_path();
   cr->fill_preserve();
   
   // draw fader |>
   cr->move_to( x, playheadY );
   cr->line_to( x - 10, playheadY + 5.5 );
   cr->line_to( x - 10, playheadY - 5.5 );
   cr->close_path();
   cr->fill_preserve();
   cr->stroke();
   
   // line between fader markers |> --- <|
   setColour(cr, COLOUR_GREY_4 );
   cr->set_line_width(2);
   cr->move_to( x, playheadY );
   cr->line_to( x + 12, playheadY );
   cr->stroke();
 }
예제 #13
0
void FrequencyGraph( Cairo::RefPtr<Cairo::Context> cr, bool active, float x, float y, float xS, float yS, EqualizerState state)
{
    cr->set_line_cap( Cairo::LINE_CAP_ROUND );
    cr->set_line_join( Cairo::LINE_JOIN_ROUND);

    int xSize = xS;
    int ySize = yS;

    // works but a bit simple
    cr -> move_to( x        , y         );
    cr -> line_to( x + xSize, y         );
    cr -> line_to( x + xSize, y + ySize );
    cr -> line_to( x        , y + ySize );
    cr -> close_path();

    // Draw outline shape
    cr -> set_source_rgb (0.1,0.1,0.1);
    cr -> fill();

    // draw "frequency guides"
    std::valarray< double > dashes(2);
    dashes[0] = 2.0;
    dashes[1] = 2.0;
    cr->set_dash (dashes, 0.0);
    cr->set_line_width(1.0);
    cr->set_source_rgb (0.4,0.4,0.4);
    for ( int i = 0; i < 4; i++ )
    {
        cr->move_to( x + ((xSize / 4.f)*i), y );
        cr->line_to( x + ((xSize / 4.f)*i), y + ySize );
    }
    for ( int i = 0; i < 4; i++ )
    {
        cr->move_to( x       , y + ((ySize / 4.f)*i) );
        cr->line_to( x +xSize, y + ((ySize / 4.f)*i) );
    }
    cr->stroke();
    cr->unset_dash();

    // set colour based on active or not
    if ( active )
        setColour(cr, COLOUR_BLUE_1, 0.2 );
    else
        setColour(cr, COLOUR_GREY_1, 0.2 );

    int tmpX = x;
    int tmpY = y;

    // precalculate some variables
    float oldGainPix = (ySize / 60.f) * (state.gain[0] - 0.5 ) * 40;
    float oldXLoc = 0;
    float qPix = ((xSize * 0.2) / 3.f );
    //float oldCutoff = 0;

    // move to bottom left, draw line to middle left
    cr->move_to( tmpX, tmpY + ySize         );
    cr->line_to( tmpX, tmpY + (ySize * 0.5) - oldGainPix );


    for ( int i = 0; i < 4; i++ )
    {
        //float cutoff = state.cutoffFreq[i] / 20000;


        float gainPix = (ySize / 60.f) * (state.gain[i] - 0.5 ) * 40;

        float xLoc = xSize * 0.2 * (i+1);

        //std::cout << "I: " << i << "  GainPix: " << gainPix << "  tmpY - gainPix" << tmpY - gainPix << std::endl;


        cr->curve_to( tmpX + oldXLoc + qPix, tmpY + (ySize * 0.5) - oldGainPix ,// control point 1
                      tmpX + xLoc - qPix   , tmpY + (ySize * 0.5) - gainPix ,   // control point 2
                      tmpX + xLoc          , tmpY + (ySize * 0.5) - gainPix );  // end of curve

        // update variables for next iter
        oldGainPix = gainPix;
        oldXLoc = xLoc;
        //oldCutoff = cutoff;
    }

    // last bit of curve to the right edge
    cr->curve_to( tmpX + oldXLoc + qPix, tmpY + (ySize * 0.5) - oldGainPix,   // control point 1
                  tmpX + xSize   - qPix, tmpY + (ySize * 0.5) - oldGainPix,   // control point 2
                  tmpX + xSize         , tmpY + (ySize * 0.5) - oldGainPix);  // end of curve


    cr->line_to( tmpX + xSize , tmpY + ySize );
    cr->close_path();
    cr->fill_preserve();

    cr->set_line_width(2.5);
    if ( active )
        setColour(cr, COLOUR_BLUE_1 );
    else
        setColour(cr, COLOUR_GREY_1 );
    cr->stroke();

    // outline
    cr->rectangle( x, y , xS, yS );
    cr->set_line_width(3);
    if ( active )
        setColour(cr, COLOUR_GREY_2 );
    else
        setColour(cr, COLOUR_GREY_3 );
    cr->stroke();

    //std::cout << "LupppWidget::FrequencyGraph() called!" << std::endl;
}
bool SamplerWidget::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
	{
		allocation = get_allocation();
		int width = allocation.get_width();
		int height = allocation.get_height();
		
		//std::cout << "Width: " << width << std::endl;
		//std::cout << "Height: " << height << std::endl;
		//std::cout << "Height / 12: " << height /12.0 << std::endl;
		
		// 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 -> set_source_rgba(0 , 0, 0 , 1);
		cr->rectangle(event->area.x, event->area.y,
		        event->area.width, event->area.height);
		//cr->rectangle(0,0,event->area.x,event->area.y);
		//cr->stroke_preserve();
		cr->clip();
		
		cr -> set_line_join (Cairo::LINE_JOIN_ROUND);
		
		cr -> move_to( 7, 7);
		cr -> line_to( width-7, 7);
		cr -> line_to( width-7, height-7);
		cr -> line_to( 7, height-7);
		cr -> close_path();
		
		// Draw outline shape
		cr -> set_source_rgb (0.1,0.1,0.1);
		cr -> fill_preserve();
		
		if (!padOnBool)
		{
			cr->set_source_rgba( 0.6, 0.6, 0.6, 0.5);
			cr->set_line_width ( 10.0);
			cr->stroke();
		}
		else
		{
			cr->set_source_rgba( 1.0,0.4,0.0, 0.8);
			cr->set_line_width ( 10.4);
			cr->stroke();
		}
		
		/* Pan functionality Not yet implemented in sampler.
		
		// Draw Pan line: pixel pan = width * pan
		cr -> set_line_cap (Cairo::LINE_CAP_ROUND);
		cr -> set_line_width ( 4.8);
		cr -> set_source_rgba( 1.0,0.8,0.8,0.8);
		cr -> move_to ( width/2 + ((width*pan)/2) , height - (height*volume) + 20);
		cr -> line_to ( width/2 + ((width*pan)/2) , height - (height*volume) - 20);
		cr -> stroke();
		*/
		
		// Draw Volume line: pixel vol = height * volume
		cr -> set_line_width ( 5.1);
		cr -> set_source_rgb( 0.2,0.2,0.2);
		cr -> move_to ( 10      , (height - ((height-20)*volume))-8 );
		cr -> line_to ( width-10, (height - ((height-20)*volume))-8 );
		cr -> line_to ( width-10, height-10);
		cr -> line_to ( 10, height-10);
		cr -> close_path();
		cr -> fill();
		
		// Draw Mode: Loop/Hit
		
		if ( !loopSampleBool)
		{
			cr->set_line_width ( 2.2);
			cr->set_source_rgb(0.2,0.2,0.2);
			cr->move_to(width/5,(height/5)*2);
			cr->line_to((width/5)*3,(height/5)*2);
			cr->line_to((width/5)*3,(height/5)*1);
			cr->line_to((width/5)*4,height/2);		// point of arrow
			cr->line_to((width/5)*3,(height/5)*4);
			cr->line_to((width/5)*3,(height/5)*3);
			cr->line_to(width/5,(height/5)*3);
			cr->close_path();
			cr->fill_preserve();
			
			cr->set_source_rgb(0.0,0.9,0.0);
			cr->stroke();
		}
		else // Loop Sample
		{
			cr -> set_source_rgb(0.2,0.2,0.2);
			cr -> arc_negative	(width/2, height/2, ((height  + width)/8)-5 , 6.0, 0.6); 	// inner curve
			cr -> arc			(width/2, height/2, ((height  + width)/6)-5 , 0.5, 6.1); 	// outer curve
			
			cr -> line_to		((width-width/3.5) + width/8  ,	height/2 - height/18 ); 	// right point of arrow
			cr -> line_to		( width-width/3.5,				height/2 + height/18 ); 	// point of arrow
			cr -> line_to		((width-width/3.5) - width/8  ,	height/2 - height/18 ); 	// left point of arrow
			cr -> close_path();
			cr -> fill_preserve();
			cr -> set_line_width(1.9);
			cr -> set_source_rgb(0.0,0.9,0.0);
			cr -> stroke();
		}
		
		// Impose orange volume line (over SampleLoop/Play)
		cr -> move_to ( 10      , (height - ((height-20)*volume))-8 );
		cr -> line_to ( width-10, (height - ((height-20)*volume))-8 );
		cr -> set_source_rgb(1.0,0.4,0.0);
		cr -> stroke();
		
		// Draw Text in center. Audio Clip name.
		cr -> set_source_rgb( 1.0,0.4,0.0);
		cr -> select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL,Cairo::FONT_WEIGHT_NORMAL);
		cr -> set_font_size ( 3 + xc/4 );
		Cairo::TextExtents extents;
		std::transform(sampleName.begin(), sampleName.end(), sampleName.begin(), toupper);
		cr -> get_text_extents(sampleName, extents);
		cr -> move_to ( xc - extents.width/2 , height/2+height/18);
		cr -> show_text (sampleName); // sampleName defined in hpp as std::string
	} 
	return true;
}
예제 #15
0
bool GHighPass::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
  {
    Gtk::Allocation allocation = get_allocation();
    int width = allocation.get_width();
    int height = allocation.get_height();
    
    // 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);
    setColour(cr, COLOUR_GREY_3 );
    cr->fill();
    
    //cout << "HighPass getting state ID " << ID << endl; 
    float cutoffRangeZeroOne = stateStore->effectState.at(ID).values[0];
    
    cutoff = cutoffRangeZeroOne;
    
    bool active = stateStore->effectState.at(ID).active;
    bool globalUnit = stateStore->effectState.at(ID).globalUnit;
    
    int x = 0;
    int y = 0;
    xSize = 73;
    ySize = 37;
    
    // works but a bit simple
    cr -> move_to( x        , y         );
    cr -> line_to( x + xSize, y         );
    cr -> line_to( x + xSize, y + ySize );
    cr -> line_to( x        , y + ySize );
    cr -> close_path();
    
    // Draw outline shape
    cr -> set_source_rgb (0.1,0.1,0.1);
    cr -> fill();
    
    // draw "frequency guides"
    std::valarray< double > dashes(2);
    dashes[0] = 2.0;
    dashes[1] = 2.0;
    cr->set_dash (dashes, 0.0);
    cr->set_line_width(1.0);
    cr->set_source_rgb (0.4,0.4,0.4);
    for ( int i = 0; i < 3; i++ )
    {
      cr->move_to( x + ((xSize / 3.f)*i), y );
      cr->line_to( x + ((xSize / 3.f)*i), y + ySize );
    }
    for ( int i = 0; i < 3; i++ )
    {
      cr->move_to( x       , y + ((ySize / 3.f)*i) );
      cr->line_to( x +xSize, y + ((ySize / 3.f)*i) );
    }
    cr->stroke();
    cr->unset_dash();
    
    // move to bottom left, draw line to middle left
    cr->move_to( x + xSize-2 , y + ySize );
    cr->line_to( x + xSize-2 , y + (ySize/2));
    
    
    int startHorizontalLine = xSize* (cutoff + 0.4);
    if ( startHorizontalLine > 75 )
      startHorizontalLine = 75;
      
    cr->line_to( startHorizontalLine, y + (ySize/2) ); // horizontal line to start of curve
    
    int xSize1CP1 = xSize* (cutoff +0.1);
    int xSize1CP2 = xSize* (cutoff +0.08);
    int xSize1End = xSize* cutoff;
    
    if ( xSize1CP1 > 75 )
      xSize1CP1 = 75;
    if ( xSize1CP2 > 75 )
      xSize1CP2 = 75;
    if ( xSize1End > 75 )
      xSize1End = 75;
    
    cr->curve_to( xSize1CP1, y+(ySize*0.5),   // control point 1
                  xSize1CP2, y+(ySize*0.3),   // control point 2
                  xSize1End, y+(ySize*0.3));  // end of curve 1, start curve 2
    
    int xSize2CP1 = xSize* (cutoff - 0.03);
    int xSize2CP2 = xSize* (cutoff - 0.08);
    int xSize2End = xSize* (cutoff - 0.15);
    
    if ( xSize2CP1 > 75 )
      xSize2CP1 = 75;
    if ( xSize2CP2 > 75 )
      xSize2CP2 = 75;
    if ( xSize2End > 75 )
      xSize2End = 75;
    
    cr->curve_to( xSize2CP1, y+(ySize*0.3),  // control point 1
                  xSize2CP2, y+(ySize*0.3), // control point 2
                  xSize2End, y+(ySize)   ); // end of curve on floor
    
    if (active)
      setColour(cr, COLOUR_BLUE_1, 0.2 );
    else
      setColour(cr, COLOUR_GREY_1, 0.2 );
    cr->close_path();
    cr->fill_preserve();
    
    // stroke cutoff line
    cr->set_line_width(2.5);
    if ( active )
      setColour(cr, COLOUR_BLUE_1 );
    else
      setColour(cr, COLOUR_GREY_1 );
    cr->stroke();
    
    // click center
    if ( globalUnit )
    {
      if ( active )
        setColour(cr, COLOUR_GREEN_1, 0.9 );
      else
        setColour(cr, COLOUR_GREY_1,0.9 );
      cr->move_to( xSize * cutoff - 5, ySize*q - 5 );
      cr->line_to( xSize * cutoff + 5, ySize*q + 5 );
      cr->move_to( xSize * cutoff - 5, ySize*q + 5 );
      cr->line_to( xSize * cutoff + 5, ySize*q - 5 );
      cr->stroke();
    }
    else
    {
      if ( active )
        setColour(cr, COLOUR_ORANGE_1, 0.9 );
      else
        setColour(cr, COLOUR_GREY_1, 0.9 );
      cr->arc( xSize*cutoff, ySize*q, 7, 0, 6.2830 );
      cr->stroke();
    }
    
    // dials
    Dial(cr, active, 70, 140, cutoffRangeZeroOne, DIAL_MODE_NORMAL);
    Dial(cr, active, 150,140, q                 , DIAL_MODE_NORMAL);
    
    // outline
    setColour(cr, COLOUR_GREY_3 );
    cr->rectangle( x, y , xSize, ySize );
    cr->set_line_width(3);
    
    setColour(cr, COLOUR_GREY_2 );
    cr->stroke();
    
    /*
    if ( state.selected )
    {
      cr->rectangle(0, 0, 74, 216);
      setColour( cr, COLOUR_PURPLE_1 );
      cr->set_line_width(1);
      cr->stroke();
    }
    */
    
  }
  return true;
}