// $Id: titlescreendisplay.cc,v 1.7 2006/08/23 22:43:17 matthew Exp $ // Fish Supper // Copyright (C) 2006 Matthew Clarke // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. #include "titlescreendisplay.h" #include "SDL_image.h" #include #include #include "fontrepository.h" extern FS::FontRepository * font_rep; // ******************* // *** CONSTRUCTOR *** // ******************* FS::TitleScreenDisplay::TitleScreenDisplay(SDL_Surface * s) { // save a pointer to main screen for drawing on screen = s; // load the images we need backdrop = IMG_Load( PKG_DATA_DIR "/images/titlescreen/intro_screen.png" ); int temp[] = { 180, 250, 320, 390 }; char * temp2[] = { "Play", "Settings", "High Scores", "Quit" }; for (int i = 0; i < NUM_OPTIONS; ++i) { options_ys[i] = temp[i]; options_strings[i] = temp2[i]; options_strings_widths[i] = font_rep->get_SFont( FontRepository::LARGE_FONT).getTextWidth(options_strings[i]); } // for for (int i = 0; i < 2; ++i) { dirty_rects[i].x = OPTIONS_X; dirty_rects[i].h = font_rep->get_SFont(FontRepository::LARGE_FONT).getHeight(); } // for current_selection = 0; } // FS::TitleScreenDisplay::TitleScreenDisplay() // ****************** // *** DESTRUCTOR *** // ****************** FS::TitleScreenDisplay::~TitleScreenDisplay() { SDL_FreeSurface(backdrop); } // FS::TitleScreenDisplay::~TitleScreenDisplay() // ************************ // *** MEMBER FUNCTIONS *** // ************************ // ************************************************** void FS::TitleScreenDisplay::redraw() { SDL_BlitSurface(backdrop, NULL, screen, NULL); for (int i = 0; i < NUM_OPTIONS; ++i) { if (i == current_selection) { font_rep->get_SFont(FontRepository::LARGE_FONT).write(screen, options_strings[i], OPTIONS_X, options_ys[i]); } else { font_rep->get_SFont(FontRepository::LARGE_FONT_FAINT).write(screen, options_strings[i], OPTIONS_X, options_ys[i]); } // if ... else } // for SDL_UpdateRect(screen, 0, 0, 0, 0); } // FS::TitleScreenDisplay::redraw() // ************************************************** FS::TitleScreenDisplay::Selection FS::TitleScreenDisplay::update(KeyboardEvent * events, int n) { bool changed = false; Selection sel = NONE; int i = 0; old_selection = current_selection; while (i < n) { if ( events[i] == ESCAPE_PRESSED ) { sel = QUIT; break; } else if ( events[i] == JUMP_KEY_PRESSED ) { sel = (Selection) current_selection; break; } else if ( events[i] == DOWN_KEY_PRESSED ) { current_selection = (current_selection + 1) % NUM_SELECTIONS; changed = true; } else if ( events[i] == UP_KEY_PRESSED ) { --current_selection; if (current_selection < 0) { current_selection = (NUM_SELECTIONS - 1); } // if changed = true; } // if ... else ++i; } // while if (changed) { redraw_options(); } // if return sel; } // FS::TitleScreenDisplay::update() // ************************************************** void FS::TitleScreenDisplay::redraw_options() { // repair background dirty_rects[0].y = options_ys[old_selection]; dirty_rects[0].w = options_strings_widths[old_selection]; SDL_BlitSurface(backdrop, &dirty_rects[0], screen, &dirty_rects[0]); font_rep->get_SFont(FontRepository::LARGE_FONT_FAINT).write(screen, options_strings[old_selection], OPTIONS_X, options_ys[old_selection]); // draw new highlighted selection dirty_rects[1].y = options_ys[current_selection]; dirty_rects[1].w = options_strings_widths[current_selection]; font_rep->get_SFont(FontRepository::LARGE_FONT).write(screen, options_strings[current_selection], OPTIONS_X, options_ys[current_selection]); SDL_UpdateRects(screen, 2, dirty_rects); } // FS::TitleScreenDisplay::redraw_options() // **************************************************