Main Page   Packages   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

Window.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: Window.cpp,v 1.16 2002/08/08 23:09:22 virtualcasino Exp $
00003  */
00004 #include<Window.h>
00005 #include<SDL_gfxPrimitives.h>
00006 extern SDL_Event globalEvent;
00007 
00008 namespace clawsoft{
00009         Window::Window(){
00010                 setClassName("Window");
00011                 caption = "Virtual Casino";
00012         }
00013 
00014         Window::Window(Rect &r, const char *ccaption):Widget(r){
00015                 setClassName("Window");
00016                 caption = ccaption;
00017         }
00018 
00019         Window::Window(Rect &r, String ccaption):Widget(r){
00020                 setClassName("Window");
00021                 caption = ccaption;
00022         }
00023 
00024         void Window::map(){
00025                 SDL_Surface *label;
00026                 int temp;
00027                 label = SystemFont[DEFAULT_FONT].render(caption);
00028                 temp = label->w - 20;
00029                 toolbarRect.H(bRes[WINDOW_BOTTOM_MIDDLE]->h);
00030                 captionRect.H(33);
00031                 captionRect.W(temp);
00032                 SDL_FreeSurface(label);
00033                 if(H() <= 52){
00034                         lborderRect.H(52);
00035                         rborderRect.H(52);
00036                         H(52);
00037                 }
00038                 else{
00039                         lborderRect.H(H());
00040                         rborderRect.H(lborderRect.H());
00041                 }
00042                 lborderRect.X(X() - bRes[WINDOW_MIDDLE_LEFT_TOP]->w);
00043                 lborderRect.Y(Y());
00044                 rborderRect.Y(lborderRect.Y());
00045                 rborderRect.X(getRight());
00046 
00047                 lborderRect.W(80);
00048                 rborderRect.W(80);
00049                 
00050                 toolbarRect.X(X() + 220);
00051                 toolbarRect.Y(Y() + lborderRect.H() + 80);
00052                 captionRect.X(X() + 20);
00053                 captionRect.Y(Y() - bRes[WINDOW_RIGHT_TOP]->h + 11);
00054 
00055                 toolbarRect.W(W() - ((bRes[WINDOW_BOTTOM_LEFT]->w - bRes[WINDOW_MIDDLE_LEFT_TOP]->w) + (bRes[WINDOW_BOTTOM_RIGHT]->w - bRes[WINDOW_MIDDLE_RIGHT_TOP]->w)));
00056                 rect.X(lborderRect.X());
00057                 rect.Y(Y() - bRes[WINDOW_RIGHT_TOP]->h);
00058                 rect.W(W() + lborderRect.W() * 2);
00059                 rect.H(bRes[WINDOW_RIGHT_TOP]->h);
00060         }
00061 
00062         void Window::draw(){
00063                 SDL_Surface *label;
00064                 SDL_Rect src, dest;
00065                 int temp;
00066                 int y1, y2, y3, y4;
00067                 int start;
00068                 src.x = 0;
00069                 src.y = 0;
00070                 src.w = bRes[WINDOW_LEFT_TOP]->w;
00071                 src.h = bRes[WINDOW_LEFT_TOP]->h;
00072                 dest.x = X() - bRes[WINDOW_MIDDLE_LEFT_TOP]->w;
00073                 dest.y = Y() - src.h;
00074                 SDL_BlitSurface(bRes[WINDOW_LEFT_TOP], &src, Screen, &dest);
00075                 start = X() + (bRes[WINDOW_LEFT_TOP]->w - bRes[WINDOW_MIDDLE_LEFT_TOP]->w);
00076                 temp = getRight() - (bRes[WINDOW_RIGHT_TOP]->w - bRes[WINDOW_MIDDLE_RIGHT_TOP]->w);
00077                 src.w = bRes[WINDOW_TOP_CAPTION]->w;
00078                 src.h = bRes[WINDOW_TOP_CAPTION]->h;
00079                 for(dest.x = start; dest.x < temp; dest.x++){
00080                         SDL_BlitSurface(bRes[WINDOW_TOP_CAPTION], &src, Screen, &dest);
00081                 }
00082                 label = SystemFont[DEFAULT_FONT].render(caption);
00083                 dest.x = captionRect.X();
00084                 dest.y = captionRect.Y();
00085                 src.w = label->w;
00086                 src.h = label->h;
00087                 SDL_BlitSurface(label, &src, Screen, &dest);
00088                 SDL_FreeSurface(label);
00089                 //Now lets render the other corner
00090                 dest.x = temp;
00091                 src.w = bRes[WINDOW_RIGHT_TOP]->w;
00092                 src.h = bRes[WINDOW_RIGHT_TOP]->h;
00093                 dest.y = Y() - src.h;
00094                 SDL_BlitSurface(bRes[WINDOW_RIGHT_TOP], &src, Screen, &dest);
00095                 //Here we go to the hard part, the middle borders
00096                 if(lborderRect.Y() > 52){
00097                         temp = (lborderRect.H() - 52) / 2;
00098                         y1 = lborderRect.Y();
00099                         y2 = y1 + temp;
00100                         y3 = y2 + 52;
00101                         y4 = y3 + temp;
00102                         src.w = bRes[WINDOW_MIDDLE_LEFT_TOP]->w;
00103                         src.h = bRes[WINDOW_MIDDLE_LEFT_TOP]->h;
00104                         for(dest.y = y1; dest.y < y2; dest.y++){
00105                                 dest.x = lborderRect.X();
00106                                 SDL_BlitSurface(bRes[WINDOW_MIDDLE_LEFT_TOP], &src, Screen, &dest);
00107                                 dest.x = rborderRect.X();
00108                                 SDL_BlitSurface(bRes[WINDOW_MIDDLE_RIGHT_TOP], &src, Screen, &dest);
00109                         }
00110                         src.w = bRes[WINDOW_MIDDLE_LEFT]->w;
00111                         src.h = bRes[WINDOW_MIDDLE_LEFT]->h;
00112                         dest.x = lborderRect.X();
00113                         SDL_BlitSurface(bRes[WINDOW_MIDDLE_LEFT], &src, Screen, &dest);
00114                         dest.x = rborderRect.X();
00115                         SDL_BlitSurface(bRes[WINDOW_MIDDLE_RIGHT], &src, Screen, &dest);
00116 
00117 
00118                         src.w = bRes[WINDOW_MIDDLE_LEFT_BOTTOM]->w;
00119                         src.h = bRes[WINDOW_MIDDLE_LEFT_BOTTOM]->h;
00120                         for(dest.y = y3; dest.y < y4; dest.y++){
00121                                 dest.x = lborderRect.X();
00122                                 SDL_BlitSurface(bRes[WINDOW_MIDDLE_LEFT_BOTTOM], &src, Screen, &dest);
00123                                 dest.x = rborderRect.X();
00124                                 SDL_BlitSurface(bRes[WINDOW_MIDDLE_RIGHT_BOTTOM], &src, Screen, &dest);
00125                         }
00126 
00127                 }
00128                 else{
00129                         dest.x = lborderRect.X();
00130                         dest.y = lborderRect.Y();
00131                         src.w = bRes[WINDOW_MIDDLE_LEFT]->w;
00132                         src.h = bRes[WINDOW_MIDDLE_LEFT]->h;
00133                         SDL_BlitSurface(bRes[WINDOW_MIDDLE_LEFT], &src, Screen, &dest);
00134                         dest.x = rborderRect.X();
00135                         dest.y = rborderRect.Y();
00136                         SDL_BlitSurface(bRes[WINDOW_MIDDLE_RIGHT], &src, Screen, &dest);
00137                 }
00138                 //Draw Bottom left cprner
00139                 src.w = bRes[WINDOW_BOTTOM_LEFT]->w;
00140                 src.h = bRes[WINDOW_BOTTOM_LEFT]->h;
00141                 dest.x = X() - lborderRect.W();
00142                 dest.y = Y() + lborderRect.H();
00143                 SDL_BlitSurface(bRes[WINDOW_BOTTOM_LEFT], &src, Screen, &dest);
00144                 //Draw Toolbar
00145                 start = dest.x + src.w;
00146                 temp = start + toolbarRect.W();
00147                 src.w = bRes[WINDOW_BOTTOM_MIDDLE]->w;
00148                 src.h = bRes[WINDOW_BOTTOM_MIDDLE]->h;
00149                 for(dest.x = start; dest.x < temp; dest.x++){
00150                         SDL_BlitSurface(bRes[WINDOW_BOTTOM_MIDDLE], &src, Screen, &dest);
00151                 }
00152                 //bottom right corner
00153                 src.w = bRes[WINDOW_BOTTOM_RIGHT]->w;
00154                 src.h = bRes[WINDOW_BOTTOM_RIGHT]->h;
00155                 dest.x = getRight() - (src.w - bRes[WINDOW_MIDDLE_RIGHT]->w);
00156                 SDL_BlitSurface(bRes[WINDOW_BOTTOM_RIGHT], &src, Screen, &dest);
00157                 
00158                 boxRGBA(Screen, X(), Y(), getRight(), getBottom(), 0, 55, 0, 230);
00159                 //rectangleRGBA(Screen, X(), Y(), getRight(), getBottom(), 255, 255, 255, 255);
00160                 drawComponents();
00161         }
00162 
00163         void Window::action(){
00164 
00165         }
00166         
00167         bool Window::checkKeyEvents(){
00168                 return false;
00169         }
00170 
00171         bool Window::checkMouseEvents(){
00172                 if(mouse.inFocus(captionRect) && mouse.leftPressed()){
00173                         return true;
00174                 }
00175                 return false;
00176         }
00177 
00178         bool Window::checkMouseMotionEvents(){
00179                 int tx, ty;
00180                 if(mouse.inFocus(rect) && mouse.leftPressed()){
00181                         cerr << globalEvent.motion.xrel << "," << globalEvent.motion.xrel << "           \r";
00182                         tx = X() + globalEvent.motion.xrel;
00183                         ty = Y() + globalEvent.motion.yrel;
00184                         if(tx < lborderRect.W())
00185                                 tx = lborderRect.W() + 1;
00186                         if(tx > (Screen->w - W()- rborderRect.W() + 1))
00187                                 tx = Screen->w - W() - rborderRect.W() + 1;
00188                         if(ty < bRes[WINDOW_TOP_CAPTION]->h)
00189                                 ty = bRes[WINDOW_TOP_CAPTION]->h;
00190                         if(ty > (Screen->h - H() - bRes[WINDOW_BOTTOM_MIDDLE]->h))
00191                                 ty = Screen->h - H() - bRes[WINDOW_BOTTOM_MIDDLE]->h;
00192                         move(tx, ty);
00193                         return true;
00194                 }
00195                 return false;
00196         }
00197 
00198         bool Window::checkEvents(){
00199                 return false;
00200         }
00201 
00202         void Window::drawComponents(){ }
00203 
00204         void Window::move(int x, int y){
00205                 X(x);
00206                 Y(y);
00207                 map();
00208         }
00209 }

Powered by:

SourceForge Logo