Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create a button
- bool CaffeinatedUI::Button(float x, float y, float width, float height, string tex, string text){
- //Get our context / window
- Window *ourwindow = Window::GetCurrent();
- Context *context = Context::GetCurrent();
- Texture *textu;
- float MXPos = ourwindow->GetMousePosition().x;
- float MYPos = ourwindow->GetMousePosition().y;
- //Create our image.
- if(tex == ""){
- context->DrawRect(x,y,width,height);
- }else{
- if (MXPos >= x && MXPos <= width + x && MYPos >= y && MYPos <= height + y){
- string textureasd = (char *)Replace((char *)tex.c_str(), ".tex", "");
- textu = Texture::Load(textureasd + "_Hover.tex");
- }else{
- textu = Texture::Load(tex);
- }
- if(textu){
- context->DrawImage(textu, x, y, width, height);
- }else{
- context->DrawRect(x,y,width,height);
- }
- }
- float xfont, yfont;
- xfont = (width - DefaultFontF->size) / 3.85f;
- yfont = (height - DefaultFontF->size) / 2;
- if(text != ""){context->DrawText(text, xfont + x, yfont + y);}
- if(MXPos >= x && MXPos <= width + x && MYPos >= y && MYPos <= height + y){
- if(GetLeftClicked()){
- return true;
- }else{
- return false;
- }
- }else{
- return false;
- }
- //Return false if nothings happening.
- return false;
- }//End Button
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement