示例#1
0
		int LOBJECT_METHOD(getRenderDrawColor, SDL_Renderer * renderer){
			Uint8 r,g,b,a;
			if (SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a)==0){
				state.new_table();
				state.set_field("r", (const int)r);
				state.set_field("g", (const int)g);
				state.set_field("b", (const int)b);
				state.set_field("a", (const int)a);
				return 1;
			}else{
				return 0;
			}

		}
示例#2
0
void GW_PlatformSDL::draw_touch(const char* log, GW_Platform_Point* touch) {
    SDL_Rect rect;
    rect.x=touch->x;
    rect.y=touch->y;
    rect.w=2;
    rect.h=2;

    unsigned char r, g, b, a;
    SDL_GetRenderDrawColor(renderer_, &r, &g, &b, &a);
    SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255);

    SDL_RenderFillRect(renderer_, &rect);
    GWDBG_FVOUTPUT(log, touch->x, touch->y);

    SDL_SetRenderDrawColor(renderer_, r, g, b, a);
}
示例#3
0
void SpriteBatch::sbFillScreen(SDL_Color *color)
{
    if(!drawingInProgress)
        throw std::runtime_error("sbBegin must be called.");

    SDL_Color oldColor;

    SDL_GetRenderDrawColor(__renderer, &oldColor.r, &oldColor.g, &oldColor.b, &oldColor.a);
    SDL_SetRenderDrawColor(__renderer, color->r, color->g, color->g, color->b);

    SDL_Rect rect;
    rect.x = 0;
    rect.y = 0;
    rect.w = 800;
    rect.h = 600;
    SDL_RenderFillRect(__renderer, &rect);
    SDL_RenderDrawRect(__renderer, &rect);
    SDL_SetRenderDrawColor(__renderer, (oldColor.r), (oldColor.g), (oldColor.b), (oldColor.a));
}
示例#4
0
void paintBackground(GraphicsData *graphicsData, int r, int g, int b){
	/* We don't need to know alpha, because the alpha for a background
	   will always be 1 (it doesn't make sense otherwise) */
	/* I don't know if keeping the colours from before is strictly necessary, but
       I'm putting it in anyway! */
	Uint8 o_r,o_g,o_b,o_a;
	SDL_Rect rect;

	rect.x = 0;
	rect.y = 0;
	/* This reads the width and height of the window into the space shown by
	   the pointers */
	SDL_GetWindowSize(graphicsData->window,&rect.w,&rect.h);

	SDL_GetRenderDrawColor(graphicsData->renderer,&o_r,&o_g,&o_b,&o_a);
	SDL_SetRenderDrawColor(graphicsData->renderer,r,g,b,SDL_ALPHA_OPAQUE);
	SDL_RenderFillRect(graphicsData->renderer, &rect);
    	SDL_SetRenderDrawColor(graphicsData->renderer,o_r,o_g,o_b,o_a);
}
示例#5
0
文件: CBall.cpp 项目: RKJokela/rjPong
/*
IDEA FOR BALL DRAWING:
SINCE EVERYTHING IS DRAWN WITH RECTS:
CREATE A VENEER FOR THE RENDERFILLRECT FUNTIONS THAT STORES THE RECT INTO A LIST ON EACH MAIN DRAW PASS
ONCE YOU HAVE THE LIST (I.E. MUST DRAW BALL LAST), USE THAT LIST OF RECTS TO INTERSECT THE BALL AND INVERT COLOR IN THE INTERSECTED AREA.
*/
void CBall::draw(SDL_Renderer* r, const std::vector<SDL_Rect> &drawnBoxes) {
	// draw ball
	CRectEntity::draw(r);
	// draw inverted over intersects
	std::vector<SDL_Rect> intersects;
	for (auto box : drawnBoxes) {
		SDL_Rect intersection;
		if (SDL_IntersectRect(&_boundingBox, &box, &intersection))
			intersects.push_back(intersection);
	}
	if (!intersects.empty()) {
		// keep old color
		SDL_Color save;
		SDL_GetRenderDrawColor(r, &save.r, &save.g, &save.b, &save.a);
		// draw colored rectangle
		SDL_SetRenderDrawColor(r, 255 - _drawColor.r, 255 - _drawColor.g, 255 - _drawColor.b, SDL_ALPHA_OPAQUE);
		SDL_RenderFillRects(r, &intersects[0], intersects.size());
		// reset color
		SDL_SetRenderDrawColor(r, save.r, save.g, save.b, save.a);
	}
}
示例#6
0
void GameInfo::HealthBar(int x, int y, int w, int h, float Percent, SDL_Color FGColor, SDL_Color BGColor, SDL_Renderer* pRender, int player) {
	   Percent = Percent > 1.f ? 1.f : Percent < 0.f ? 0.f : Percent;
	   SDL_Color old;
	   SDL_GetRenderDrawColor(pRender, &old.r, &old.g, &old.g, &old.a);
	   SDL_Rect bgrect = { x, y, w, h };
	   SDL_SetRenderDrawColor(pRender, BGColor.r, BGColor.g, BGColor.b, BGColor.a);
	   SDL_SetRenderDrawBlendMode(pRender, SDL_BLENDMODE_BLEND);
	   SDL_RenderFillRect(pRender, &bgrect);
	   SDL_SetRenderDrawColor(pRender, FGColor.r, FGColor.g, FGColor.b, FGColor.a);
	   int pw = (int)((float)w * Percent);
	   int px;
	   if (player == 0) {
		   px = x;
	   } else {
		   px = x + (w - pw);
	   }

	   SDL_Rect fgrect = { px, y, pw, h };
	   SDL_RenderFillRect(pRender, &fgrect);
       SDL_SetRenderDrawColor( pRender, 227, 188, 119, 0xFF );
       SDL_RenderDrawRect( pRender, &bgrect );
	   SDL_SetRenderDrawColor(pRender, 0x00, 0x00, 0x00, 0xFF );
}
示例#7
0
void Window::getDrawColour( Graphics::Colour& colour ) const noexcept
{
    SDL_GetRenderDrawColor( m_wimpl->renderer, &colour.r, &colour.g, &colour.b, &colour.a );
}
示例#8
0
    Color Renderer::getDrawColor() const {
        Color col;
        SDL_GetRenderDrawColor(_renderer, &col.red, &col.green, &col.blue, &col.alpha);

        return col;
    }
