void ConfigurationMenu::RenderMenu( SDL_Surface *surface )
{
	if ( visibility )
	{
		boxRGBA( surface, 800 / 2 - 250, 480 / 2 - 150, 800 / 2 + 250, 480 / 2 + 150, 0, 0, 0, 255 );
		rectangleRGBA( surface, 800 / 2 - 250, 480 / 2 - 150, 800 / 2 + 250, 480 / 2 + 150, 255, 255, 255, 255 );
		rectangleRGBA( surface, 800 / 2 - 250 + 1, 480 / 2 - 150 + 1, 800 / 2 + 250 - 1, 480 / 2 + 150 - 1, 255, 255, 255, 255 );
		aalineRGBA( surface, 800 / 2 - 225, 480 / 2 - 100, 800 / 2 + 225, 480 / 2 - 100, 255, 255, 255, 200 );
		dialogTitleLabel.Render( surface );
		traceLinesLabel.Render( surface );
		traceLineBodyLabel.Render( surface );
		traceLineSledLabel.Render( surface );
		traceLineHatLabel.Render( surface );
		traceLineHeadLabel.Render( surface );
		traceLineArmLabel.Render( surface );
		traceLineLegLabel.Render( surface );

		traceLineBodyRadio.Render( surface );
		traceLineSledRadio.Render( surface );
		traceLineHatRadio.Render( surface );
		traceLineHeadRadio.Render( surface );
		traceLineArmRadio.Render( surface );
		traceLineLegRadio.Render( surface );

		lineSnapLabel.Render( surface );
		lineSnapRadio.Render( surface );
	}
}
int _progressThread( void *data )
{
	ResearchEngine* researchEngine = (ResearchEngine*) data;
	int screenWidth = 1000;
	int screenHeight = 100;
	int r = researchEngine->getCurrentResearch();
	int e = researchEngine->getCurrentEpoch();

	SDL_Init( SDL_INIT_VIDEO );
	SDL_Surface* screen = SDL_SetVideoMode( screenWidth, screenHeight, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
	SDL_WM_SetCaption( "Reasearch progress", 0 );
	SDL_Event event;

	bool quit = false;
    while( researchEngine->isRunning() && !quit)
    {
    	if(r != researchEngine->getCurrentResearch() || e != researchEngine->getCurrentEpoch()){
    		r = researchEngine->getCurrentResearch();
    		e = researchEngine->getCurrentEpoch();

    		int barHeight = 30;
    		int offset1 = 5;
    		int offset2 = 50;
    		int start = 5;
    		float barWidth = (float)screenWidth - 5.0f;
    		float progressA = barWidth * ((float)r / (float)researchEngine->getResearches());
    		float progressB = barWidth * ((float)e / (float)researchEngine->getEpochs());

    		boxRGBA(screen, 0, 0, screenWidth, screenHeight, 255, 255, 255, 255);
    		rectangleRGBA(screen, start, offset1, barWidth, barHeight + offset1, 0, 0, 255, 255);
    		boxRGBA(screen, start, offset1, progressA + start, barHeight + offset1, 0, 0, 255, 255);
    		rectangleRGBA(screen, start, offset2, barWidth, barHeight + offset2, 0, 0, 255, 255);
    		boxRGBA(screen, start, offset2, progressB + start, barHeight + offset2, 0, 0, 255, 255);
    		SDL_Flip(screen);
    	}

		if (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT) {
				quit = true;
			}
		}
    }

    SDL_Quit();

    return 0;
}
Exemple #3
0
void map_show() {
  if (map_loaded == TRUE) {
    SDL_Rect offset;
    int row, col, x, y;
    y = map_rect.y;
    for (row = 0; row < map_rows; row++) {
      x = map_rect.x;
      for (col = 0; col < map_cols; col++) {
        offset.x = x;
        offset.y = y;
        if (map[row][col] > -1) {
          SDL_BlitSurface(tiles[map[row][col]].tile, NULL, screen, &offset);
        }
        x += TILES_SIZE;
      }
      y += TILES_SIZE;
    }
  }

  if (map_show_grid == TRUE) {
    int row, col, x, y;
    y = map_rect.y;
    for (row = 0; row < map_rows; row++) {
      x = map_rect.x;
      lineRGBA(
        screen, x, y, x + map_rect.w, y,
        255, 255, 255, 255
      );
      for (col = 0; col < map_cols; col++) {
        lineRGBA(
          screen, x, y, x, y + map_rect.h - row * TILES_SIZE,
          255, 255, 255, 255
        );
        x += TILES_SIZE;
      }
      lineRGBA(
        screen, x, y, x, y + map_rect.h - row * TILES_SIZE,
        255, 255, 255, 255
      );
      y += TILES_SIZE;
    }
    x = map_rect.x;
    lineRGBA(
      screen, x, y, x + map_rect.w, y,
      255, 255, 255, 255
    );
  }

  if (map_tile_selection.col > -1 && map_tile_selection.row > -1) {
    rectangleRGBA(
      screen,
      map_rect.x + map_tile_selection.col * TILES_SIZE,
      map_rect.y + map_tile_selection.row * TILES_SIZE,
      map_rect.x + map_tile_selection.col * TILES_SIZE + TILES_SIZE,
      map_rect.y + map_tile_selection.row * TILES_SIZE + TILES_SIZE,
      255, 0, 0, 255
    );
  }
}
Exemple #4
0
void Rectangulo(int x1, int y1, int x2, int y2,
              unsigned char r, unsigned char g, unsigned char b, GRF_Imagen img)
{
    GRF_Imagen ptr = ((img==0) ? ventana : img);
    rectangleRGBA(ptr, x1, y1, x2, y2, r, g, b, 255);
    if (img==0 && dibujo_activo) 
      SDL_UpdateRect(ptr, min(x1,x2), min(y1,y2), abs(x1-x2)+1, abs(y1-y2)+1);
}
Exemple #5
0
void DrawMsg(char Msg[]){
	boxRGBA(screen,350,400,439,409,16,16,16,0xFF);
	rectangleRGBA(screen,350,400,439,409,32,32,32,0xFF);
	if (Msg[strlen(Msg)-1]!='!')
		stringRGBA(screen,351,401,Msg,200,200,200,0xFF);
	else
		stringRGBA(screen,351,401,Msg,250,50,50,0xFF);
	SDL_UpdateRect(screen,350,400,90,10);
}
Exemple #6
0
void DrawTxtMenu(char Mnu[10][20]){
int I,L=0;
	boxRGBA(screen,0,400,419,409,64,64,64,0xFF);
	rectangleRGBA(screen,0,400,419,409,32,32,32,0xFF);
	for (I=0;(I<10)&&(Mnu[I][0]!='\0');I++){
		stringRGBA(screen,2+L*8,402,Mnu[I],250,250,250,0xFF);
		L+=strlen(Mnu[I]);
	}
	SDL_UpdateRect(screen,0,400,400,10);
}
// *********************************************************************************
// *****	Erase_Data														********
// *****	Erase the old data 												********
// *****	(r) void														********
// *****	(1) Struct_Coordinates *:  coordinate of left corner of box		********
// *****	(2) Struct_Coordinates *:  coordinate of left corner of box		********
// *****	(3) SDL_Color;  background color								********
// *********************************************************************************
void Erase_Data(SDL_Surface* p_DS, Struct_Coordinates s, SDL_Color v_bg, int v_border)
{
	// ***** Erase old data by covering up with box *****
boxRGBA(p_DS,  s.x1, s.y1, s.x2, s.y2, v_bg.r, v_bg.g, v_bg.b,255);	

	// ***** Box Border *****
if(v_border)
rectangleRGBA(p_DS, s.x1, s.y1, s.x2, s.y2, 0,0,255,255);
return;
}
Exemple #8
0
int BEE::draw_rectangle(int x, int y, int w, int h, bool is_filled, bool is_hud) {
	if (!is_hud) {
		convert_view_coords(x, y);
	}
	SDL_Rect rect = {x, y, w, h};
	if (is_filled) {
		return boxRGBA(renderer, x+w, y, x, y+h, color->r, color->g, color->b, color->a);
	} else {
		return rectangleRGBA(renderer, x+w, y, x, y+h, color->r, color->g, color->b, color->a);
	}
}
Exemple #9
0
void ScreenMap::showFieldSelection() {
  if (fieldSelection.column > -1 && fieldSelection.row > -1) {
    rectangleRGBA(
      surface,
      rect.x + fieldSelection.column * imageSize,
      rect.y + fieldSelection.row * imageSize,
      rect.x + fieldSelection.column * imageSize + imageSize,
      rect.y + fieldSelection.row * imageSize + imageSize,
      255, 0, 0, 255
    );
  }
}
Exemple #10
0
void colliders_debug_draw()
{
	for (int i = 0; i < MAX_COLLIDERS; ++i) {
		if (colliders[i]) {
			int x1 = colliders[i]->bounds.x;
			int y1 = colliders[i]->bounds.y;
			int x2 = x1 + colliders[i]->bounds.w;
			int y2 = y1 + colliders[i]->bounds.h;
			rectangleRGBA(globals.screen, x1, y1, x2, y2, 255, 0, 0, 255);
		}
	}
}
void Button::Draw()
{
	if(buttonType == IMAGE)
	{
		DrawSurface(collisionBox.x, collisionBox.y, content, mainScreen);
	}
	else if(buttonType == TEXT)
	{
		if(!mousedOver)
		{
			SDL_FillRect(mainScreen, &collisionBox, SDL_MapRGB(mainScreen->format, bgClr.r, bgClr.g, bgClr.b));
			DrawSurface(collisionBox.x, collisionBox.y, content, mainScreen);
			rectangleRGBA(mainScreen, collisionBox.x  , collisionBox.y, collisionBox.x + collisionBox.w, collisionBox.y + collisionBox.h, borderClr.r, borderClr.g, borderClr.b, 255);
		}
		else if(mousedOver)
		{
			SDL_FillRect(mainScreen, &collisionBox, SDL_MapRGB(mainScreen->format, hoverClr.r, hoverClr.g, hoverClr.b));
			DrawSurface(collisionBox.x  , collisionBox.y, content, mainScreen);
			rectangleRGBA(mainScreen, collisionBox.x, collisionBox.y, collisionBox.x + collisionBox.w, collisionBox.y + collisionBox.h, borderClr.r, borderClr.g, borderClr.b, 255);
		}
	}
}
Exemple #12
0
	void Image::draw_rectangle(Color c, float x, float y, float width, float height, bool filled)
	{
		SDL_Surface* aux = SDL_CreateRGBSurface(SDL_SRCALPHA, width, height, 32, 0, 0, 0, 0);
		if(filled)
			boxRGBA(aux, 0, 0, width, height, c.r, c.g, c.b, SDL_ALPHA_OPAQUE);

		else
			rectangleRGBA(aux, 0, 0, width, height, c.r, c.g, c.b, SDL_ALPHA_OPAQUE);

		dstrect.x = x; dstrect.y = y;
		SDL_BlitSurface(aux, null, GameEngine::display->implementation->sdlDisplaySurface, &dstrect);
		SDL_FreeSurface(aux);
	}
