コード例 #1
0
ファイル: SDLRenderer.cpp プロジェクト: cesarparent/Meteor
void
SDLRenderer::renderLine(const vec2& start, const vec2& end, const Color& color) {
    SDL_SetRenderDrawColor(_renderer,
                           color.red * 255,
                           color.green * 255,
                           color.blue * 255,
                           color.alpha * 255);
    
    auto p1 = AffineTransform::applyTransform(_origin, start);
    auto p2 = AffineTransform::applyTransform(_origin, end);
    
    SDL_RenderDrawLine(_renderer,
                       p1.x,
                       p1.y,
                       p2.x,
                       p2.y);
}
コード例 #2
0
ファイル: ngui_flowbox.cpp プロジェクト: jcftang/ngui
void ngui_render_flowbox_connection(ngui_flowbox_connection_data *d)
{

	int input_flowbox  = d->input_port_flowbox;
	int input_port     = d->input_port_number;
	int output_flowbox = d->output_port_flowbox;
	int output_port    = d->output_port_number;

	double ix = input_port_x (&ngui_flowboxs[input_flowbox] ,input_port);
	double iy = input_port_y (&ngui_flowboxs[input_flowbox] ,input_port);
	double ox = output_port_x(&ngui_flowboxs[output_flowbox],output_port);
	double oy = output_port_y(&ngui_flowboxs[output_flowbox],output_port);

	SDL_RenderDrawLine(ngui_renderer,
	                   ix,
	                   iy,
	                   ox,
	                   oy);

	int delta=0;
	if(ox < ix) delta= 1;
	else delta=-1;

	if(flow_running)
	{
		double m = (oy-iy) / (ox-ix);

		int n=0;
		for(int x=ox; x!=ix; x+=delta)
		{

			SDL_Rect rect;

			rect.x = x;
			rect.y = (m*(x-ox))+oy-4;
			rect.w = 8;//-((n+(flow_run_count/50))%10);
			rect.h = 8;//-((n+(flow_run_count/50))%10);

			if(n%15 == ((flow_run_count/50)%15)) SDL_RenderDrawRect(ngui_renderer,&rect);
			n++;
		}
		ngui_redraw_required();
		flow_run_count++;
	}
}
コード例 #3
0
ファイル: Path.cpp プロジェクト: sammut91/TDG-DIstinction
void Path::Render(SDL_Renderer* renderer)
{
	if (!m_Points.empty())
	{
		if (m_Points.size() > 1)
		{
			for (int i = 0; i < m_Points.size(); i++)
			{
				if (m_Points[i] != m_Points.back())
				{
					SDL_RenderDrawLine(renderer, m_Points[i]->x, m_Points[i]->y, m_Points[i + 1]->x, m_Points[i + 1]->y);
				}
				
			}
			
		}
	}
}
コード例 #4
0
ファイル: effects.c プロジェクト: akien-mga/tbftss
void drawEffects(void)
{
	int i;
	Effect *e;

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);

	for (i = 0, e = effectsToDraw[i] ; e != NULL ; e = effectsToDraw[++i])
	{
		SDL_SetRenderDrawColor(app.renderer, e->r, e->g, e->b, e->a);

		SDL_SetTextureBlendMode(e->texture, SDL_BLENDMODE_ADD);
		SDL_SetTextureAlphaMod(e->texture, e->a);

		switch (e->type)
		{
			case EFFECT_POINT:
				SDL_RenderDrawPoint(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y);
				break;

			case EFFECT_LINE:
				SDL_RenderDrawLine(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y, e->x + (e->dx * 3) - battle.camera.x, e->y + (e->dy * 3) - battle.camera.y);
				break;

			case EFFECT_TEXTURE:
				SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
				blitScaled(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->size, e->size, 0);
				break;

			case EFFECT_HALO:
				SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
				blitScaled(e->texture, e->x - battle.camera.x - (e->size / 2), e->y - battle.camera.y - (e->size / 2), e->size, e->size, 0);
				break;

			case EFFECT_ECM:
				SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
				blitScaled(e->texture, SCREEN_WIDTH / 2 - (e->size / 2), SCREEN_HEIGHT / 2 - (e->size / 2), e->size, e->size, 0);
				break;
		}
	}

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
}
コード例 #5
0
void SDLHardwareRenderDevice::drawLine(
	int x0,
	int y0,
	int x1,
	int y1,
	Uint32 color
) {
	Uint32 u_format = SDL_GetWindowPixelFormat(window);
	SDL_PixelFormat* format = SDL_AllocFormat(u_format);

	if (!format) return;

	SDL_Color rgba;
	SDL_GetRGBA(color, format, &rgba.r, &rgba.g, &rgba.b, &rgba.a);
	SDL_FreeFormat(format);

	SDL_SetRenderDrawColor(renderer, rgba.r, rgba.g, rgba.b, rgba.a);
	SDL_RenderDrawLine(renderer, x0, y0, x1, y1);
}
コード例 #6
0
ファイル: navigation.cpp プロジェクト: rmtoth/ritual
void SimDebugDraw(SDL_Renderer *r, float t)
{
	auto it = GetPotentialField(t);
	int w = it->w;
	int *next = &it->next[0];
	for (int i = 0; i < w * it->h; ++i)
	{
		int j = next[i];
		if (j == -1) continue;
		float x0 = float(i % w);
		float y0 = float(i / w);
		float x1 = float(j % w);
		float y1 = float(j / w);
		float sx0, sy0, sx1, sy1;
		g_world->WorldToScreen(sx0, sy0, x0, y0);
		g_world->WorldToScreen(sx1, sy1, x1, y1);
		SDL_RenderDrawLine(r, (int)sx0, (int)sy0, (int)sx1, (int)sy1);
	}
}
コード例 #7
0
ファイル: main.cpp プロジェクト: ProkopHapala/cpp_arch
void draw(){
	//SDL_SetRenderDrawColor(render, 128, 128, 128, 255);
    //SDL_RenderClear(render);
	SDL_RenderCopy( render, tempTex, &SrcR, &DestR);

	int mouseX,mouseY;
	SDL_GetMouseState( &mouseX, &mouseY );

	double dfdx=0,dfdy=0;
	double x = i2x( mouseX );
	double y = i2y( mouseY );
	double f = warped_function( x, y, dfdx, dfdy );
	SDL_SetRenderDrawColor(render, 255, 0, 0, 255);
	SDL_RenderDrawLine    ( render, x2i( x ), y2i( y ), x2i( x - dfdx ), y2i( y - dfdy ) ); 
	//printf( " %f %f %f %f \n", x, y, dfdx, dfdy );

	SDL_RenderPresent( render );
	SDL_UpdateWindowSurface(window);
}
コード例 #8
0
ファイル: render.c プロジェクト: Jools64/IWBTG-C-Engine
void lineDraw(Game* g, float ax, float ay, float bx, float by,
              float cr, float cg, float cb, float ca)
{
    #ifdef OPENGL
    
        
    
    #else
        SDL_SetRenderDrawBlendMode(g->renderer,
                                   SDL_BLENDMODE_BLEND);
        SDL_SetRenderDrawColor(g->renderer, 
                               clampi((cr * 255), 0, 255), 
                               clampi((cg * 255), 0, 255), 
                               clampi((cb * 255), 0, 255), 
                               clampi((ca * 255), 0, 255));
        SDL_RenderDrawLine(g->renderer, ax, ay, bx, by);
    
    #endif
}
コード例 #9
0
void PathfindingApp::drawPath()
{
	// Start at the start point
	// tileSize / 2 is added to all coordinates to put them in the centre of the tile
	int lastX = map->getStartX() * tileSize + tileSize / 2;
	int lastY = map->getStartY() * tileSize + tileSize / 2;

	// Step through the path
	for (const Point& point : path)
	{
		int nextX = point.getX() * tileSize + tileSize / 2;
		int nextY = point.getY() * tileSize + tileSize / 2;

		SDL_RenderDrawLine(renderer, lastX, lastY, nextX, nextY);
		lastX = nextX;
		lastY = nextY;
		;
	}
}
コード例 #10
0
ファイル: Wall.cpp プロジェクト: Hagglesmith/tunnelproject-1
/** Other Functions **/
void Wall::draw(Renderer & g_renderer)
{
	/*
	* Draw the line for this Wall object. Use the simple SDL
	* functions. The hexidecimal can also be written as decimal.
	*/
	SDL_SetRenderDrawColor(g_renderer, 0x20, 0x20, 0x20, 0x20);
	SDL_RenderDrawLine(g_renderer, getX(), getY(), getX2(), getY2());
	/*
	int y = getY();
	int z;
	do
	{
		SDL_RenderDrawPoint(g_renderer, getX(), y);
		if (getO() == TOP) y--;
		else y++;
		std::cin >> z;
	} while (y != 0 && y != 479);
	*/
}
コード例 #11
0
ファイル: draw.c プロジェクト: computermouth/shortstack
SDL_Renderer* draw_shape(shape_t *shape, SDL_Renderer* renderer){
	
	SDL_SetRenderDrawBlendMode(renderer, (shape->color[3] == 255) ? 
		SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, 
		shape->color[0], 
		shape->color[1], 
		shape->color[2], 
		shape->color[3]);	

	int i;
	for(i = 0; i < shape->line_cnt; i++){
		SDL_RenderDrawLine(renderer, 
			shape->lines[i].xa, 
			shape->lines[i].y, 
			shape->lines[i].xb, 
			shape->lines[i].y);
	}
		
	return renderer;
}
コード例 #12
0
ファイル: MinimapView.cpp プロジェクト: nint22/RayCaster
void MinimapView::Render( SDL_Renderer* renderer )
{
	SDL_Rect rect;

	// For each tile in the game world
	Vector2i worldSize = m_gameWorld->GetWorldSize();
	for(int y = 0; y < worldSize.y; y++)
	for(int x = 0; x < worldSize.x; x++)
	{
		int tileId = m_gameWorld->GetWorldTile(x, y)->m_tileId;
		
		if(tileId == ' ')
			SDL_SetRenderDrawColor( renderer, 255, 255, 255, 255 );
		else
			SDL_SetRenderDrawColor( renderer, 32, 32, 32, 255 );
		
		rect.x = m_minimapPos.x + x * m_minimapTileSize;
		rect.y = m_minimapPos.y + y * m_minimapTileSize;
		rect.h = rect.w = m_minimapTileSize;

		SDL_RenderFillRect( renderer, &rect );
	}

	// Draw wherever the player is as a circle, then draw the facing vector
	Vector3f ppos = m_player->GetPosition();
	rect.x = (int)((float)m_minimapPos.x + ppos.x * (float)m_minimapTileSize - 1.0f);
	rect.y = (int)((float)m_minimapPos.y + ppos.y * (float)m_minimapTileSize - 1.0f);
	rect.h = rect.w = 3;

	SDL_SetRenderDrawColor( renderer, 0, 0, 128, 255 );
	SDL_RenderFillRect( renderer, &rect );

	// Draw a line for the facing-direction
	float facing = m_player->GetFacing();
	int dx = (int)(cos( facing ) * 8.0f);
	int dy = (int)(-sin( facing ) * 8.0f);
	
	SDL_SetRenderDrawColor( renderer, 255, 0, 0, 255 );
	SDL_RenderDrawLine( renderer, rect.x + 1, rect.y + 1, rect.x + dx + 1, rect.y + dy + 1 );
}
コード例 #13
0
ファイル: testviewport.c プロジェクト: Daft-Freak/vogl
void
DrawOnViewport(SDL_Renderer * renderer, SDL_Rect viewport)
{    
    SDL_Rect rect;

    /* Set the viewport */
    SDL_RenderSetViewport(renderer, &viewport);
    
    /* Draw a gray background */
    SDL_SetRenderDrawColor(renderer, 0x80, 0x80, 0x80, 0xFF);
    SDL_RenderClear(renderer);

    /* Test inside points */
    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xF, 0xFF);
    SDL_RenderDrawPoint(renderer, viewport.h/2 + 10, viewport.w/2);
    SDL_RenderDrawPoint(renderer, viewport.h/2 - 10, viewport.w/2);
    SDL_RenderDrawPoint(renderer, viewport.h/2     , viewport.w/2 - 10);
    SDL_RenderDrawPoint(renderer, viewport.h/2     , viewport.w/2 + 10);

    /* Test horizontal and vertical lines */
    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
    SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
    SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
    SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
    SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);

    /* Test diagonal lines */
    SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF);
    SDL_RenderDrawLine(renderer, 0, 0,
                       viewport.w-1, viewport.h-1);
    SDL_RenderDrawLine(renderer, viewport.w-1, 0,
                       0, viewport.h-1);                      

    /* Test outside points */
    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xF, 0xFF);
    SDL_RenderDrawPoint(renderer, viewport.h/2 + viewport.h, viewport.w/2);
    SDL_RenderDrawPoint(renderer, viewport.h/2 - viewport.h, viewport.w/2);
    SDL_RenderDrawPoint(renderer, viewport.h/2     , viewport.w/2 - viewport.w);
    SDL_RenderDrawPoint(renderer, viewport.h/2     , viewport.w/2 + viewport.w);

    /* Add a box at the top */
    rect.w = 8;
    rect.h = 8;
    rect.x = (viewport.w - rect.w) / 2;
    rect.y = 0;
    SDL_RenderFillRect(renderer, &rect);
}
コード例 #14
0
ファイル: primitives.c プロジェクト: tedajax/runner
int prim_circle(SDL_Renderer* renderer, Circle* circle, u32 segments) {
    int result = 0;

    f32 degPerSegment = 360.f / segments;

    f32 x0 = circle->position.x + cosf(0.f) * circle->radius;
    f32 y0 = circle->position.y + sinf(0.f) * circle->radius;

    for (u32 s = 1; s <= segments; ++s) {
        f32 a = degPerSegment * DEG_TO_RAD * (f32)s;
        
        f32 x1 = circle->position.x + cosf(a) * circle->radius;
        f32 y1 = circle->position.y + sinf(a) * circle->radius;

        result |= SDL_RenderDrawLine(renderer, (int)x0, (int)y0, (int)x1, (int)y1);

        x0 = x1;
        y0 = y1;
    }

    return result;
}
コード例 #15
0
ファイル: ngui_button.c プロジェクト: new299/wflow
void draw_alt_icon  (int x,int y,int shine) {


    SDL_Rect rect;

    rect.x = x;
    rect.y = y;
    rect.w = 6*16;
    rect.h = 6*16;

    SDL_SetRenderDrawColor(ngui_renderer,0x50,0x50,0x50,0xFF);
    SDL_RenderDrawRect(ngui_renderer,&rect);

    int col = 0xA0;
    if(shine != 0) {
        if(shine>10) {
            col = ((255/10)*(shine-10));
        } else {
            col = (0xA0/10)*(10-shine);
        }
    }
    SDL_SetRenderDrawColor(ngui_renderer,col,col,col,0xFF);
    // A
    SDL_RenderDrawLine(ngui_renderer,x+16,y+(16*4),x   ,y+(16*4));  // Top line
    SDL_RenderDrawLine(ngui_renderer,x   ,y+(16*4),x   ,y+(16*6)-1);  // Down line
    SDL_RenderDrawLine(ngui_renderer,x   ,y+(16*5),x+16,y+(16*5));  // Midline
    SDL_RenderDrawLine(ngui_renderer,x+16,y+(16*4),x+16,y+(16*6)-1);  // Right down line

    // L
    SDL_RenderDrawLine(ngui_renderer,x+(16*2),y+(16*4),x+(16*2),y+(16*6)-1); // left
    SDL_RenderDrawLine(ngui_renderer,x+(16*3),y+(16*6)-1,x+(16*2),y+(16*6)-1); //bottom

    // T
    SDL_RenderDrawLine(ngui_renderer,x+(16*6),y+(16*4),x+(16*4),y+(16*4));
    SDL_RenderDrawLine(ngui_renderer,x+(16*5),y+(16*4),x+(16*5),y+(16*6)-1);
}
コード例 #16
0
ファイル: primitives.c プロジェクト: tedajax/runner
int prim_rect_oriented(SDL_Renderer* renderer, Rect* rect, f32 rotation) {
    Vec2 corners[4];

    Vec2 x = vec2_init(cosf(rotation), sinf(rotation));
    Vec2 y = vec2_init(-sinf(rotation), cosf(rotation));

    vec2_scale(&x, rect->width / 2.f, &x);
    vec2_scale(&y, rect->height / 2.f, &y);

    Vec2 center;
    center.x = rect->position.x + rect->width / 2.f;
    center.y = rect->position.y + rect->height / 2.f;

    for (u32 i = 0; i < 4; ++i) {
        vec2_copy_to(&center, &corners[i]);
    }

    vec2_sub(&corners[0], &x, &corners[0]);
    vec2_sub(&corners[0], &y, &corners[0]);

    vec2_add(&corners[1], &x, &corners[1]);
    vec2_sub(&corners[1], &y, &corners[1]);

    vec2_add(&corners[2], &x, &corners[2]);
    vec2_add(&corners[2], &y, &corners[2]);

    vec2_sub(&corners[3], &x, &corners[3]);
    vec2_add(&corners[3], &y, &corners[3]);

    int result = 0;
    for (u32 i = 0; i < 4; ++i) {
        Vec2 c1 = corners[i];
        Vec2 c2 = (i < 3) ? corners[i + 1] : corners[0];
        result |= SDL_RenderDrawLine(renderer, (int)c1.x, (int)c1.y, (int)c2.x, (int)c2.y);
    }

    return result;
}
コード例 #17
0
ファイル: testintersections.c プロジェクト: Distrotech/SDL
static void
DrawRectLineIntersections(SDL_Renderer * renderer)
{
    int i, j;

    SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);

    for (i = 0; i < num_rects; i++)
        for (j = 0; j < num_lines; j++) {
            int x1, y1, x2, y2;
            SDL_Rect r;

            r = rects[i];
            x1 = lines[j].x;
            y1 = lines[j].y;
            x2 = lines[j].w;
            y2 = lines[j].h;

            if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
                SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
            }
        }
}
コード例 #18
0
ファイル: input.cpp プロジェクト: west3316/AUI
bool Input::draw(SDL_Renderer * renderer)
{
	//static clock_t clock = std::clock();

	Label::draw(renderer);
	SDL_Rect rcText = { 0, 0, 0, 0 };
	if (!_text.empty()) 
	{
		memcpy(&rcText, &getTextRect(), sizeof(rcText));
	}

	SDL_Rect rcPading;
	getPaddingRect(rcPading);
	SDL_Rect dstText = { rcPading.x, rcPading.y, rcText.w, rcText.h };
	if (_bGrating)
	{
		int x = rcPading.x + dstText.w + 1;				// +1 for grating
		SDL_SetRenderDrawColor(renderer, 0xcc, 0xcc, 0xcc, 0xff);
		SDL_RenderDrawLine(renderer, x, rcPading.y, x, rcPading.y + rcPading.h);
	}

	return true;
}
コード例 #19
0
ファイル: Plot.cpp プロジェクト: jason-weber/FFT
void Plot::drawGraph(SDL_Renderer* renderer){

	//Draw y axis tick marks
	SDL_RenderDrawLine(renderer, x - 5, y, x + 5, y);
	SDL_RenderDrawLine(renderer, x - 5, y + (float)(height / 5), x + 5, y + (float)(height / 5));
	SDL_RenderDrawLine(renderer, x - 5, y + (float)(height / 5) * 2, x + 5, y + (float)(height / 5) * 2);
	SDL_RenderDrawLine(renderer, x - 5, y + (float)(height / 5) * 3, x + 5, y + (float)(height / 5) * 3);
	SDL_RenderDrawLine(renderer, x - 5, y + (float)(height / 5) * 4, x + 5, y + (float)(height / 5) * 4);
	
	for(unsigned int i = 0; i < yValues->size() - 1; i++){
		//Draw next plot line
		int x1 = (int)((i * deltaX / this->maxX) * this->width + x);
		int y1 = (int)((y + this->height) - (yValues->at(i) / this->maxY) * this->height);
		int x2 = (int)(((i + 1) * deltaX / this->maxX) * this->width + x);
		int y2 = (int)((y + this->height) - (yValues->at(i + 1) / this->maxY) * this->height);
		SDL_RenderDrawLine(renderer, x1, y1, x2, y2);

		//Draw tick marks on x axis
		SDL_RenderDrawLine(renderer, x2, y + height - 5, x2, y + height + 5);
	}

}
コード例 #20
0
ファイル: video_display.c プロジェクト: Jakopter/Jakopter
/**
* \brief simple attitude indicator with the horizon represented by a straight line
* and the drone by a line with a center point.
*/
void draw_attitude_indic()
{
	int i = 0;
	//nose inclination = y offset from the horizon
	int nose_incl = (int)(horiz_pitchScale * pitch);
	//"center" of the drone, unaffected by roll
	SDL_Point center = {horiz_posx + horiz_size/2, horiz_posy-nose_incl};
	//series of points representing the drone on the indicator, affected by pitch
	SDL_Point drone_points[] = {
		{horiz_posx, center.y},
		{center.x-5, center.y},
		{center.x, center.y-5},
		{center.x+5, center.y},
		{horiz_posx+horiz_size, center.y}
	};
	int nb_points = sizeof(drone_points)/sizeof(SDL_Point);
	//apply roll to the points
	for (i = 0; i < nb_points; i++)
		rotate_point(&drone_points[i], &center, roll);
	//1. draw the horizon
	SDL_RenderDrawLine(renderer, horiz_posx, horiz_posy, horiz_posx+horiz_size, horiz_posy);
	//2. draw the drone's "flight line"
	SDL_RenderDrawLines(renderer, drone_points, nb_points);
}
コード例 #21
0
ファイル: ngui_button.c プロジェクト: new299/wflow
void draw_ctrl_icon (int x,int y,int shine) {


    SDL_Rect rect;

    rect.x = x;
    rect.y = y;
    rect.w = 6*16;
    rect.h = 6*16;

    SDL_SetRenderDrawColor(ngui_renderer,0x50,0x50,0x50,0xFF);
    SDL_RenderDrawRect(ngui_renderer,&rect);

    int col = 0xA0;
    if(shine != 0) {
        if(shine>10) {
            col = ((255/10)*(shine-10));
        } else {
            col = (0xA0/10)*(10-shine);
        }
    }
    SDL_SetRenderDrawColor(ngui_renderer,col,col,col,0xFF);
    // C
    SDL_RenderDrawLine(ngui_renderer,x+16,y+(16*0),x   ,y+(16*0));
    SDL_RenderDrawLine(ngui_renderer,x   ,y+(16*0),x   ,y+(16*2));
    SDL_RenderDrawLine(ngui_renderer,x   ,y+(16*2),x+16,y+(16*2));

    // T
    SDL_RenderDrawLine(ngui_renderer,x+(16*4),y+(16*0),x+(16*2)   ,y+(16*0));  // Top line
    SDL_RenderDrawLine(ngui_renderer,x+(16*3),y+(16*0),x+(16*3),y+(16*2));

    // L
    SDL_RenderDrawLine(ngui_renderer,x+(16*5),y+(16*0),x+(16*5),y+(16*2));
    SDL_RenderDrawLine(ngui_renderer,x+(16*5),y+(16*2),x+(16*6),y+(16*2));

}
コード例 #22
0
ファイル: SceneSDL.cpp プロジェクト: Puttini/Prototype_1
void SceneSDL::afficherGrille()
{
    // Lignes verticales
    SDL_SetRenderDrawColor(m_rendu, 0, 0, 0, 200);
    for(int i = 0 ; i <= def::width ; i += def::pasGrille)
        SDL_RenderDrawLine(m_rendu, i*def::taillePixel, 0, i*def::taillePixel, def::height*def::taillePixel);
    SDL_SetRenderDrawColor(m_rendu, 0, 0, 0, 128);
    for(int i = 0 ; i <= def::width ; i += def::divisionGrille*def::pasGrille)
    {
        SDL_RenderDrawLine(m_rendu, i*def::taillePixel+1, 0, i*def::taillePixel+1, def::height*def::taillePixel);
        SDL_RenderDrawLine(m_rendu, i*def::taillePixel-1, 0, i*def::taillePixel-1, def::height*def::taillePixel);
    }

    // Lignes horizontales
    SDL_SetRenderDrawColor(m_rendu, 0, 0, 0, 200);
    for(int j = 0 ; j <= def::height ; j += def::pasGrille)
        SDL_RenderDrawLine(m_rendu, 0, j*def::taillePixel, def::width*def::taillePixel, j*def::taillePixel);
    SDL_SetRenderDrawColor(m_rendu, 0, 0, 0, 128);
    for(int j = 0 ; j <= def::height ; j += def::divisionGrille*def::pasGrille)
    {
        SDL_RenderDrawLine(m_rendu, 0, j*def::taillePixel+1, def::width*def::taillePixel, j*def::taillePixel+1);
        SDL_RenderDrawLine(m_rendu, 0, j*def::taillePixel-1, def::width*def::taillePixel, j*def::taillePixel-1);
    }
}
コード例 #23
0
ファイル: Window.cpp プロジェクト: Gumichan01/lunatix-engine
void Window::drawLine( const lx::Graphics::ImgCoord& p,
                       const lx::Graphics::ImgCoord& q ) noexcept
{
    SDL_RenderDrawLine( m_wimpl->renderer, p.x, p.y, q.x, q.y );
}
コード例 #24
0
ファイル: Graphics.cpp プロジェクト: mdclyburn/hume
 void Graphics::draw_line(const int32_t x1, const int32_t y1, const int32_t x2, const int32_t y2)
 {
     if(SDL_RenderDrawLine(window->get_renderer(), x1, y1, x2, y2) != 0) throw SDLException();
     return;
 }
