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

BaseButton.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: BaseButton.cpp,v 1.12 2002/07/30 20:13:03 virtualcasino Exp $
00003  */
00004 #include<BaseButton.h>
00005 #include<Resource.h>
00006 #include<iostream.h>
00007 #include<SDL/SDL.h>
00008 
00009 extern SDL_Surface *Screen;
00010 extern char *fnames[];
00011 
00012 namespace clawsoft{
00013 
00014         BaseButton::BaseButton(){
00015                 Object::setClassName("BaseButton");
00016                 state = false;
00017                 drawn = false;
00018         }
00019 
00020         BaseButton::BaseButton(Rect &r):Widget(r){
00021                 Object::setClassName("BaseButton");
00022                 state = false;
00023                 drawn = false;
00024         }
00025 
00026 
00027         bool BaseButton::pressed(){
00028                 state = false;
00029                 if(mouse.leftPressed() && mouse.inFocus((Rect)*this)){
00030                         state = true;
00031                 }
00032                 return state;
00033         }
00034 
00035         void BaseButton::draw(){
00036                 SDL_Rect src;
00037                 SDL_Rect dest;
00038                 dest.x = X();
00039                 dest.y = Y();
00040                 dest.w = W();
00041                 dest.h = H();
00042                 src.x = 0;
00043                 src.y = 0;
00044                 //if(!state){   //If not pressed draw it normally
00045                 if(mouse.inFocus((Rect)*this)){ //Draw with focus
00046                         if(mouse.leftPressed()){
00047                                 src.w = bRes[BASE_BUTTON_DOWN]->w;
00048                                 src.h = bRes[BASE_BUTTON_DOWN]->h;
00049                                 SDL_BlitSurface(bRes[BASE_BUTTON_DOWN],
00050                                         &src, Screen, &dest);
00051                         }
00052                         else{
00053                                 src.w = bRes[BASE_BUTTON_LIT]->w;
00054                                 src.h = bRes[BASE_BUTTON_LIT]->h;
00055                                 SDL_BlitSurface(bRes[BASE_BUTTON_LIT],
00056                                                 &src, Screen, &dest);
00057                         }
00058                 }
00059                 else{ //Draw normally
00060                         if(!drawn){
00061                                 src.w = bRes[BASE_BUTTON_UP]->w;
00062                                 src.h = bRes[BASE_BUTTON_UP]->h;
00063                                 SDL_BlitSurface(bRes[BASE_BUTTON_UP],
00064                                                 &src, Screen, &dest);
00065                                 drawn = true;
00066                         }
00067                 }
00068                 //SDL_UpdateRect(Screen, dest.x, dest.y, dest.w, dest.h);
00069         }
00070 
00071         void BaseButton::action(int xx, int yy, int button){
00072                 cout << "Button pressed\n";
00073         }
00074 
00075         bool BaseButton::checkMouseMotionEvents(){
00076                 if(drawn){
00077                         if(!mouse.inFocus((Rect)*this)){
00078                                 drawn = false;
00079                         }
00080                 }
00081                 draw();
00082                 return false;
00083         }
00084 
00085         bool BaseButton::checkMouseEvents(){
00086                 int xx, yy, bb;
00087                 mouse.getStatus(&xx, &yy, &bb);
00088                 if(pressed()){
00089                         draw();
00090                         action(xx, yy, bb);
00091                         return true;
00092                 }
00093                 return false;
00094         }
00095 
00096         bool BaseButton::checkKeyEvents(){
00097                 int xx, yy, bb;
00098                 mouse.getStatus(&xx, &yy, &bb);
00099                 if(keyboard.keyPressed(SDLK_RETURN) && mouse.inFocus((Rect)*this)){
00100                         mouse.getStatus(&xx, &yy, &bb);
00101                         draw();
00102                         action(xx, yy, bb);
00103                         return true;
00104                 }
00105                 return false;
00106         }
00107 }
00108 

Powered by:

SourceForge Logo