static void drawDIPS(SDL_Surface* surf, state* s, unsigned char r, unsigned char g, unsigned char b, unsigned char a, double ratioPixels) {

    double distance = (fabs(s->xPosition2 - s->xPosition1) * ratioPixels) - 14;
    double inter = (distance) / (double)NB_SPRING;
    unsigned int i = 1;
    int sign = 1;

    double x1 = (screenWidth / 4.0) + (s->xPosition1 * ratioPixels);
    double y1 = screenHeight / 2.0;
    double x2 = x1 - (ratioPixels * sin(M_PIl - s->angularPosition1) * 2.0 * parameters[2]);
    double y2 = y1 + (ratioPixels * cos(M_PIl - s->angularPosition1) * 2.0 * parameters[2]);

    aalineRGBA(surf, x1, y1, x2, y2, r, g, b, a);
    filledCircleRGBA(surf, x1, y1, 5, r, g, b, a);
    filledCircleRGBA(surf, x2, y2, 5, r, g, b, a);
    rectangleRGBA(surf, x1 - 7, y1 - 7, x1 + 7, y1 + 7, r, g, b, a);

    x1 = (screenWidth / 4.0) + (s->xPosition2 * ratioPixels);
    y1 = (screenHeight / 2.0);
    x2 = x1 - (ratioPixels * sin(M_PIl - s->angularPosition2) * 2.0 * parameters[3]);
    y2 = y1 + (ratioPixels * cos(M_PIl - s->angularPosition2) * 2.0 * parameters[3]);

    aalineRGBA(surf, x1, y1, x2, y2, r, g, b, a);
    filledCircleRGBA(surf, x1, y1, 5, r, g, b, a);
    filledCircleRGBA(surf, x2, y2, 5, r, g, b, a);
    rectangleRGBA(surf, x1 - 7, y1 - 7, x1 + 7, y1 + 7, r, g, b, a);

    x1 = (screenWidth / 4.0) + (s->xPosition1 * ratioPixels) + 7;
    y1 = (screenHeight / 2.0);
    for(; i <= NB_SPRING; i++) {
        if(sign > 0)
            sign = -7;
        else
            sign = 7;
        aalineRGBA(surf, x1+((i-1)*inter), y1+sign, x1+(i*inter), y1-sign, r, g, b, a);
    }

}
Exemple #14
0
CAMLprim value ml_rectangleRGBA(value dst,value p1,value p2, value col,value alpha)
{
  SDL_Surface *sur= SDL_SURFACE(dst);
  SDL_Rect rect1, rect2;
  SDL_Color c;
  int r;

  SDLRect_of_value(&rect1,p1);
  SDLRect_of_value(&rect2,p2);
  SDLColor_of_value(&c,col);
  r=rectangleRGBA(sur,rect1.x,rect1.y,rect2.x,rect2.y,c.r,c.g,c.b, Int_val(alpha));

  return Val_bool(r);
}
Exemple #15
0
void DrawMenu(T_E_Sel Mnu){
int I;
	boxRGBA(screen,Mnu.X,0,Mnu.X+19,399,64,64,64,0xFF);
	boxRGBA(screen,Mnu.X+19,0,Mnu.X+19,399,32,32,32,0xFF);

	rectangleRGBA(screen,Mnu.X,0,Mnu.X+19,19,32,32,32,0xFF);
	lineRGBA(screen,Mnu.X+5,5,Mnu.X+10,0,200,200,200,0xFF);
	lineRGBA(screen,Mnu.X+10,0,Mnu.X+15,5,200,200,200,0xFF);
	stringRGBA(screen,Mnu.X+1,10,Mnu.Name,200,200,200,0xFF);

	rectangleRGBA(screen,Mnu.X,380,Mnu.X+19,399,32,32,32,0xFF);
	lineRGBA(screen,Mnu.X+5,395,Mnu.X+10,399,200,200,200,0xFF);
	lineRGBA(screen,Mnu.X+10,399,Mnu.X+15,395,200,200,200,0xFF);
	
	for (I=0;(I<18)&&(Mnu.Top+I<Mnu.L);I++)
		DrawSpr(Spr[Mnu.E[Mnu.Top+I].Spr].img,screen,Mnu.X,20+I*20);

	if ((Mnu.Akt>=Mnu.Top)&&(Mnu.Akt<Mnu.Top+18)){
		rectangleRGBA(screen,Mnu.X+1,21+(Mnu.Akt-Mnu.Top)*20,Mnu.X+18,19+(Mnu.Akt-Mnu.Top)*20+19,0,0,0,128);
		rectangleRGBA(screen,Mnu.X,20+(Mnu.Akt-Mnu.Top)*20,Mnu.X+19,20+(Mnu.Akt-Mnu.Top)*20+19,255,255,255,128);
	}

	SDL_UpdateRect(screen,Mnu.X,0,20,400);
}
Exemple #16
0
int main()
{
    SDL_Init(SDL_INIT_VIDEO);

    srand(time(NULL));

    SDL_Surface *screen = SDL_SetVideoMode(800,600,32,SDL_HWSURFACE|SDL_DOUBLEBUF);

    if (screen == NULL) return -1;

    atexit(SDL_Quit);

    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0x38, 0x1a, 0x0e));

    printf("%x\n",SDL_MapRGBA(screen->format, 0x61, 0xc6, 0xd0, 0xff));

    boxRGBA(screen, 100, 100, 500, 500, 0x61, 0xc6, 0xd0, 0xff);

    for (int i = 0; i<2; i++) {
        rectangleRGBA(screen, 100+i,100+i, 500-i, 500-i, 0x00,0x00,0x00,0xdd-(rand()%3));
    }

    for (int i = 0; i<30; i++) {
        lineColor(screen, 100+i, 100, 100+i, 500, 0x00000096 -(5*i));
    }

    for (int i = 0; i<30; i++) {
        lineColor(screen, 100,100+i,500, 100+i, 0x00000096 -(5*i));
    }

    for (int i = 0; i<30; i++) {
        lineColor(screen, 100, 500-i,500, 500-i, 0x00000096 -(5*i));
    }

    for (int i = 0; i<30; i++) {
        lineColor(screen, 500-i,100,500-i, 500, 0x00000096 -(5*i));
    }
    
    SDL_Flip(screen);

    getchar();
    return 0;
}
Exemple #17
0
	void Image::drawRectangle(Color c, float x, float y, float width, float height, bool filled)
	{
		checkInit();
		x = round(x);
		y = round(y);
		width = round(width);
		height = round(height);

		SDL_Surface* aux = SDL_CreateRGBSurface(SDL_SRCALPHA, width, height, 32, 0, 0, 0, 0);

		if(filled)
			boxRGBA(aux, 0, 0, width, height, c.r, c.g, c.b, SDL_ALPHA_OPAQUE);
		else
			rectangleRGBA(aux, 0, 0, width, height, c.r, c.g, c.b, SDL_ALPHA_OPAQUE);

		SDL_Rect dstrect = {(Sint16) x, (Sint16) y};
		SDL_BlitSurface(aux, null, fgeal::display->implementation->sdlDisplaySurface, &dstrect);
		SDL_FreeSurface(aux);
	}