コード例 #25
0
ファイル: Vector2D.cpp プロジェクト: MantasVit/test3
void Vector2D::draw(SDL_Renderer* renderer){
	SDL_SetRenderDrawColor( renderer, 0x00, 0x00, 0xFF, 0xFF ); 
	SDL_RenderDrawLine(renderer, 100, 100, 200, 200);
	printf("drawn");
}
コード例 #26
0
/* Draw a (r,g,b,a) line from (x1,y1) to (x2, y2)
* @param (r, g, b, a) is the RGB color
* @param (x1, y1) is the source coordinate
* @param (x2, y2) is the target coordinate
*/
void SDLInterface::drawLine(int r, int g, int b, int a, int x1, int y1, int x2, int y2) {
	SDL_SetRenderDrawColor(_renderer, r, g, b, a);
	SDL_RenderDrawLine(_renderer, x1, y1, x2, y2);
	SDL_SetRenderDrawColor(_renderer, windowBackGroundColor.r, windowBackGroundColor.g, windowBackGroundColor.b, windowBackGroundColor.a);
}
コード例 #27
0
ファイル: Painter.cpp プロジェクト: Mandarancio/Vector
void Painter::paintPolygon(Polygon pol) {
	if (status.fill.alpha() > 0) {
		Polygon * s = pol.transformPolygon(*status.transformation);
		std::vector<Line> lines = s->lines();
		SDL_Point p;
		Line l(0, 0, 0, 0);

		int x0 = s->getBoundingBox().x;
		int y0 = s->getBoundingBox().y;
		int h0 = s->getBoundingBox().h;
		int w0 = s->getBoundingBox().w;
		std::vector<int> inters;

		SDL_SetRenderDrawColor(renderer, status.fill.red(), status.fill.green(),
				status.fill.blue(), status.fill.alpha());
		if (w0 > h0) {
			for (int y = y0; y < y0 + h0; y++) {
				inters.clear();
				l = Line(x0, y, x0 + w0, y);
				if (s->contains(x0, y)) {
					inters.push_back(x0);
				}
				for (unsigned int i = 0; i < lines.size(); i++) {
					if (lines[i].intersectLine(l, p)) {
						if (std::find(inters.begin(), inters.end(), p.x)
								== inters.end()) {
							inters.push_back(p.x);
						}
					}
				}
				if (inters.size() > 0) {
					std::sort(inters.begin(), inters.end());
					for (unsigned int i = 0; i < inters.size() - 1; i += 2) {
						SDL_RenderDrawLine(renderer, inters[i], y,
								inters[i + 1], y);
					}
					if (inters.size() % 2 != 0) {
						SDL_RenderDrawPoint(renderer, inters.back(), y);
					}
				}
			}
		} else {
			for (int x = x0; x < x0 + w0; x++) {
				inters.clear();
				l = Line(x, y0, x, y0 + h0);
				if (s->contains(x, y0)) {
					inters.push_back(y0);
				}
				for (unsigned int i = 0; i < lines.size(); i++) {
					if (lines[i].intersectLine(l, p)) {
						if (std::find(inters.begin(), inters.end(), p.y)
								== inters.end()) {
							inters.push_back(p.y);
						}
					}
				}
				if (inters.size() > 0) {
					std::sort(inters.begin(), inters.end());
					for (unsigned int i = 0; i < inters.size() - 1; i += 2) {
						SDL_RenderDrawLine(renderer, x, inters[i], x,
								inters[i + 1]);
					}
					if (inters.size() % 2 != 0) {
						SDL_RenderDrawPoint(renderer, x, inters.back());
					}
				}
			}
		}
	}
	for (unsigned int i = 0; i < pol.lines().size(); i++) {
		paintLine(pol.lines()[i]);
	}
}
コード例 #28
0
int main(int, char**)
{


    // inicia SDL
     SDL_Init(SDL_INIT_VIDEO);
	if (SDL_Init(SDL_INIT_VIDEO) != 0){
		std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
		return 1;
	}

	// crea la ventana
    SDL_Window *win = SDL_CreateWindow("Gestor de eventos de teclado y raton", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
    if (win == nullptr){
        std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    // crea el "renderer"
    SDL_Renderer *ren = SDL_CreateRenderer(win, -1, 1);
    if (ren == nullptr){
        cleanup(win); // SDL_DestroyWindow(win);
        std::cerr << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    std::string imagePath1 = "panel3.bmp";


    SDL_Surface *panel = SDL_LoadBMP(imagePath1.c_str());

    //SDL_Surface *screen = SDL_CreateRGBSurface(0, 640, 480, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
    SDL_Texture *texPanel = SDL_CreateTextureFromSurface(ren, panel);

    //SDL_Texture * tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 480);

        // Select the color for drawing. It is set to red here.
        SDL_SetRenderDrawColor(ren, 0, 204, 255, 255);
        SDL_RenderClear(ren);

               //SDL_DrawLine(screen, 20, 10, 70, 90, 255, 0, 0, 255);
        SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);

         SDL_RenderDrawLine(ren, 10, 10, 200, 200);

        // Up until now everything was drawn behind the scenes.
        // This will show the new, red contents of the window.

        SDL_RenderCopy(ren, texPanel, NULL, NULL);

        SDL_RenderPresent(ren);

	//Our event structure
	SDL_Event e;
	//For tracking if we want to quit
	bool quit = false;

	SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);
    ///Variables
    int i=0;
    bool pinta=false;
    ///Variables END
	while (!quit){


		//Read any events that occurred, for now we'll just quit if any event occurs
		while (SDL_PollEvent(&e)){
			//If user closes the window
			if (e.type == SDL_QUIT){
				quit = true;
			}
			//If user presses any key
			if (e.type == SDL_KEYDOWN) {
                SDL_Keycode key = e.key.keysym.sym;
                std::cout << "Tecla pulsada: " << SDL_GetKeyName(key)
                          << std::endl;
                if (key == SDLK_ESCAPE){
                    quit = true;
                }
			}




			//If user clicks the mouse
			if (e.type == SDL_MOUSEBUTTONDOWN){
				std::cout << "Boton de raton pulsado en X = "
                          << e.button.x << "\tY = " << e.button.y << std::endl;
			               //SDL_DrawLine(screen, 20, 10, 70, 90, 255, 0, 0, 255);
            //APAÑAR EL BUCLE CON LOS 2 CLICKS DE RATON     <<<GUILLER>>>       APAÑADO ;)

            //BOTON DE CERRAR
            if ((e.button.x > 708 && e.button.x < 800) & (e.button.y > 0 && e.button.y < 55)){
                quit = true;
            }
            //BOTON CREAR LINEA
            if ((e.button.x > 708 && e.button.x < 800) & (e.button.y > 115 && e.button.y < 168)){
                if (pinta == false)
                    pinta=true;
                else
                    pinta=false;

            }
            if ((pinta == true) & (e.button.x > 12 && e.button.x < 692) & (e.button.y > 77 && e.button.y < 588)){

            int x1;
            int y1;
            int x2;
            int y2;

            if (i==0){
                std::cout <<" 1 ";
                x1 = e.button.x;
                y1 = e.button.y;
                }
                if (i==1){
                std::cout <<" 2 ";
                x2 = e.button.x;
                y2 = e.button.y;
                SDL_RenderDrawLine(ren, x1, y1, x2, y2);
                }
                i++;
                if (i==2)
                    i=0;
            }


       /*
        for(int i=0; i<2; i++){
         x1 = e.button.x;
         y1 = e.button.y;
        std::cout << "e1 = "<< e.button.x<< std::endl;
        if (x1!=0){
         x2 = e.button.x;
         y2 = e.button.y;
        std::cout << "e2 = "<< e.button.x << std::endl;
         i++;
            }
        }*/



         }

		}

        //Update the screen
        SDL_RenderPresent(ren);
        //Take a quick break after all that hard work
	}






    // limpia y termina
    cleanup(ren, win); // SDL_DestroyTexture(tex); SDL_DestroyRenderer(ren); SDL_DestroyWindow(win);
	std::cout << "Todo correcto. Bye!" << std::endl;
	SDL_Quit();

	return 0;
}
コード例 #29
0
void TextureRenderer::drawLine(int x1, int y1, int x2, int y2)
{
    SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
}
コード例 #30
0
void mouse::run(SDL_Renderer *renderer, SDL_Event *event) {
    switch(event->type) {
    case SDL_MOUSEBUTTONDOWN:
        printf("left mouse down\n");
        switch(event->button.button) {
        case SDL_BUTTON_LEFT:
            printf("Mouse button %d pressed at (%d,%d)\n",event->button.button, event->button.x, event->button.y);
            printf("Mouse button pressed \n");
            printf("Left Mouse Button Pressed\n");

            if(m_left_mouse_down == false) {
                SDL_SetRenderDrawColor(renderer,255,0,0,0);
                m_left_mouse_down = true;
                m_mouse_draw_initial_x = event->button.x;
                m_mouse_draw_initial_y = event->button.y;
            } else {
                m_mouse_draw_final_x = event->motion.x;
                m_mouse_draw_final_y = event->motion.y;
                SDL_SetRenderDrawColor(renderer,255,0,0,0);
                SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x,m_mouse_draw_initial_y,event->motion.x,event->motion.y);
                SDL_SetRenderDrawColor(renderer,0,255,0,0);
                SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x, m_mouse_draw_initial_y, event->motion.x, m_mouse_draw_initial_y);
                SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x, m_mouse_draw_initial_y, m_mouse_draw_initial_x, event->motion.y);
                SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x, event->motion.y, event->motion.x, event->motion.y);
                SDL_RenderDrawLine(renderer,event->motion.x, m_mouse_draw_initial_y, event->motion.x, event->motion.y);
            }

            break;
        }

        break;

    case SDL_MOUSEBUTTONUP:
        switch(event->button.button) {
        case SDL_BUTTON_LEFT:
            printf("left mouse up\n");
            m_left_mouse_down = false;

            break;
        }

        break;

    case SDL_MOUSEMOTION:
        printf("Mouse moved by %d,%d to (%d,%d)\n",event->motion.xrel, event->motion.yrel,event->motion.x, event->motion.x);
        if(m_left_mouse_down) {
            // to be used when checking if something is in the bounding box/slection box
            m_mouse_draw_final_x = event->motion.x;
            m_mouse_draw_final_y = event->motion.y;

            SDL_SetRenderDrawColor(renderer,255,0,0,0);
            SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x,m_mouse_draw_initial_y,event->motion.x,event->motion.y);

            //line going from top left to top right of box
            SDL_SetRenderDrawColor(renderer,0,255,0,0);
            SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x, m_mouse_draw_initial_y, event->motion.x, m_mouse_draw_initial_y);
            //line going from top left to botton left
            SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x, m_mouse_draw_initial_y, m_mouse_draw_initial_x, event->motion.y);
            //line going from bottom left to bottom right
            SDL_RenderDrawLine(renderer,m_mouse_draw_initial_x, event->motion.y, event->motion.x, event->motion.y);
            //line going from top right to bottom right
            SDL_RenderDrawLine(renderer,event->motion.x, m_mouse_draw_initial_y, event->motion.x, event->motion.y);

        }

        break;
    }
}