Betagui.jpg

This is an OgreGallery featured project

BetaGUI

Minimal GUI overlay system

What it does and what it does not do

Using overlays it is capable of doing seven things:

  • Creating a Window
  • Resizing the window via a bottom-right button.
  • Moving the window around via a top bar button.
  • Creating a push button in a window with a inactive and active material state.
    • Calling back to a function or class to report when that button has been "pushed"
  • Creating a functional text gadget on a window to accept textual input to n characters.
  • Creating a static piece of text on a window.


It does nothing more or nothing less.

A video demonstrating the features 1.26Mb, playable in VLC.

BetaGUI is an incredibly small, very free to use, and incredibly unreadable piece of code that creates a fully working {LEX()}GUI{LEX} system with no external libraries except for Ogre.

So whats the point if it can't do feature x?

You may ask, whats the point? {LEX()}CEGUI{LEX} or OpenGUI can do the same but 10x as better, yes it can. But perhaps you don't want the dependencies or perhaps your application is brand new and you just really wanted to get the core of it done and out of the away with before messing around with XML layouts.

What it is the differences between a fully features GUI library, once you get to that point. Then BetaGUI is no longer for you.

Download and Usage

This is the full source right here, it depends on nothing except for Ogre. Just paste it into a header file and you should be good to go. It is under the Whatevar! licence. Do what you want to do it, just keep the original copyright header in the code.

C++ Version

Code

015 Version - 88 Lines, by Betajaen

/// Betajaen's GUI 015
/// Written by Robin "Betajaen" Southern 07-Nov-2006, http://www.ogre3d.org/wiki/index.php/BetaGUI
/// This code is under the Whatevar! licence. Do what you want; but keep the original copyright header.
/// This code is not meant to be readable, if you base your future source on this, I will laugh at you.
#include "Ogre.h"
using namespace Ogre;using namespace std;namespace BetaGUI {class GUI;class Window;class Button;
class TextInput;class Callback;enum wt{NONE=0,MOVE=1,RESIZE=2,RESIZE_AND_MOVE=3};
class GUI{public:friend class Window;friend class Button;friend class TextInput;
    GUI(String font, uint fontSize);~GUI();    bool injectMouse(uint x, uint y, bool LMB);
    bool injectKey(String key, uint x, uint y);void injectBackspace(uint x, uint y){injectKey("!b",x,y);}
    Window* createWindow(Vector4,String,wt,String c="");void destroyWindow(Window *w){mXW=w;}
    OverlayContainer* createOverlay(String,Vector2,Vector2,String m="",String="",bool a=true);
    OverlayContainer* createMousePointer(Vector2 size,String material);protected:uint wc,bc,tc;
    Overlay* mO;vector<Window*>WN;Window *mXW;OverlayContainer* mMP;String mFont;uint mFontSize;};
class Window{public:friend class Button;friend class TextInput;friend class GUI;
    Button* createButton(Vector4 Dimensions, String Material, String Text, Callback callback);
    TextInput* createTextInput(Vector4 Dimensions, String Material, String Value, uint length);
    void createStaticText(Vector4 Dimensions, String Text);
    void hide(){mO->hide();}void show(){mO->show();}bool isVisible(){return mO->isVisible();}
    protected:Window(Vector4 Dimensions, String Material, wt type, String caption, GUI *gui);~Window();
    bool check(uint x, uint y, bool LMB); bool checkKey(String key, uint x, uint y);TextInput* mATI;
    Button *mRZ,*mAB,*mTB;uint x,y,w,h;GUI *mGUI;OverlayContainer* mO;vector<BetaGUI::Button*>mB;vector<BetaGUI::TextInput*>mT;};
class BetaGUIListener{public:virtual void onButtonPress(Button *ref) = 0;};
class Callback{public:friend class Window;friend class Button;Callback(){t=0;}
    Callback(void(*functionPointer)(Button *ref)){t=1;fp=functionPointer;}
    Callback(BetaGUIListener *L){t=2;LS=L;}protected:uchar t;void(*fp)(Button *r);BetaGUIListener *LS;};
class Button{public:friend class Window;protected:
    Button(Vector4 Dimensions, String Material, String Text, Callback callback, Window *parent);
    ~Button(){mO->getParent()->removeChild(mO->getName());mCP->getParent()->removeChild(mCP->getName());}
    void activate(bool a){if(!a&&mmn!="")mO->setMaterialName(mmn);if(a&&mma!="")mO->setMaterialName(mma);}
    bool in(uint mx,uint my,uint px,uint py) {return(!(mx>=x+px&&my>=y+py))||(!(mx<=x+px+w&&my<=y+py+h));}
    OverlayContainer* mO,*mCP;String mmn,mma;Callback callback;uint x,y,w,h;};
class TextInput{protected: friend class Window;
    TextInput(Vector4 Dimensions, String Material, String Value, uint length, Window *parent);~TextInput(){}
    bool in(uint mx,uint my,uint px,uint py) {return(!(mx>=x+px&&my>=y+py))||(!(mx<=x+px+w&&my<=y+py+h));}
    OverlayContainer* mO,*mCP;String mmn,mma,value;uint x,y,w,h,length;
    public:String getValue(){return value;}void setValue(String v){mCP->setCaption(value=v);}};
}
/*** Optional Seperate Code that goes into a .cpp part : Cut downwards and paste  ***/
using namespace Ogre;using namespace std;namespace BetaGUI {
GUI::GUI(String font, uint fontSize):mXW(0), mMP(0),mFont(font),mFontSize(fontSize),wc(0),bc(0),tc(0){
    mO=OverlayManager::getSingleton().create("BetaGUI");mO->show();}
GUI::~GUI(){for(uint i=0;i < WN.size();i++)delete WN[i];WN.clear();}
bool GUI::injectMouse(uint x,uint y,bool LMB){if(mMP)mMP->setPosition(x,y);
    if(mXW){for(vector<Window*>::iterator i=WN.begin();i!=WN.end();i++) {if(mXW==(*i)){delete mXW;WN.erase(i);mXW=0;return false;}}}
    for(uint i=0;i<WN.size();i++){if(WN[i]->check(x,y,LMB)){return true;}}return false;}
bool GUI::injectKey(String key, uint x,uint y){for(uint i=0;i<WN.size();i++){if(WN[i]->checkKey(key,x,y)){return true;}}return false;}
OverlayContainer* GUI::createOverlay(String N,Vector2 P,Vector2 D,String M,String C,bool A){String t="Panel";if (C!="")t="TextArea";
    OverlayContainer* e=static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement(t, N));
    e->setMetricsMode(GMM_PIXELS);e->setDimensions(D.x,D.y);e->setPosition(P.x,P.y);if (M!="")e->setMaterialName(M);
    if (C!=""){e->setCaption(C);e->setParameter("font_name",mFont);e->setParameter("char_height",StringConverter::toString(mFontSize));}
    if(A){mO->add2D(e);e->show();}return e;}
