00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "screen.h"
00030
00031
00032 Screen::Screen(){
00033 width = 0;
00034 height = 0;
00035 depth = 0;
00036 screen = NULL;
00037 if( SDL_Init(SDL_INIT_EVERYTHING) <0 ) {
00038 cerr << "Unable to init SDL: " << SDL_GetError() << endl;
00039 SDL_Delay(2000);
00040 SDL_Quit();
00041 exit(1);
00042 }
00043 SDL_WM_SetCaption("Project Piedmont", NULL);
00044 YFont = SFont_InitFont(IMG_Load("font/24P_Arial_NeonYellow.png"));
00045 BFont = SFont_InitFont(IMG_Load("font/24P_Copperplate_Blue.png"));
00046 }
00047
00048 Screen::~Screen(){
00049 if(screen != NULL) SDL_FreeSurface(screen);
00050 SFont_FreeFont(YFont);
00051 SFont_FreeFont(BFont);
00052 }
00053
00054 int Screen::get_height(){
00055 return(height);
00056 }
00057
00058 int Screen::get_width(){
00059 return(width);
00060 }
00061
00062 int Screen::get_depth(){
00063 return(depth);
00064 }
00065
00066 int Screen::configure(int w, int h, int d){
00067 screen = SDL_SetVideoMode (w, h, d, SDL_HWSURFACE|SDL_DOUBLEBUF );
00068 if ( screen == NULL ) {
00069 cerr << "Unable to set 640x480 video: " << SDL_GetError() << endl;
00070 SDL_Delay(2000);
00071 SDL_Quit();
00072 exit(1);
00073 }
00074 height = h;
00075 width = w;
00076 depth = d;
00077 return(1);
00078 }
00079
00080 void Screen::update_screen(){
00081
00082 SDL_Flip(screen);
00083
00084 }
00085
00086 void Screen::update_rect(SDL_Rect dest){
00087 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
00088 }
00089
00090 SDL_Surface* Screen::get_screen(){
00091 return(screen);
00092 }
00093
00094 int Screen::draw(SDL_Surface *s, SDL_Rect src, SDL_Rect dest){
00095 if(SDL_BlitSurface(s, &src, screen, &dest) == -1) printf("darn, Screen::draw\n");
00096 return(1);
00097 }
00098
00099 int Screen::blit(SDL_Surface *s, SDL_Rect dest){
00100 SDL_Rect src = makerect(0,0, s->w, s->h);
00101 if(SDL_BlitSurface(s, &src, screen, &dest) == -1) printf("darn, Screen::blit\n");
00102 return(1);
00103 }
00104
00105 int Screen::blankblit(SDL_Surface *s, SDL_Rect dest){
00106 SDL_Rect src = makerect(0, 0, s->w, s->h);
00107 blank(dest);
00108 if(SDL_BlitSurface(s, &src, screen, &dest) == -1) printf("darn, Screen::blankblit\n");
00109 return(1);
00110 }
00111
00112 int Screen::blank(SDL_Rect dest){
00113 Uint32 color;
00114 color = SDL_MapRGB(screen->format, 0, 0, 0);
00115 return(SDL_FillRect(screen, &dest, color));
00116 }
00117
00118 int Screen::textwidth(char* string){
00119 return(get_text_width(string));
00120 }
00121
00122 int Screen::textwidthsy(char* string){
00123 return(SFont_TextWidth(YFont, string));
00124 }
00125
00126 int Screen::textwidthsb(char* string){
00127 return(SFont_TextWidth(BFont, string));
00128 }
00129
00130 void Screen::write(char* string, int x, int y, int color, int scale){
00131 int round = 1;
00132 if(scale == 1) round = 0;
00133 put_string2(screen, string, x, y, color, scale, round);
00134 }
00135
00136 void Screen::writesy(char* string, int x, int y){
00137 SFont_Write(screen, YFont, x, y, string);
00138 }
00139
00140 void Screen::writesb(char* string, int x, int y){
00141 SFont_Write(screen, BFont, x, y, string);
00142 }
00143
00144 void Screen::operator=(Screen &source){
00145 if (this == &source) return;
00146 height = source.height;
00147 width = source.width;
00148 depth = source.depth;
00149 screen = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, depth, 0,0,0,0);
00150 screen = source.screen;
00151 YFont = (SFont_Font *) malloc(sizeof(SFont_Font));
00152 BFont = (SFont_Font *) malloc(sizeof(SFont_Font));
00153 YFont = source.YFont;
00154 BFont = source.BFont;
00155 }