Exemple #18
0
// Draws the button based on the state given
bool Button::draw(SDL_Surface* dest)
{
  // Ouput a box with text in the middle
  Sint16 x1 = point.x-BUFFER;
  Sint16 x2 = point.x + text->clip_rect.w+BUFFER;
  Sint16 y1 = point.y-BUFFER;
  Sint16 y2 = point.y + text->clip_rect.h+BUFFER;

  boxRGBA(dest, x1, y1, x2, y2, 255,255,255,150);
  rectangleRGBA(dest, x1, y1, x2, y2, 0,0,0,255);

  apply_surface( point.x, point.y, text, dest, NULL);

  // Might want to check if destination is valid
  //apply_surface(location.x, location.y, image, destination, &clips[state]);

  // It was succesful
  return true;
}
Exemple #19
0
// ML type: surface -> rectangle -> color -> unit
// Draws a rectangle of the given color on the surface.
EXTERNML value draw_draw_rectangle(value wScreen, value wRect, value wColor) {
    SDL_Surface *screen = (SDL_Surface *)Addr_val(wScreen);

    int x = Long_val(Field(Field(wRect, 0), 0)),
        y = Long_val(Field(Field(wRect, 0), 1)),
        w = Long_val(Field(Field(wRect, 1), 0)),
        h = Long_val(Field(Field(wRect, 1), 1)),
        colorr = Long_val(Field(wColor, 0)),
        colorg = Long_val(Field(wColor, 1)),
        colorb = Long_val(Field(wColor, 2)),
        colora = Tag_val(wColor) == RGBA ? Long_val(Field(wColor, 3)) : 255;

    if (Tag_val(wRect) == FilledRectangle) {
        boxRGBA(screen, x, y, x+w, y+h, colorr, colorg, colorb, colora);
    } else {
        rectangleRGBA(screen, x, y, x+w, y+h,
                              colorr, colorg, colorb, colora);
    }

    return Val_unit;
}
static void drawPendulum(state* s, unsigned char r, unsigned char g, unsigned char b, unsigned char a, double ratioPixels) {
	
	double x1 = (screenWidth / 4.0) + (s->xPosition * ratioPixels);
	
	double y1 = screenHeight / 2.0;
	
	double x2 = x1 - (ratioPixels * sin(M_PIl - s->angularPosition) * 2.0 * parameters[2]);
	
	double y2 = y1 + (ratioPixels * cos(M_PIl - s->angularPosition) * 2.0 * parameters[2]);
	
	aalineRGBA(screen, x1, y1, x2, y2, r, g, b, a);
	
	filledCircleRGBA(screen, x1, y1, 3, r, g, b, a);
	
	x2 = x1 - (int)(ratioPixels * sin(M_PIl - s->angularPosition) * ((2.0 * parameters[2]) + (3.0/ratioPixels)));
	
	y2 = y1 + (int)(ratioPixels * cos(M_PIl - s->angularPosition) * ((2.0 * parameters[2]) + (3.0/ratioPixels)));
	
	filledCircleRGBA(screen, x2, y2, 3, r, g, b, a);
	
	rectangleRGBA(screen, x1 - 10, y1 - 5, x1 + 10, y1 + 5, r, g, b, a);

}
Exemple #21
0
/*!
 * @breif Draw rect
 *  drawRect({x, y, width, height}, color)
 *  drawRect(x, y, width, height, color)
 */