OverlayContainer* GUI::createMousePointer(Vector2 d, String m) {
    Overlay* o=OverlayManager::getSingleton().create("BetaGUI.MP");o->setZOrder(649);mMP=createOverlay("bg.mp",Vector2(0,0),d,m,"", false);
    o->add2D(mMP);o->show();mMP->show();return mMP;}
Window* GUI::createWindow(Vector4 D,String M, wt T,String C){Window* w=new Window(D,M,T,C,this);WN.push_back(w);return w;}
Window::Window(Vector4 D,String M, wt t,String C, GUI *G):x(D.x),y(D.y),w(D.z),h(D.w),mGUI(G),mTB(0),mRZ(0),mATI(0),mAB(0){
    mO=G->createOverlay("BetaGUI.w"+StringConverter::toString(G->wc++),Vector2(D.x,D.y),Vector2(D.z,D.w),M); 
    if(t>=2){Callback c;c.t=4;mRZ=createButton(Vector4(D.z-16,D.w-16,16,16),M+".resize","",c);}
    if(t==1||t==3){Callback c;c.t=3;mTB=createButton(Vector4(0,0,D.z,22),M+".titlebar",C,c);}}
Window::~Window(){for(uint i=0;i<mB.size();i++)delete mB[i];for(uint i=0;i<mT.size();i++)delete mT[i];mGUI->mO->remove2D(mO);}
Button* Window::createButton(Vector4 D,String M,String T,Callback C) {Button *x=new Button(D,M,T,C,this);mB.push_back(x);return x;}
Button::Button(Vector4 D, String M, String T, Callback C, Window *P):x(D.x),y(D.y),w(D.z),h(D.w),mmn(M),mma(M){
    ResourcePtr ma=MaterialManager::getSingleton().getByName(mmn+".active");if(!ma.isNull())mma+=".active";
    mO=P->mGUI->createOverlay(P->mO->getName()+"b"+StringConverter::toString(P->mGUI->bc++),Vector2(x,y),Vector2(w,h),M,"",false);
    mCP=P->mGUI->createOverlay(mO->getName()+"c",Vector2(4,(h-P->mGUI->mFontSize)/2),Vector2(w,h),"",T,false);
    P->mO->addChild(mO);mO->show();mO->addChild(mCP);mCP->show();callback=C;}
