Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. //Create a button
  2. bool CaffeinatedUI::Button(float x, float y, float width, float height, string tex, string text){
  3.     //Get our context / window
  4.     Window *ourwindow = Window::GetCurrent();
  5.     Context *context = Context::GetCurrent();
  6.     Texture *textu;
  7.     float MXPos = ourwindow->GetMousePosition().x;
  8.     float MYPos = ourwindow->GetMousePosition().y;
  9.     //Create our image.
  10.     if(tex == ""){
  11.         context->DrawRect(x,y,width,height);
  12.     }else{
  13.         if (MXPos >= x && MXPos <= width + x && MYPos >= y && MYPos <= height + y){
  14.             string textureasd = (char *)Replace((char *)tex.c_str(), ".tex", "");
  15.             textu = Texture::Load(textureasd + "_Hover.tex");
  16.         }else{
  17.             textu = Texture::Load(tex);
  18.         }
  19.         if(textu){
  20.             context->DrawImage(textu, x, y, width, height);
  21.         }else{
  22.             context->DrawRect(x,y,width,height);
  23.         }
  24.     }
  25.     float xfont, yfont;
  26.     xfont = (width - DefaultFontF->size) / 3.85f;
  27.     yfont = (height - DefaultFontF->size) / 2;
  28.     if(text != ""){context->DrawText(text, xfont + x, yfont + y);}
  29.     if(MXPos >= x && MXPos <= width + x && MYPos >= y && MYPos <= height + y){
  30.         if(GetLeftClicked()){
  31.             return true;
  32.         }else{
  33.             return false;
  34.         }
  35.     }else{
  36.         return false;
  37.     }
  38.     //Return false if nothings happening.
  39.     return false;
  40. }//End Button
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement