Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

More about styles

Changing style

If you want to use one of the style listed below you should define SJGUI_USE_STYLE directive whith the name of the style, before including <sjgui/sjgui.h>
 // this will enable modern style
    #define SJGUI_USE_STYLE modern
    #include <sjgui/sjgui.h>
If you want to use your own style you should provide default values for classes. their names are standard and are also mentioned in Lesson 7. The defaults for styles could be found in globals.cpp. The following is an example of user defined style, which does not do anything at all, but can be used as a template for your own designes. This is the code from "examples/own_style.cpp":
// This macro should be defined before you include sjgui header files
// Comment it to use modern style, or change to classic, 
// if you want to see how test dialog is drawn in a classic style.
#define SJGUI_USE_STYLE own_style

// Now we can include all resources of the sjgui library
#include <sjgui/sjgui.h>

namespace sjgui
{
    // Controls drawn with your own style.
    namespace own_style
    {
        /* Base class the sytle. */
        class CWndCtrl : public CWndCtrlBase
        {
        public:
            /* This class usually handles global parameters as
            enabled/disabled appearance or focused/unfocused, so we would
            like to draw not only before, but also after child windows are drawn.
            */
            virtual void Draw()
            {
                // ... Draw background here if needed
                CWndCtrlBase::Draw();
                // ... add something else, if you wish.
            }
        };
        /* Label. */
        template<class Tbase=CWndCtrl>
            class CLabelTmpl: public CLabelCtrlTmpl<Tbase>{};
        /* Text. */
        template<class Tbase=CWndCtrl>
            class CTextTmpl : public CTextCtrlTmpl<Tbase>{};
        /* Background plane. */
        template<class Tbase=CWndCtrl>
        class CPlaneWndTmpl : public CPlaneWndCtrlTmpl<Tbase>
        {
        public:
            /* Draw it. */
            virtual void OnDraw()
            {
                // ... draw here
                CPlaneWndCtrlTmpl<Tbase>::OnDraw();
            }
        };
        /* Horizontal and vertical slider. */
        template<class Tbase=CWndCtrl>
            class CSliderTmpl : public CSliderCtrlTmpl<Tbase>{};
        /* Edit field. */
        template<class Ttext=CText>
            class CEditTmpl : public CEditCtrlTmpl<Ttext>{};
        /* Check box. */
        template<class Tlabel=CLabel,class Tbase=CWndCtrl>
            class CCheckBoxTmpl : public CButtonCtrlTmpl<Tlabel,Tbase>
        {
        protected:
            // you should position label in a proper place
            virtual void OnUpdatePos()
            {
                CButtonCtrlTmpl<Tlabel,Tbase>::OnUpdatePos();
                // this is an example
                m_Label.PosWnd(GetClAr());
            }
        public:
            CCheckBoxTmpl():CButtonCtrlTmpl<Tlabel,Tbase>()
            {
                // change text
                m_Label.SetText("ChBox");
                m_Label.SetAlign(ALIGN_LEFT,ALIGN_CENTER);
            }
            virtual void OnDraw()
            {
                CButtonCtrlTmpl<Tlabel,Tbase>::OnDraw();
            }
        };
        /* Push button. */
        template<class Tlabel=CLabel,class Tbase=CWndCtrl>
            class CButtonTmpl : public CButtonCtrlTmpl<Tlabel,Tbase>
        {
        protected:
            virtual void OnUpdatePos()
            {
                CButtonCtrlTmpl<Tlabel,Tbase>::OnUpdatePos();
                m_Label.PosWnd(GetClAr());
            }
        public:
            CButtonTmpl():CButtonCtrlTmpl<Tlabel,Tbase>()
            {
                SetLabel("Button");
            }
            virtual void OnDraw()
            {
                CButtonCtrlTmpl<Tlabel,Tbase>::OnDraw();
            }
        };
        /* Text box with. */
        template<class Ttext=CText,class Tslider=CSlider, class Tbase=CWndCtrl>
            class CTextBoxTmpl : public CTextBoxCtrlTmpl<Ttext,Tslider,Tbase>{};
        /* Panel class. */
        template<class Tslider=CSlider,class Tbase=CWndCtrl>
            class CPanelTmpl : public CPanelCtrlTmpl<Tslider,Tbase>{};
        /* Stack panel class. */
        template<class Tslider=CSlider,class Tbase=CWndCtrl>
            class  CStackPanelTmpl: public CStackPanelCtrlTmpl<Tslider,Tbase>{};
        /* Squeeze panel class. */
        template<class Tslider=CSlider,class Tbase=CWndCtrl>
            class CSqueezePanelTmpl : public CSqueezePanelCtrlTmpl<Tslider,Tbase>{};
        /* Dialog. */
        template<class Tbutton=CButton,class Tcaption=CLabel,class TclientPanel=CPanel, class TbuttonPanel=CStackPanel, class Tbase=CPlaneWnd>
            class CDlgTmpl : public CDlgCtrlTmpl<Tbutton,Tcaption,TclientPanel,TbuttonPanel,Tbase>{};
        /* Friendly name wrappers */
        /* Text label. */
        typedef CLabelTmpl<> CLabel;
        /* Text. */
        typedef CTextTmpl<> CText;
        /* Push button with the default label. */
        typedef CButtonTmpl<> CButton;
        /* Dialog window with a thin border. */
        typedef CPlaneWndTmpl<> CPlaneWnd;
        /* Slider. */
        typedef CSliderTmpl<> CSlider;
        /* Text with horizontal and vertical sliders. */
        typedef CTextBoxTmpl<> CTextBox;
        /* Edit field .*/
        typedef CEditTmpl<> CEdit;
        /* Simple panel class. */
        typedef CPanelTmpl<> CPanel;
        /* Stack panel class. */
        typedef CStackPanelTmpl<> CStackPanel;
        /* Squeeze panel class. */
        typedef CSqueezePanelTmpl<> CSqueezePanel;
        /* Dialog with CButtons and CLabel. */
        typedef CDlgTmpl<> CDlg;
        /* Check box with a label. */
        typedef CCheckBoxTmpl<> CCheckBox;
    } // namespace own_style
} // namespace sjgui

// Default parameters for windows
// Note That they must stay in cpp file and can not to be moved to h
namespace sjgui
{
    namespace own_style
    {
        // CWnd
        // Default minimum size of a control.
        CWnd::CSize     def_wnd_min_size(0,0);
        // CWndCtrl
        // Default CWndCtrl border light color.
        GLfloat def_wnd_ctrl_border_light_color[4]={1.0f,1.0f,1.0f,1.0f};
        // Default CWndCtrl border dark color.
        GLfloat def_wnd_ctrl_border_dark_color[4]={0.3f,0.3f,0.3f,0.3f};
        // Default CWndCtrl border color.
        GLfloat def_wnd_ctrl_border_color[4]={1.0f,1.0f,1.0f,1.0f};
        // Default CWndCtrl shadow color.
        GLfloat def_wnd_ctrl_shadow_color[4]={0.3f,0.3f,0.3f,0.5f};
        // Default CWndCtrl background color.
        GLfloat def_wnd_ctrl_bg_color[4]={0.3f,0.5f,0.7f,1.0f};
        // Default CWndCtrl background color when selection.
        GLfloat def_wnd_ctrl_bg_sel_color[4]={0.6f,0.5f,0.7f,1.0f};
        // CButtonTmpl and CCheckBoxTmpl
        // default button size
        CWnd::CSize     def_button_size(100,30);
        // CDlgTmpl
        // Default caption color
        GLfloat         def_dlg_caption_color[4]    ={0.1f,0.9f,1.0f,1.0f};
        // Default text color
        GLfloat         def_dlg_button_text_color[4]={0.1f,0.9f,1.0f,1.0f};
        // Default minimum size for dialog
        CWnd::CSize     def_dlg_min_size(240,50);
        // Default distance of the button from the edge
        int             def_dlg_btn_dist            =5;
        // Default distance between buttons
        int             def_dlg_btn_offset          =5;
        // Default height of the button panel
        int             def_dlg_btn_panel_height    =40;
        // CDlgWnd
        // Default dlgwnd border color.
        GLfloat         def_dlg_wnd_border_color[4] ={0.5f,0.5f,0.5f,1.0f};
        // Default dlgwnd background color.
        GLfloat         def_dlg_wnd_bg_color[4]     ={0.1f,0.5f,0.5f,1.0f};
        // Default dlgwnd background color when selected.
        GLfloat         def_dlg_wnd_bg_sel_color[4] ={0.11f,0.51f,0.51f,1.0f};
        // CEditTmpl
        // Default font size for edit.
        int             def_edit_font_size          =10;
        // Default blink period for edit.
        int             def_edit_blink_period       =750;
        // Default minimum size of a control.
        CWnd::CSize     def_edit_size(100,12);
        // CLabel
        // Default label text color.
        GLfloat         def_label_color[4]          ={1.0f,1.0f,1.0f,1.0f};
        // Default label horizontal alignment.
        CWnd::eAligns   def_label_hor_aling         =CWnd::ALIGN_CENTER;
        // Default label vertical alignment.
        CWnd::eAligns   def_label_ver_aling         =CWnd::ALIGN_CENTER;
        // CSlider
        // Default slider size.
        CWnd::CSize     def_slider_size(16,16);
        // Default slider lengths.
        float           def_slider_length           =0.2f;
        // Default slider orientation.
        CWnd::eOrient def_slider_orientation=CWnd::HORIZONTAL;
        // CText
        // Default text color
        GLfloat         def_text_color[4]           ={1.0f,1.0f,1.0f,1.0f};
        // CTextBoxTmpl
        // Default text box text color.
        GLfloat         def_text_box_text_color[4]  ={0.8f,1.0f,0.8f,1.0f};
        // Default text box font size.
        int             def_text_box_fonst_size     =12;
    } // namespace own_style
} // namespace sjgui

typedef CDlgTmpl<sjgui::CButton,sjgui::CLabel,sjgui::CSqueezePanel> CMyDlg;

// Dialog with controls
class CTestDlg: public CMyDlg
{
    sjgui::CEdit    m_edt;
    sjgui::CTextBox m_txb;
    sjgui::CCheckBox    m_chb;
public:
    CTestDlg():CMyDlg()
    {
        // register children
        RegisterToClientArea(&m_edt);
        RegisterToClientArea(&m_txb);
        RegisterToClientArea(&m_chb);
        // setup panel
        m_pnlClientArea.SetVertMode();
        SetSize(200,200);
        m_txb.SetSize(100,100);
        m_txb.LoadTextFromFile("own_style.cpp");
        m_txb.SetSelectLines();
    }
};

// Testing widgets
class CSpcWnd : public sjgui::CWnd
{
    // dialog with all controls
    CTestDlg        m_dlg;
    // button to switch it on and off
    sjgui::CButton  m_btn;
public:
    CSpcWnd():CWnd(){RegisterChild(&m_btn);RegisterChild(&m_dlg);m_dlg.Show();}
    virtual void OnReshape(){m_btn.ToCenter();m_dlg.ToCenter();}
    virtual void OnKeyUp(int &iKey)
    {
        // I want to see how it looks in disabled mode
        if(m_dlg.IsVisible() && !m_dlg.IsEnabled())
            m_dlg.Reset();
        // show or hide dialog
        if(m_btn.IsPushed())
        {
            m_btn.Reset();
            m_dlg.Show(!m_dlg.IsVisible());
        }
    }
    virtual void OnDraw()
    {
        Animate();
        SET_GL_FOR_GUI_DRAW;
    }
}; // end of CSpcWnd class

// This is the way you create window and let it be running.
// Once this is done, all modifications required by sjgui, 
// could be done within space window class CSpcWnd
int main(int argc, char* argv[])
{
    // first thing we should do, is to create 
    // an instance of our space window.
    CSpcWnd SpcWnd;
    // Position the window,
    // Note that we position actuall drawing area, and there is
    // a wondow caption bar on top of it.
    SpcWnd.PosWnd(20,50,320,240);
    // Then we create a window which will be assigned to our
    // space window class.
    // Given parameters are the name of the window
    // (I am using name of the program, which is stored in arv[0])
    // and the class, which will receive all events.
    // Function reruns non zero value in case of the success
    if(sjgui::Create(argv[0],&SpcWnd))
    {
        // Run it. Now all events are transferred to our class.
        // And when we are done, program will be finished.
        sjgui::GlobalMainLoop();
    }
    else
        // Print error message if something was wrong.
        printf("Could not create opengl window.\n");
    return 0;
} // the end of main
sjgui logo
Quick Links:

 News
 Description
 Screen Shots
 Projects
 Downloads
 Source Code
 Help/FAQ
 Want to help?
 Credits
 Disclaimer


Documentation:

 Documentation
 Reference
 Lessons


Useful links:

sjcomp logo
sjcomp

opengl logo

nehe logo

SourceForge.net Logo

Last modified:


Started by Alexander Shyrokov. Generated at Wed Apr 28 12:31:05 2004 for the sjgui by doxygen 1.3.1. SourceForge.net Logo