TextInput* Window::createTextInput(Vector4 D,String M,String V,uint L){TextInput *x=new TextInput(D,M,V,L,this);mT.push_back(x);return x;}
void Window::createStaticText(Vector4 D,String T){OverlayContainer* x=mGUI->createOverlay(mO->getName()+StringConverter::toString(mGUI->tc++),
    Vector2(D.x,D.y),Vector2(D.z,D.w),"", T,false);mO->addChild(x);x->show();}
TextInput::TextInput(Vector4 D,String M,String V,uint L,Window *P):x(D.x),y(D.y),w(D.z),h(D.w),value(V),mmn(M),mma(M),length(L) {
    ResourcePtr ma=Ogre::MaterialManager::getSingleton().getByName(mmn+".active");if(!ma.isNull())mma+=".active";
    mO=P->mGUI->createOverlay(P->mO->getName()+"t"+StringConverter::toString(P->mGUI->tc++) ,Vector2(x,y),Vector2(w,h),M,"",false);
    mCP=P->mGUI->createOverlay(mO->getName()+"c",Vector2(4,(h-P->mGUI->mFontSize)/2),Vector2(w,h),"",V,false);
    P->mO->addChild(mO);mO->show();mO->addChild(mCP);mCP->show();}
bool Window::checkKey(String k, uint px, uint py){if(mATI==0)return false;if(!mO->isVisible())return false;
    if(!(px>=x&&py>=y)||!(px<=x+w&&py<=y+h))return false;if(k=="!b"){mATI->setValue(mATI->value.substr(0,mATI->value.length()-1));
    return true;}if(mATI->value.length() >= mATI->length)return true;mATI->mCP->setCaption(mATI->value+=k);return true;}
bool Window::check(uint px, uint py, bool LMB){if(!mO->isVisible())return false;
    if(!(px>=x&&py>=y)||!(px<=x+w&&py<=y+h)){if(mAB){mAB->activate(false);}return false;}
    if(mAB){mAB->activate(false);}for(uint i=0;i<mB.size();i++){if (mB[i]->in(px,py,x,y))continue;
    if(mAB){mAB->activate(false);}mAB=mB[i];mAB->activate(true);if(!LMB)return true;
    if(mATI){mATI->mO->setMaterialName(mATI->mmn);mATI=0;}switch(mAB->callback.t){default: return true;
    case 1:mAB->callback.fp(mAB);return true;case 2:mAB->callback.LS->onButtonPress(mAB);return true;
    case 3:mO->setPosition(x=px-(mAB->w/2),y=py-(mAB->h/2));return true;case 4:mO->setDimensions(w=px-x+8,h=py-y+8);
    mRZ->mO->setPosition(mRZ->x=w-16,mRZ->y=h-16);if(mTB){mTB->mO->setWidth(mTB->w=w);}return true;}}if (!LMB)return true;
    for(uint i=0;i<mT.size();i++){if(mT[i]->in(px,py,x,y))continue;mATI=mT[i];mATI->mO->setMaterialName(mATI->mma);return true;}
    if(mATI){mATI->mO->setMaterialName(mATI->mmn);mATI=0;}return true;}
} // End of Betajaen's GUI. Normal programming can resume now.

Uncompressed version...

/// Betajaen's GUI 015 Uncompressed
/// Written by Robin "Betajaen" Southern 07-Nov-2006, http://www.ogre3d.org/wiki/index.php/BetaGUI
/// This code is under the Whatevar! licence. Do what you want; but keep the original copyright header.
#include "Ogre.h"
using namespace Ogre;
using namespace std;
namespace BetaGUI {
    
    /// This code is not meant to be readable, if you base your future source on this, I will laugh at you.
    
    class GUI;
    class Window;
    class Button;
    class TextInput;
    class Callback;
    
    enum wt { /* Window Type */
        NONE=0,
        MOVE=1,
        RESIZE=2,
        RESIZE_AND_MOVE=3
    };

    class GUI {
        public:
            friend class Window;
            friend class Button;
            friend class TextInput;
            GUI(String font, uint fontSize);
            ~GUI();
            bool injectMouse(uint x, uint y, bool LMB);
            bool injectKey(String key, uint x, uint y);
            void injectBackspace(uint x, uint y);
            Window*     createWindow(Vector4 Dimensions, String Material, wt type, String caption = "");
            void destroyWindow(Window *window) {
                mXW=window;
            }
            OverlayContainer* createOverlay(Ogre::String name, Vector2 position, Vector2 dimensions, Ogre::String material = "", Ogre::String caption = "", bool autoAdd = true);
            OverlayContainer* createMousePointer(Vector2 dimensions, Ogre::String material);
                
    protected:
            Overlay* mO;                        // Main sheet overlay
            vector<Window*>WN;                    // Windows
            Window *mXW;                        // Window to destroy
            OverlayContainer* mMP;                // Mouse Pointer Overlay
            String mFont;
            uint mFontSize;
            uint wc, bc, tc;
    };

    class Window {
        public:
            friend class Button;
            friend class TextInput;
            friend class GUI;
        
            Button*        createButton(Vector4 Dimensions, String Material, String Text, Callback callback);
            TextInput*    createTextInput(Vector4 Dimensions, String Material, String Value, uint length);
            void        createStaticText(Vector4 Dimensions, String Text);
        
            void hide(){
                mO->hide();
            }
            
            void show(){
                mO->show();
            }
            
            bool isVisible() {
                return mO->isVisible();
            }
        protected:
            Window(Vector4 Dimensions, String Material, wt type, String caption, GUI *gui);
            ~Window();
            
            bool check(uint x, uint y, bool LMB); bool checkKey(String key, uint x, uint y);
            TextInput* mATI;                // Active TextInput
            Button *mRZ,*mAB,*mTB;            // Resizer, ActiveButton, Titlebar
            uint x,y,w,h;                    // Dimensions
            GUI *mGUI;                        // mGUI pointer
            OverlayContainer* mO;            // Overlay
            vector<BetaGUI::Button*> mB;    // Buttons
            vector<BetaGUI::TextInput*> mT;    // TextInputs
    };

    class BetaGUIListener {
        public:
            virtual void onButtonPress(Button *ref) = 0;
    };

    class Callback {
        public:
            friend class Window;
            friend class Button;
            
            Callback() {
                t=0;
            }
            
            Callback( void(*functionPointer)(Button *ref) ) {
                t=1;
                fp = functionPointer;
            }

            Callback(BetaGUIListener *l){
                t = 2;
                LS = l;
            }
        protected:
            uchar t;                    // Type of callback: 0 - None, 1 - FunctionPointer 2 - GUIListener, 3 - Move Window, 4 - Resize
            void(*fp)(Button *ref);        // Function pointer (if 1)
            BetaGUIListener *LS;        // GuiListener (if 2)
    };

    class Button {
        public:
            friend class Window;
        
            Button(Vector4 Dimensions, String Material, String Text, Callback callback, Window *parent);
            ~Button() {
                mO->getParent()->removeChild(mO->getName());
                mCP->getParent()->removeChild(mCP->getName());
            }
        protected:
            void activate(bool a) {
                if (!a && mmn!="")
                mO->setMaterialName(mmn);
                if (a && mma!="")
                    mO->setMaterialName(mma);
            }
            bool in(uint mx, uint my, uint px, uint py) {
                return ( !(mx >= x + px && my >= y + py)) || ( ! (mx <= x + px + w && my <= y + py + h) );
            }
            OverlayContainer* mO,*mCP;            // Main Overlay and Caption
            String mmn,mma;                        // MaterialName Normal, MaterialName Active
            BetaGUI::Callback callback;            // Callback to use
            uint x,y,w,h;                        // Dimensions.
    };
    
    class TextInput {
        public:
            friend class Window;
            
            TextInput(Vector4 Dimensions, String Material, String Value, uint length, Window *parent);
            ~TextInput(){}
            String getValue() {
                return value;
            }
            
            void setValue(String v) {
                mCP->setCaption(value=v);
            }

        protected:
            bool in(uint mx, uint my, uint px, uint py) {
                return ( !(mx >= x + px && my >= y + py)) || ( ! (mx <= x + px + w && my <= y + py + h) );
            }
            OverlayContainer* mO,*mCP;
            String mmn, mma, value;
            uint x,y,w,h,length;
    };
} // End of Namespace

/*** Optional Seperate Code that goes into a .cpp part : Cut downwards and paste  ***/
using namespace Ogre;
using namespace std;
namespace BetaGUI {
    GUI::GUI(String font, uint fontSize)
        :mXW(0),
         mMP(0),
         mFont(font),
         mFontSize(fontSize),
         wc(0),
         bc(0),
         tc(0)
    {
            mO = OverlayManager::getSingleton().create("BetaGUI");
            mO->show();
    }
    
    GUI::~GUI() {
        for(uint i=0;i < WN.size();i++)
            delete WN[i];
        WN.clear();
    }
    
    bool GUI::injectMouse(uint x, uint y, bool LMB) {
        
        if (mMP)
            mMP->setPosition(x,y);

        if (mXW) {
            for(vector<Window*>::iterator i=WN.begin();i!=WN.end();i++) {
                if(mXW==(*i)) {
                    delete mXW;
                    WN.erase(i);
                    mXW=0;
                    return false;
                }
            }
        }

        for(uint i=0;i<WN.size();i++) {
            if(WN[i]->check(x,y,LMB)) {
                return true;
            }
        }

        return false;
    }    
    bool GUI::injectKey(String key, uint x, uint y) {
        for(uint i=0;i<WN.size();i++) {
            if(WN[i]->checkKey(key,x,y)) {
                return true;
            }
        }
        return false;
    }
    
    void GUI::injectBackspace(uint x, uint y) {
        injectKey("!b", x, y);
    }

    OverlayContainer* GUI::createOverlay(String name, Vector2 position, Vector2 dimensions, String material, String caption, bool autoAdd) {
        String type="Panel";
        
        if (caption!="")
            type="TextArea";
        
        OverlayContainer* e=static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement(type, name));

        e->setMetricsMode(Ogre::GMM_PIXELS);
        e->setDimensions(dimensions.x, dimensions.y);
        e->setPosition(position.x, position.y);

        if (material!="")
            e->setMaterialName(material);
        
        if (caption!="") {
            e->setCaption(caption);
            e->setParameter("font_name",mFont);
            e->setParameter("char_height",StringConverter::toString(mFontSize));
        }

        if(autoAdd) {
            mO->add2D(e);
            e->show();
        }
        