示例#9
0
/**
 * Swap the renderer color by the provided color.
 *
 * The color previously in the renderer will be copied to the pointer.
 */
void swap_color(Renderer *renderer, SDL_Color *color) {
  SDL_Color swap;
  SDL_GetRenderDrawColor(renderer, &swap.r, &swap.g, &swap.b, &swap.a);
  SDL_SetRenderDrawColor(renderer, color->r, color->g, color->b, color->a);
  *color = swap;
}
示例#10
0
SDL_Color Renderer::getColor()  {
	SDL_Color c;
	SDL_GetRenderDrawColor(m_renderer,&c.r,&c.g,&c.b,&c.a);
	return c;
}
示例#11
0
void ScrollableContainer::draw(SDL_Renderer * renderer)
{
	if(isVisible())
	{
		if(renderTarget == NULL)
		{
			renderTarget = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_UNKNOWN,SDL_TEXTUREACCESS_TARGET,getWidth(),getHeight());
		}

		if(childAreaTexture == nullptr)
		{
			childAreaTexture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_UNKNOWN,SDL_TEXTUREACCESS_TARGET,childArea.w,childArea.h);
		}

		SDL_Texture * callerTexture = SDL_GetRenderTarget(renderer);

		SDL_SetRenderTarget(renderer,renderTarget);

		SDL_SetRenderDrawColor(renderer,bgColor.r,bgColor.g,bgColor.b,bgColor.a);

		SDL_RenderClear(renderer);


		SDL_SetRenderTarget(renderer,childAreaTexture);
		SDL_RenderClear(renderer);


		for(it = widgets.begin();it != widgets.end();++it)
		{
			(*it)->draw(renderer);
		}

		SDL_Color prevColor;

		SDL_SetRenderTarget(renderer,renderTarget);
		SDL_RenderCopy(renderer,childAreaTexture,nullptr,&childArea);

		if(vScroll || hScroll)
		{
			SDL_GetRenderDrawColor(renderer,&prevColor.r,&prevColor.g,&prevColor.b,&prevColor.a);

			SDL_SetRenderDrawColor(renderer,scrollColor.r,scrollColor.g,scrollColor.b,scrollColor.a);
			if(vScroll)
			{
				SDL_RenderFillRect(renderer,&vScrollRect);
			}

			if(hScroll)
			{
				SDL_RenderFillRect(renderer,&hScrollRect);
			}

			SDL_SetRenderDrawColor(renderer,prevColor.r,prevColor.g,prevColor.b,prevColor.a);
		}

		if(borderVisible)
		{
			SDL_GetRenderDrawColor(renderer,&prevColor.r,&prevColor.g,&prevColor.b,&prevColor.a);

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

			SDL_RenderDrawRect(renderer,&childArea);

			SDL_SetRenderDrawColor(renderer,prevColor.r,prevColor.g,prevColor.b,prevColor.a);
		}
		

		SDL_SetRenderTarget(renderer,callerTexture);

		SDL_RenderCopy(renderer,renderTarget,NULL,&getArea());
		callerTexture = NULL;
	}
}