static int32_t
luaSDL_drawRect(
	lua_State *L
)
{
	SDL_Surface *surface;
	gp_rect_t rect;
	gp_color_t color;

	surface = (SDL_Surface *) lua_touserdata(L, 1);
	if (!lua_istable(L, 2)) { /* number mode */
		rect.x = (int16_t)lua_tointeger(L, 2);
		rect.y = (int16_t)lua_tointeger(L, 3);
		rect.width = (int16_t)lua_tointeger(L, 4);
		rect.height = (int16_t)lua_tointeger(L, 5);
		color = luaSdl_toColor(L, 6);
	}
	else {
		rect = luaSdl_toRect(L, 2);
		color = luaSdl_toColor(L, 3);
	}
	rectangleRGBA(surface, rect.x + rect.width, rect.y, rect.x, rect.y + rect.height, color.red, color.green, color.blue, color.alpha);
	return 0;
}
Exemple #22
0
void gfx_rectangle(int x1, int y1, int x2, int y2)
{
	rectangleRGBA(g_gfx_screen, x1, y1, x2, y2, g_gfx_color.r, g_gfx_color.g, g_gfx_color.b, 255);
}
Exemple #23
0
TEST ( T_Intersection, RectRect, off )
{
    // init and setup a video window
    if ( SDL_WasInit(SDL_INIT_VIDEO) == 0 )
    {
        SDL_InitSubSystem( SDL_INIT_VIDEO );
    }
    if ( !SDL_SetVideoMode( 1024, 1024, 0, 0 ) )
    {
        fprintf( stderr, "Could not set video mode: %s\n", SDL_GetError() );
        SDL_Quit();
        exit( -1 );
    }

    //
    static int mouse_x = 0;
    static int mouse_y = 0;
    static bool drawing_select = false;
    static bool drawing_create = false;

    // insert nodes to the tree
    typedef ex::Array<ex::recti_t> rects_t; 
    rects_t rect_list; 
    rects_t selected_rects; 

    ex::recti_t mouse_rect;

    // main loop
    SDL_Event event;
    int quit = 0;
    while ( !quit )
    {
        // ======================================================== 
        // clear the buffer
        // ======================================================== 

        ex::uint32 color = SDL_MapRGB( SDL_GetVideoSurface()->format, 20, 20, 20 );
        SDL_FillRect( SDL_GetVideoSurface(), NULL, color );

        // ======================================================== 
        // process event
        // ======================================================== 

        while ( SDL_PollEvent(&event) )
        {

            switch ( event.type ) 
            {
                // process mouse
            case SDL_MOUSEMOTION:
                {
                    if ( drawing_create || drawing_select )
                    {
                        mouse_rect.setInScreen ( mouse_x, mouse_y, event.button.x, event.button.y );
                    }
                }
                break;
            case SDL_MOUSEBUTTONDOWN:
                {
                    mouse_x = event.button.x;
                    mouse_y = event.button.y;
                    mouse_rect.setInScreen ( mouse_x, mouse_y, event.button.x, event.button.y );

                    if ( event.button.button == SDL_BUTTON_RIGHT )
                    {
                        drawing_create = true;
                    }
                    else if ( event.button.button == SDL_BUTTON_LEFT )
                    {
                        drawing_select = true;
                    }
                }
                break;
            case SDL_MOUSEBUTTONUP:
                {
                    mouse_rect.setInScreen ( mouse_x, mouse_y, event.button.x, event.button.y );

                    if ( event.button.button == SDL_BUTTON_RIGHT )
                    {
                        rect_list.push_back(mouse_rect);
                        drawing_create = false;
                    }
                    else if ( event.button.button == SDL_BUTTON_LEFT )
                    {
                        selected_rects.clear();
                        for ( rects_t::iterator iter = rect_list.begin(); iter != rect_list.end(); ++iter )
                        {
                            if ( mouse_rect.contains(*iter) || ex::intersect::rect_rect( mouse_rect, *iter ) )
                            {
                                selected_rects.push_back(*iter);
                            }
                        }
                        drawing_select = false;
                    }
                }
                break;

            case SDL_QUIT:
                quit = 1; 
                break;

            default:
                break;
            }
        }

        // ======================================================== 
        // rendering
        // ======================================================== 

        // draw rects
        for ( rects_t::iterator iter = rect_list.begin(); iter != rect_list.end(); ++iter )
        {
            rectangleRGBA ( SDL_GetVideoSurface(), (*iter).left(), (*iter).top(), (*iter).right(), (*iter).bot(), 255, 255, 255, 255 );
        }

        // draw selected rects
        for ( rects_t::iterator iter = selected_rects.begin(); iter != selected_rects.end(); ++iter )
        {
            rectangleRGBA ( SDL_GetVideoSurface(), (*iter).left(), (*iter).top(), (*iter).right(), (*iter).bot(), 255, 0, 0, 255 );
        }

        // daw creating & selecting rect
        if ( drawing_create )
        {
            rectangleRGBA ( SDL_GetVideoSurface(), mouse_rect.left(), mouse_rect.top(), mouse_rect.right(), mouse_rect.bot(), 0, 255, 255, 255 );
        }
        if ( drawing_select )
        {
            boxRGBA ( SDL_GetVideoSurface(), mouse_rect.left(), mouse_rect.top(), mouse_rect.right(), mouse_rect.bot(), 0, 128, 255, 128 );
            rectangleRGBA ( SDL_GetVideoSurface(), mouse_rect.left(), mouse_rect.top(), mouse_rect.right(), mouse_rect.bot(), 0, 150, 255, 255 );
        }

        //
        stringRGBA ( SDL_GetVideoSurface(), 10, 10, "Test Intersection RectRect", 255, 255, 255, 255 );

        //
        SDL_Flip ( SDL_GetVideoSurface() );
    }
}
Exemple #24
0
void RenderBlock::drawRect(Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2) {
    rectangleRGBA(_renderer, x1, y1, x2, y2, _r, _g, _b, _a);
}
Exemple #25
0
int Surface::rectangle(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
	return rectangleRGBA(raw,re.x,re.y,re.x+re.w-1,re.y+re.h-1,r,g,b,a);
}
Exemple #26
0
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
	return rectangleRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
}
Exemple #27
0
/* Calls to commands created via [sdl.surface] are implemented by this
 * C command. */