        return e;
    }

    OverlayContainer* GUI::createMousePointer(Vector2 d, String m) {
        Overlay* o = OverlayManager::getSingleton().create("BetaGUI.MP");
        o->setZOrder(649);
        mMP = createOverlay("bg.mp", Vector2(0,0), d, m, "", false);
        o->add2D(mMP);
        o->show();
        mMP->show();
        return mMP;
    }

    Window* GUI::createWindow(Vector4 Dimensions, String Material, wt type, String caption) {
        Window* window = new BetaGUI::Window(Dimensions, Material, type, caption, this);
        WN.push_back(window);
        return window;
    }

    Window::Window(Vector4 Dimensions, String Material, wt t, String caption, GUI *gui)
        : x(Dimensions.x), 
          y(Dimensions.y),
          w(Dimensions.z),
          h(Dimensions.w),
          mGUI(gui),
          mTB(0),
          mRZ(0),
          mATI(0),
          mAB(0) 
    {
        mO = gui->createOverlay("BetaGUI.w" + StringConverter::toString(gui->wc++), Vector2(Dimensions.x,Dimensions.y), Vector2(Dimensions.z,Dimensions.w), Material); 
        if (t >= 2) {
            Callback c;c.t=4;
            mRZ=createButton(Vector4(Dimensions.z-16,Dimensions.w-16,16,16),Material+".resize", "",c);
        }

        if (t == 1 || t == 3) {
            Callback c;c.t=3;
            mTB = createButton(Vector4(0,0,Dimensions.z,22),Material + ".titlebar", caption, c);
        }

    }

    Window::~Window() {
        for(uint i=0;i<mB.size();i++)
            delete mB[i];
        
        for(uint i=0;i<mT.size();i++)
            delete mT[i];
        
        mGUI->mO->remove2D(mO);
    }

    Button* Window::createButton(Vector4 D, String M, String T, Callback C) {
        Button *x = new Button(D, M, T, C, this);
        mB.push_back(x);
        return x;
    }

    Button::Button(Vector4 Dimensions, String m, String Text, Callback cb, Window *parent)
        : x(Dimensions.x),
          y(Dimensions.y),
          w(Dimensions.z),
          h(Dimensions.w),
          mmn(m),
          mma(m)
    {
    
        Ogre::ResourcePtr ma=Ogre::MaterialManager::getSingleton().getByName(mmn + ".active");
        if(!ma.isNull())
            mma += ".active";
        
        mO = parent->mGUI->createOverlay(parent->mO->getName() + "b" + StringConverter::toString(parent->mGUI->bc++), Vector2(x,y),Vector2(w,h),m,"",false);
        mCP = parent->mGUI->createOverlay(mO->getName() + "c",Vector2(4,(h - parent->mGUI->mFontSize) / 2),Vector2(w, h),"",Text,false);
        parent->mO->addChild(mO);
        mO->show();
        mO->addChild(mCP);
        mCP->show();
        callback = cb;
    }

    TextInput* Window::createTextInput(Vector4 D, String M, String V, uint L) {
        TextInput *x = new TextInput(D,M,V,L,this);
        mT.push_back(x);
        return x;
    }

    void Window::createStaticText(Vector4 D, String T) {
        OverlayContainer* x = mGUI->createOverlay(mO->getName() + StringConverter::toString(mGUI->tc++),Vector2(D.x,D.y),Vector2(D.z,D.w),"", T,false);
        mO->addChild(x);
        x->show();
    }
    
    TextInput::TextInput(Vector4 D, String M, String V, uint L, Window *P)
        : x(D.x),y(D.y),w(D.z),h(D.w),value(V),mmn(M), mma(M), length(L) 
    {
        ResourcePtr ma=Ogre::MaterialManager::getSingleton().getByName(mmn + ".active");
        if(!ma.isNull())
            mma += ".active";

        mO=P->mGUI->createOverlay(P->mO->getName() + "t" + StringConverter::toString(P->mGUI->tc++) ,Vector2(x,y),Vector2(w,h),M,"",false);
        mCP=P->mGUI->createOverlay(mO->getName() + "c",Vector2(4,(h - P->mGUI->mFontSize) / 2),Vector2(w,h),"",V,false);
        P->mO->addChild(mO);
        mO->show();
        mO->addChild(mCP);
        mCP->show();
    }
    
    bool Window::checkKey(String k, uint px, uint py) {
        
        if (!mO->isVisible())
            return false;

        if(!(px>=x&&py>=y)||!(px<=x+w&&py<=y+h))return false;
        
        if(mATI == 0)
            return false;
        
        if(k=="!b") {
            mATI->setValue(mATI->value.substr(0,mATI->value.length()-1));
            return true;
        }

        if(mATI->value.length() >= mATI->length)
            return true;
        
        mATI->mCP->setCaption(mATI->value+=k);
        return true;
    }
    
    bool Window::check(uint px, uint py, bool LMB) {
        
        if (!mO->isVisible())
            return false;
        
        if (!(px >= x && py >= y) || !(px <= x + w && py <= y + h))    {
            if (mAB) {
                mAB->activate(false);
            }
            return false;
        }
        
        if (mAB) {
            mAB->activate(false);
        }

        for (uint i=0;i < mB.size();i++) {
            if (mB[i]->in(px,py,x,y))
                continue;

            if (mAB) {
                mAB->activate(false);
            }

            mAB=mB[i];
            mAB->activate(true);

            if (!LMB)
                return true;

            if(mATI) {
                mATI->mO->setMaterialName(mATI->mmn);
                mATI=0;
            }

            switch(mAB->callback.t) {
                default: return true;
                case 1: 
                    mAB->callback.fp(mAB);
                    return true;
                case 2:
                    mAB->callback.LS->onButtonPress(mAB);
                    return true;
                case 3:
                    mO->setPosition(x=px-(mAB->w/2),y=py-(mAB->h/2));
                    return true;
                case 4:
                    mO->setDimensions(w=px-x+8,h=py-y+8);
                    mRZ->mO->setPosition(mRZ->x=w-16,mRZ->y=h-16);
                    if(mTB){
                        mTB->mO->setWidth(mTB->w=w);
                    }
                return true;
            }

        }

        
        if (!LMB)
            return true;

        for (uint i=0;i<mT.size();i++) {
    
            if (mT[i]->in(px,py,x,y))
                continue;

            mATI=mT[i];
            mATI->mO->setMaterialName(mATI->mma);
            return true;
        }
        
        if(mATI) {
            mATI->mO->setMaterialName(mATI->mmn);
            mATI=0;
        }
        
        return true;
    }

} // End of Betajaen's GUI. Normal programming can resume now.

