Exemple #1
0
void dialog_frame::draw_background()
{
	if(auto_restore_) {
		clear_background();
//		restorer_ = new surface_restorer(&video_, dim_.exterior);
	}

	if (dialog_style_.blur_radius) 
	{
		//surface surf = ::get_surface_portion(video_.getSurface(), dim_.exterior);
		//surf = blur_surface(surf, dialog_style_.blur_radius, false);
		//SDL_BlitSurface(surf, NULL, video_.getSurface(), &dim_.exterior);
		// KP: fade instead of blur...
		SDL_SetRenderDrawColor(0, 0, 0, 0x80);
		SDL_RenderFill(&dim_.exterior);
	}

	if(bg_ == NULL) {
		ERR_DP << "could not find dialog background '" << dialog_style_.panel << "'\n";
		return;
	}
	for(int i = 0; i < dim_.interior.w; i += bg_->w) {
		for(int j = 0; j < dim_.interior.h; j += bg_->h) {
			SDL_Rect src = {0,0,0,0};
			src.w = std::min(dim_.interior.w - i, bg_->w);
			src.h = std::min(dim_.interior.h - j, bg_->h);
			SDL_Rect dst = src;
			dst.x = dim_.interior.x + i;
			dst.y = dim_.interior.y + j;
			//SDL_BlitSurface(bg_, &src, video_.getSurface(), &dst);
			blit_surface(dst.x, dst.y, bg_, &src);
		}
	}
}
/* paints over a glyph sized region with the background color
   in effect it erases the area
*/
void
drawBlank(int x, int y)
{
    SDL_Rect rect = { x, y, GLYPH_SIZE_SCREEN, GLYPH_SIZE_SCREEN };
    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
                           bg_color.unused);
    SDL_RenderFill(&rect);
}
int
main(int argc, char *argv[])
{

    int index;                  /* index of last key we pushed in the bitmap font */
    SDL_Window *window;
    SDL_Event event;            /* last event received */
    SDLMod mod;                 /* key modifiers of last key we pushed */
    SDL_scancode scancode;      /* scancode of last key we pushed */

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("Error initializing SDL: %s", SDL_GetError());
    }
    /* create window */
    window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
    /* create renderer */
    SDL_CreateRenderer(window, 0, 0);

    /* load up our font */
    loadFont();

    /* draw the background, we'll just paint over it */
    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
                           bg_color.unused);
    SDL_RenderFill(NULL);
    SDL_RenderPresent();

    int done = 0;
    /* loop till we get SDL_Quit */
    while (SDL_WaitEvent(&event)) {
        switch (event.type) {
        case SDL_QUIT:
            done = 1;
            break;
        case SDL_KEYDOWN:
            index = keyToIndex(event.key.keysym);
            scancode = event.key.keysym.scancode;
            mod = event.key.keysym.mod;
            if (scancode == SDL_SCANCODE_DELETE) {
                /* if user hit delete, delete the last character */
                backspace();
                lastCharWasColon = 0;
            } else if (lastCharWasColon && scancode == SDL_SCANCODE_0
                       && (mod & KMOD_SHIFT)) {
                /* if our last key was a colon and this one is a close paren, the make a hoppy face */
                backspace();
                drawIndex(32);  /* index for happy face */
                numChars++;
                drawCursor();
                lastCharWasColon = 0;
            } else if (index != -1) {
                /* if we aren't doing a happy face, then just draw the normal character */
                drawIndex(index);
                numChars++;
                drawCursor();
                lastCharWasColon =
                    (event.key.keysym.scancode == SDL_SCANCODE_SEMICOLON
                     && (event.key.keysym.mod & KMOD_SHIFT));
            }
            /* check if the key was a colon */
            /* draw our updates to the screen */
            SDL_RenderPresent();
            break;
#ifdef __IPHONEOS__
        case SDL_MOUSEBUTTONUP:
            /*      mouse up toggles onscreen keyboard visibility
               this function is available ONLY on iPhone OS
             */
            SDL_iPhoneKeyboardToggle(window);
            break;
#endif
        }
    }
    cleanup();
    return 0;
}
void loadscreen::set_progress(const int percentage, const std::string &text, const bool commit)
{
	
	if (gRedraw)
	{
		gRedraw = false;
		logo_drawn_ = false;
	}
	
	// Saturate percentage.
	prcnt_ = percentage < MIN_PERCENTAGE ? MIN_PERCENTAGE: percentage > MAX_PERCENTAGE ? MAX_PERCENTAGE: percentage;
	// Set progress bar parameters:
	int fcr =  21, fcg =  53, fcb =  80;		// RGB-values for finished piece.
	int lcr =  21, lcg =  22, lcb =  24;		// Leftover piece.
	//int bcr = 188, bcg = 176, bcb = 136;		// Border color.
	int bcr = 104, bcg = 74, bcb = 28;			// Border color.
	int bw = 1;								//< Border width.
	int bispw = 1;								//< Border inner spacing width.
	bw = 2*(bw+bispw) > screen_.getx() ? 0: 2*(bw+bispw) > screen_.gety() ? 0: bw;
	int scrx = screen_.getx() - 2*(bw+bispw);	//< Available width.
	int scry = screen_.gety() - 2*(bw+bispw);	//< Available height.
	int pbw = scrx/2;							//< Used width.
	int pbh = scry/16;							//< Used heigth.
	int	lightning_thickness = 2;

//	surface const gdis = screen_.getSurface();
	SDL_Rect area;
	
	// Clear the last text and draw new if text is provided.
//	if(text.length() > 0 && commit)
//	{
//		logo_drawn_ = false;
//	}
	
	bool updateFull = false;
	
	
	// Draw logo if it was succesfully loaded.
//	if (logo_surface_ && !logo_drawn_) 
	if (!logo_drawn_)
	{
/*		
		area.x = (screen_.getx () - logo_surface_->w) / 2;
		area.y = ((scry - logo_surface_->h) / 2) - pbh;
		area.w = logo_surface_->w;
		area.h = logo_surface_->h;
		// Check if we have enough pixels to display it.
		if (area.x > 0 && area.y > 0) {
			pby_offset_ = (pbh + area.h)/2;
			SDL_BlitSurface (logo_surface_, 0, gdis, &area);
		} else {
			ERR_DISP << "loadscreen: Logo image is too big." << std::endl;
		}
*/
		area.x = 0;
		area.y = 0;
		//area.w = logo_surface_->w;
		//area.h = logo_surface_->h;
		//SDL_BlitSurface (logo_surface_, 0, gdis, &area);		
		//screen_.blit_surface(0, 0, logo_surface_);
		GLshort vertices[12];
		GLfloat texCoords[8];
		
#ifdef __IPAD__
		int size = 1024;
#else
		int size = 512;
#endif
		
		vertices[0] = 0;
		vertices[1] = 0;
		vertices[2] = 0;
		vertices[3] = size;
		vertices[4] = 0;
		vertices[5] = 0;
		vertices[6] = 0;
		vertices[7] = size;
		vertices[8] = 0;
		vertices[9] = size;
		vertices[10] = size;
		vertices[11] = 0;

		texCoords[0] = 0;
		texCoords[1] = 0;
		texCoords[2] = 1;
		texCoords[3] = 0;
		texCoords[4] = 0;
		texCoords[5] = 1;
		texCoords[6] = 1;
		texCoords[7] = 1;
		renderQueueAddTexture(vertices, texCoords, logo_texture_, 0xFFFFFFFF, 1.0);
		
		//	glVertexPointer(3, GL_SHORT, 0, vertices);
		//	glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
		//	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		
		//SDL_RenderCopy(logo_texture_, NULL, NULL,DRAW);
		//SDL_RenderPresent();
		//SDL_UpdateRect(gdis, area.x, area.y, area.w, area.h);
		
		// draw logo over everything
#ifdef __IPAD__
		std::string path = game_config::path + "/data/core/images/misc/logo.png";
		surface logo_surface = IMG_Load(path.c_str());
		blit_surface((1024-logo_surface.get()->w)/2, -10, logo_surface);
		
		
		SDL_Rect tip_area = {690, 306, 225, 140};
		draw_tip_of_day(screen_, tips_of_day, gui::dialog_frame::titlescreen_style,&tip_area);		
#else
		std::string path = game_config::path + "/data/core/images/misc/logo_small.png";
		surface logo_surface = IMG_Load(path.c_str());
		blit_surface((480-logo_surface.get()->w)/2, -10, logo_surface);
		

		SDL_Rect tip_area = {242, 100, 225, 140};
		draw_tip_of_day(screen_, tips_of_day, gui::dialog_frame::titlescreen_style,&tip_area);
#endif

		logo_drawn_ = true;

		updateFull = true;
	}
	
	int pbx = (scrx - pbw)/2;					// Horizontal location.
#ifdef __IPAD__	
	int pby = 693;
#else
	int pby = 276; //(scry - pbh)/2 + pby_offset_;		// Vertical location.
#endif

	// Draw top border.
	area.x = pbx; area.y = pby;
	area.w = pbw + 2*(bw+bispw); area.h = bw;
//	SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	SDL_SetRenderDrawColor(bcr, bcg, bcb, 0xff);
	SDL_RenderFill(&area);
	// Draw bottom border.
	area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
	area.w = pbw + 2*(bw+bispw); area.h = bw;
	//SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	SDL_RenderFill(&area);
	// Draw left border.
	area.x = pbx; area.y = pby + bw;
	area.w = bw; area.h = pbh + 2*bispw;
	//SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	SDL_RenderFill(&area);
	// Draw right border.
	area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
	area.w = bw; area.h = pbh + 2*bispw;
	//SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	SDL_RenderFill(&area);
	// Draw the finished bar area.
	area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
	area.w = (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
	//SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));
	SDL_SetRenderDrawColor(fcr, fcg, fcb, 0xff);
	SDL_RenderFill(&area);

	SDL_Rect lightning = area;
	lightning.h = lightning_thickness;
	//we add 25% of white to the color of the bar to simulate a light effect
	//SDL_FillRect(gdis,&lightning,SDL_MapRGB(gdis->format,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4));
	SDL_SetRenderDrawColor((fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4, 0xff);
	SDL_RenderFill(&lightning);
	lightning.y = area.y+area.h-lightning.h;
	//remove 50% of color to simulate a shadow effect
	//SDL_FillRect(gdis,&lightning,SDL_MapRGB(gdis->format,fcr/2,fcg/2,fcb/2));
	SDL_SetRenderDrawColor(fcr/2,fcg/2,fcb/2, 0xff);
	SDL_RenderFill(&lightning);

	// Draw the leftover bar area.
	area.x = pbx + bw + bispw + (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.y = pby + bw + bispw;
	area.w = ((MAX_PERCENTAGE - prcnt_) * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
	//SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));
	SDL_SetRenderDrawColor(lcr, lcg, lcb, 0xff);
	SDL_RenderFill(&area);

	// Clear the last text and draw new if text is provided.
/*	if(text.length() > 0 && commit)
	{
		SDL_Rect oldarea = textarea_;
//		SDL_FillRect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
		textarea_ = font::line_size(text, font::SIZE_NORMAL);
		textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
		textarea_.y = pby + pbh + 4*(bw + bispw);
		//draw_solid_tinted_rectangle(textarea_.x-4, textarea_.y-2, textarea_.w + 8, textarea_.h + 4,0,0,0,0.50,gdis);
		SDL_Rect tintRect = {textarea_.x-4, textarea_.y-2, textarea_.w + 8, textarea_.h + 4};
		SDL_SetRenderDrawColor(0, 0, 0, 0x80);
		SDL_RenderFill(&tintRect);
		textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOUR,text,textarea_.x,textarea_.y);
		oldarea.x = std::min<int>(textarea_.x, oldarea.x);
		oldarea.y = std::min<int>(textarea_.y, oldarea.y);
		oldarea.w = std::max<int>(textarea_.w, oldarea.w);
		oldarea.h = std::max<int>(textarea_.h, oldarea.h);
//		SDL_UpdateRect(gdis, oldarea.x, oldarea.y, oldarea.w, oldarea.h);
	}
*/ 
	// Update the rectangle if needed
	if(commit)
	{
//		SDL_UpdateRect(gdis, pbx, pby, pbw + 2*(bw + bispw), pbh + 2*(bw + bispw));
	}
	
//	if (updateFull)
//	{
//		SDL_UpdateRect(gdis, 0, 0, 480, 320);
//	}
//	else if (commit)
//	{
//		SDL_UpdateRect(gdis, 116, 274, 251, 47);
//	}
	
	SDL_RenderPresent();
}