static int JimSdlHandlerCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    JimSdlSurface *jss = Jim_CmdPrivData(interp);
    int option;
    static const char * const options[] = {
        "free", "flip", "pixel", "rectangle", "box", "line", "aaline",
        "circle", "aacircle", "fcircle", NULL
    };
    enum
    { OPT_FREE, OPT_FLIP, OPT_PIXEL, OPT_RECTANGLE, OPT_BOX, OPT_LINE,
        OPT_AALINE, OPT_CIRCLE, OPT_AACIRCLE, OPT_FCIRCLE
    };

    if (argc < 2) {
        Jim_WrongNumArgs(interp, 1, argv, "method ?args ...?");
        return JIM_ERR;
    }
    if (Jim_GetEnum(interp, argv[1], options, &option, "SDL surface method", JIM_ERRMSG) != JIM_OK)
        return JIM_ERR;
    if (option == OPT_PIXEL) {
        /* PIXEL */
        long x, y, red, green, blue, alpha = 255;

        if (argc != 7 && argc != 8) {
            Jim_WrongNumArgs(interp, 2, argv, "x y red green blue ?alpha?");
            return JIM_ERR;
        }
        if (Jim_GetLong(interp, argv[2], &x) != JIM_OK ||
            Jim_GetLong(interp, argv[3], &y) != JIM_OK ||
            Jim_GetLong(interp, argv[4], &red) != JIM_OK ||
            Jim_GetLong(interp, argv[5], &green) != JIM_OK ||
            Jim_GetLong(interp, argv[6], &blue) != JIM_OK) {
            return JIM_ERR;
        }
        if (argc == 8 && Jim_GetLong(interp, argv[7], &alpha) != JIM_OK)
            return JIM_ERR;
        pixelRGBA(jss->screen, x, y, red, green, blue, alpha);
        return JIM_OK;
    }
    else if (option == OPT_RECTANGLE || option == OPT_BOX ||
        option == OPT_LINE || option == OPT_AALINE) {
        /* RECTANGLE, BOX, LINE, AALINE */
        long x1, y1, x2, y2, red, green, blue, alpha = 255;

        if (argc != 9 && argc != 10) {
            Jim_WrongNumArgs(interp, 2, argv, "x y red green blue ?alpha?");
            return JIM_ERR;
        }
        if (Jim_GetLong(interp, argv[2], &x1) != JIM_OK ||
            Jim_GetLong(interp, argv[3], &y1) != JIM_OK ||
            Jim_GetLong(interp, argv[4], &x2) != JIM_OK ||
            Jim_GetLong(interp, argv[5], &y2) != JIM_OK ||
            Jim_GetLong(interp, argv[6], &red) != JIM_OK ||
            Jim_GetLong(interp, argv[7], &green) != JIM_OK ||
            Jim_GetLong(interp, argv[8], &blue) != JIM_OK) {
            return JIM_ERR;
        }
        if (argc == 10 && Jim_GetLong(interp, argv[9], &alpha) != JIM_OK)
            return JIM_ERR;
        switch (option) {
            case OPT_RECTANGLE:
                rectangleRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
            case OPT_BOX:
                boxRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
            case OPT_LINE:
                lineRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
            case OPT_AALINE:
                aalineRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
                break;
        }
        return JIM_OK;
    }
    else if (option == OPT_CIRCLE || option == OPT_AACIRCLE || option == OPT_FCIRCLE) {
        /* CIRCLE, AACIRCLE, FCIRCLE */
        long x, y, radius, red, green, blue, alpha = 255;

        if (argc != 8 && argc != 9) {
            Jim_WrongNumArgs(interp, 2, argv, "x y radius red green blue ?alpha?");
            return JIM_ERR;
        }
        if (Jim_GetLong(interp, argv[2], &x) != JIM_OK ||
            Jim_GetLong(interp, argv[3], &y) != JIM_OK ||
            Jim_GetLong(interp, argv[4], &radius) != JIM_OK ||
            Jim_GetLong(interp, argv[5], &red) != JIM_OK ||
            Jim_GetLong(interp, argv[6], &green) != JIM_OK ||
            Jim_GetLong(interp, argv[7], &blue) != JIM_OK) {
            return JIM_ERR;
        }
        if (argc == 9 && Jim_GetLong(interp, argv[8], &alpha) != JIM_OK)
            return JIM_ERR;
        switch (option) {
            case OPT_CIRCLE:
                circleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
                break;
            case OPT_AACIRCLE:
                aacircleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
                break;
            case OPT_FCIRCLE:
                filledCircleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
                break;
        }
        return JIM_OK;
    }
    else if (option == OPT_FREE) {
        /* FREE */
        if (argc != 2) {
            Jim_WrongNumArgs(interp, 2, argv, "");
            return JIM_ERR;
        }
        Jim_DeleteCommand(interp, Jim_String(argv[0]));
        return JIM_OK;
    }
    else if (option == OPT_FLIP) {
        /* FLIP */
        if (argc != 2) {
            Jim_WrongNumArgs(interp, 2, argv, "");
            return JIM_ERR;
        }
        SDL_Flip(jss->screen);
        return JIM_OK;
    }
    return JIM_OK;
}
Exemple #28
0
//No es usado por hilos
bool ModeloFactory::nuevoElegirEscenario(std::list<ParserYaml::stEscenario>& listaEscenarios){
	bool quit = false;
	bool clicBotonMouseIzquierdo = false;	
	int posicionMouseX, posicionMouseY;
	SDL_Event event;
	TTF_Font *fuente = NULL;
	SDL_Color textColor = { 255, 255, 255 }; //color blanco 
	SDL_Surface* pantalla = NULL;
	SDL_Init( SDL_INIT_EVERYTHING );
	pantalla = SDL_SetVideoMode( PANTALLA_ANCHO, PANTALLA_ALTO, SCREEN_BPP, SDL_SWSURFACE );
	TTF_Init();
	SDL_WM_SetCaption( "Menu", NULL );
	SDL_Surface *imagenDeFondo3 = NULL;
	imagenDeFondo3 = ImageLoader::getInstance().load_image( IMG_CARNICERO );
	fuente = TTF_OpenFont( FUENTE_USADA, 28 );	
	SDL_Rect offsetDelFondo;
	offsetDelFondo.x = 0;
	offsetDelFondo.y = 0;
	SDL_BlitSurface( imagenDeFondo3, NULL, pantalla, &offsetDelFondo );
	vector <SDL_Surface*> vectorDeNombresDeEscenarios;
	for (std::list<ParserYaml::stEscenario>::iterator it=listaEscenarios.begin() ; it != listaEscenarios.end(); it++ ){		
		const char* nombreDeEscenario = it->nombre.c_str();		
		vectorDeNombresDeEscenarios.push_back( TTF_RenderText_Solid( fuente, nombreDeEscenario, textColor ) );
	}	
	int x = 100;
	int y = 65;		
	for (std::vector<SDL_Surface*>::iterator it=vectorDeNombresDeEscenarios.begin() ; it != vectorDeNombresDeEscenarios.end(); it++ ){
		SDL_Rect offsetDelTextoNombreDelEscenario;
		offsetDelTextoNombreDelEscenario.x = x;
		offsetDelTextoNombreDelEscenario.y = y;						
		SDL_BlitSurface( *it, NULL, pantalla, &offsetDelTextoNombreDelEscenario );			
		rectangleRGBA( pantalla, x-5, y-5, x+400, y+35, 0, 255, 0, 255);	
		y += 100;			
	}		
	SDL_Flip( pantalla );
	while( quit == false ) {
        while( SDL_PollEvent( &event ) ) {            
			switch (event.type) {
				case SDL_QUIT:
					quit = true;
				break;
				case SDL_MOUSEMOTION:
					posicionMouseX = event.motion.x;
					posicionMouseY = event.motion.y;
				break;		
				case SDL_MOUSEBUTTONDOWN:
					switch (event.button.button) {
						case SDL_BUTTON_LEFT:	
							clicBotonMouseIzquierdo = true;
						break;						
					}			
					break;
				case SDL_MOUSEBUTTONUP:
					switch (event.button.button) {
						case SDL_BUTTON_LEFT:	
							clicBotonMouseIzquierdo = false;
						break;				
					}			
				break;
			}
		}		
		x = 100;
		y = 65;		
		int k = 1;
		while (k <= vectorDeNombresDeEscenarios.size() ) {
			if (clicBotonMouseIzquierdo && posicionMouseX > x-5 && posicionMouseX < x+400 && posicionMouseY > y-5 && posicionMouseY < y+35){				
				std::list<ParserYaml::stEscenario>::iterator it=listaEscenarios.begin();
				for ( int a = 1; a <= k-1; a++ ){		
					it++;
				}
				std::cout << "Se usara el escenario: "<< (*it).nombre << std::endl;
				this->juegoElegido.nombreEscenario = (*it).nombre;				
				this->juegoElegido.escenario = (*it);		
				while (vectorDeNombresDeEscenarios.size() != 0) {
					SDL_Surface * nombreDeEscenario = NULL; 
					nombreDeEscenario = vectorDeNombresDeEscenarios.back();
					SDL_FreeSurface ( nombreDeEscenario );
					vectorDeNombresDeEscenarios.pop_back();
				}
				SDL_FreeSurface( pantalla );    
				SDL_FreeSurface( imagenDeFondo3 );    
				TTF_CloseFont( fuente );
				TTF_Quit();   
				SDL_Quit();
				return true;
			}	
			y+=100;
			k++;
		}		
    }
	while (vectorDeNombresDeEscenarios.size() != 0) {
		SDL_Surface * nombreDeEscenario = NULL; 
		nombreDeEscenario = vectorDeNombresDeEscenarios.back();
		SDL_FreeSurface ( nombreDeEscenario );
		vectorDeNombresDeEscenarios.pop_back();
	}
	SDL_FreeSurface( pantalla );    
	SDL_FreeSurface( imagenDeFondo3 );    
	TTF_CloseFont( fuente );
	TTF_Quit();   
	SDL_Quit();
	return false;
}
Exemple #29
0
void Renderer::Rectangle(Point p, Size s, Uint8 rr, Uint8 gg, Uint8 bb, Uint8 aa){
    rectangleRGBA(_renderer, p.x(), p.y(), p.x() + s.w(), p.y() + s.h(), rr, gg, bb, aa);
}
Exemple #30
0
char ModeloFactory::nuevoElegirMisiones(std::list<ParserYaml::stEscenario>& listaEscenarios){
	bool quit = false;
	bool clicBotonMouseIzquierdo = false;	
	int posicionMouseX, posicionMouseY;
	char misionElegida;
	SDL_Event event;
	TTF_Font *fuente = NULL;
	SDL_Color textColor = { 255, 255, 255 }; //color blanco 
	SDL_Surface* pantalla = NULL;
	SDL_Init( SDL_INIT_EVERYTHING );
	pantalla = SDL_SetVideoMode( PANTALLA_ANCHO, PANTALLA_ALTO, SCREEN_BPP, SDL_SWSURFACE );
	TTF_Init();
	SDL_WM_SetCaption( "Misiones", NULL );
	SDL_Surface *imagenDeFondo = NULL;
	imagenDeFondo = ImageLoader::getInstance().load_image( "./img/background4.png" );
	fuente = TTF_OpenFont( "./fonts/Verdana.ttf", 28 );	
	SDL_Surface* textoMisionCarnicero = TTF_RenderText_Solid( fuente, "Mision Carnicero", textColor );
	SDL_Surface* textoMisionBanderas = TTF_RenderText_Solid( fuente, "Mision Banderas", textColor );	
	SDL_BlitSurface( imagenDeFondo, NULL, pantalla, NULL );		
	SDL_Rect offset;
	offset.x = 50;
	offset.y = 190;
	SDL_BlitSurface( textoMisionCarnicero, NULL, pantalla, &offset );
	rectangleRGBA( pantalla, 48, 190, 295, 225, 0, 255, 0, 255);
	offset.x = 350;
	offset.y = 190;
	SDL_BlitSurface( textoMisionBanderas, NULL, pantalla, &offset );	
	rectangleRGBA( pantalla, 348, 190, 595, 225, 0, 255, 0, 255);	
	SDL_Flip( pantalla );
	while( quit == false ) {
        while( SDL_PollEvent( &event ) ) {            
			switch (event.type) {
				case SDL_QUIT:
					quit = true;
				break;
				case SDL_MOUSEMOTION:
					posicionMouseX = event.motion.x;
					posicionMouseY = event.motion.y;
				break;		
				case SDL_MOUSEBUTTONDOWN:
					switch (event.button.button) {
						case SDL_BUTTON_LEFT:	
							clicBotonMouseIzquierdo = true;
						break;						
					}			
					break;
				case SDL_MOUSEBUTTONUP:
					switch (event.button.button) {
						case SDL_BUTTON_LEFT:	
							clicBotonMouseIzquierdo = false;
						break;				
					}			
				break;
			}
		}				
		if (clicBotonMouseIzquierdo && posicionMouseX >48 && posicionMouseX <295 && posicionMouseY >190 && posicionMouseY <225){
			misionElegida = 1;
			std::cout << "Mision Elegida Carnicero" << std::endl;
			Log::getInstance().log(1,__FILE__,__LINE__,"Mision Elegida Carnicero");
			std::list<ParserYaml::stEscenario>::iterator it=listaEscenarios.begin();
			advance(it, 0);
			std::cout << "Se usara el escenario: "<< (*it).nombre << std::endl;
			this->juegoElegido.nombreEscenario = (*it).nombre;
			this->juegoElegido.escenario = (*it);
			SDL_FreeSurface( imagenDeFondo );
			SDL_FreeSurface( textoMisionCarnicero );   
			SDL_FreeSurface( textoMisionBanderas );    				
			SDL_FreeSurface( pantalla );   
			TTF_CloseFont( fuente );
			TTF_Quit();   
			SDL_Quit();
			return misionElegida;
		}		
		else  if (clicBotonMouseIzquierdo && posicionMouseX >348 && posicionMouseX <595 && posicionMouseY >190 && posicionMouseY <225){
			misionElegida = 2;
			std::cout << "Mision Elegida Banderas" << std::endl;
			Log::getInstance().log(1,__FILE__,__LINE__,"Mision Elegida Banderas");
			std::list<ParserYaml::stEscenario>::iterator it=listaEscenarios.begin();
			advance(it, 1);
			std::cout << "Se usara el escenario: "<< (*it).nombre << std::endl;
			this->juegoElegido.nombreEscenario = (*it).nombre;
			this->juegoElegido.escenario = (*it);
			SDL_FreeSurface( imagenDeFondo );
			SDL_FreeSurface( textoMisionCarnicero );   
			SDL_FreeSurface( textoMisionBanderas );    				
			SDL_FreeSurface( pantalla );   
			TTF_CloseFont( fuente );
			TTF_Quit();   
			SDL_Quit();				
			return misionElegida;
		}		
    }
	SDL_FreeSurface( imagenDeFondo );
	SDL_FreeSurface( textoMisionCarnicero );   
	SDL_FreeSurface( textoMisionBanderas );    				
	SDL_FreeSurface( pantalla );   
	TTF_CloseFont( fuente );
	TTF_Quit();   
	SDL_Quit();		
	return 3;
}