Usage

The usage is very simple. You create the main instance when you start initilasing your application as so:

mGUI = new BetaGUI::GUI("MyFontName",MyFontSize);


And delete it when shutting down:

delete mGUI;


To inject actions into the GUI, in your InputListener you'll need to handle four-ish actions:

mGUI->injectKey(<character>, <pointer x>, <pointer y>);
mGUI->injectBackspace(<pointer x>, <pointer y>); //
mGUI->injectMouse(<pointer x>, <pointer y>, true); // Mouse key down.
mGUI->injectMouse(<pointer x>, <pointer y>, false); // Mouse key not down.


Now to create a window with a few things is just as easy to. Just remember to make sure your material images are the same size as your windows, buttons and textinputs else they will be stretched.

BetaGUI::Window* window = mGUI->createWindow(Vector4(100,100,300,100), "my window material", BetaGUI::RESIZE_AND_MOVE, "Magical Doubler");
window->createStaticText(Vector4(4,22,198,40), "Type in a number and I'll double it!");
BetaGUI::Button* mDoubleIt = window->createButton(Vector4(108,50,104,24), "my button material", "Go on then!", BetaGUI::Callback(myCallback));
BetaGUI::TextInput* mAmount = window->createTextInput(Vector4(4,50,104,24), "my textinput material", "1", 3);


And to finalise it all, you'll need a callback

class myCallbackOrMainClass : public public BetaGUI::BetaGUIListener {
  ...
  void onButtonPress(BetaGUI::Button *ref) {
     if (ref == mDoubleIt)
    cout << "The answer is:" << StringConverter::parseUnsignedInt(mAmount->getValue()) * 2 << endl;
  }
  ...
}


Some notes when setting up:

  • If your window has a resize option, you will need to create a material called <windowmaterialname>.resize, The image should be 16,16 pixels.
  • If your window has a titlebar option, you will need to create a material called <windowmaterialname>.titlebar, The image should be x,22 pixels.
  • All of your buttons can have active states just create an extra material with .active at the end, it even applies to resize or titlebars.
  • InputText must have a material.


That's it!

C# Version with MOgre

Content moved to MogreBetaGUI.

Perl Version

I ported BetaGUI version 016 to Perl:
browse here.

As an example, I ported Intermediate Tutorial 2,
Intermediate Tutorial 3, and
Intermediate Tutorial 4
(the ones where you place robots with a -CEGUI mouse cursor):
tute 2,
tute 3,
tute 4

Note: you should probably also know there are some (incomplete)
Perl bindings for OGRE

Addons

Further iterations and versions of BetaGUI can be found HERE

Betajaen's GUI Resources

BetaGUI_example.png


 Plugin disabled
Plugin attach cannot be executed.


Simple dark transparent look for all GUI parts with active states.

Copy the ZIP to your resources directory and append the following to your resources.cfg

Zip=bguires.zip


Use the following settings when creating your GUI for the correct look

  • Pointer Material: "bgui.pointer" Size(32,32)
  • Window Material: "bgui.window"
  • Button Material: "bgui.button" Size(72,22)
  • TextInput Material: "bgui.textinput" Size(100,22) Length(10)

re

<HR>
Creative Commons Copyright -- Some rights reserved.


THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

  • "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
  • "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  • "Licensor" means the individual or entity that offers the Work under the terms of this License.
  • "Original Author" means the individual or entity who created the Work.
  • "Work" means the copyrightable work of authorship offered under the terms of this License.
  • "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
  • "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.

2. Fair Use Rights

Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

3. License Grant

Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

  • to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
  • to create and reproduce Derivative Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
  • For the avoidance of doubt, where the work is a musical composition:
    • Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    • Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
    • Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).


The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

4. Restrictions

The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

  • You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
  • You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
  • If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability.

EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. Termination

  • This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
  • Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.

8. Miscellaneous

  • Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
  • Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
  • If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  • No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
  • This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.