Results 1 to 4 of 4

Thread: GUI Direct Problem (still)

  1. #1
    Lesser Knight
    Join Date
    Sep 2010
    Location
    Germany
    Posts
    36

    Default GUI Direct Problem (still)

    Hello,

    I still have the same problem: I just don't know how to draw a button or lineedit on a CL_DisplayWindow.
    The new example code looks simpler than the old one but I just can't figure it out.

    Can anyone please show me an easy example where just a button is drawn on a CL_DisplayWindow?

    Thank you

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Your right, there isn't a simple example to draw a GUI button to a CL_DisplayWindow !

    I'll have a look in the next couple of days.

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Name:  NewBasic2D.png
Views: 11
Size:  31.5 KB

    Patch, applied from the Basic2D example:

    Code:
    Index: Sources/basic2d.cpp
    ===================================================================
    --- Sources/basic2d.cpp	(revision 5541)
    +++ Sources/basic2d.cpp	(working copy)
    @@ -30,6 +30,12 @@
     #include "precomp.h"
     #include "basic2d.h"
     
    +class RootWindow : public CL_GUIComponent
    +{
    +public:
    +	RootWindow(CL_GUIManager *gui, const CL_Rect &gui_position) : CL_GUIComponent(gui, CL_GUITopLevelDescription("Root Window", gui_position, false)) {}
    +};
    +
     // The start of the Application
     int Basic2D::start(const std::vector<CL_String> &args)
     {
    @@ -43,6 +49,20 @@
     
     	CL_DisplayWindow window(desc);
     
    +
    +	// Set up GUI
    +	CL_String theme;
    +	if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
    +		theme = "../../../Resources/GUIThemeAero";
    +	else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
    +		theme = "../../../Resources/GUIThemeBasic";
    +	else
    +		throw CL_Exception("No themes found");
    +
    +	CL_GUIWindowManagerTexture wm(window);
    +	CL_GUIManager gui(wm, theme);
    +
    +
     	// Connect the Window close event
     	CL_Slot slot_quit = window.sig_window_close().connect(this, &Basic2D::on_window_close);
     
    @@ -59,6 +79,14 @@
     	float ypos = 0.0f;
     	float ydir = 0.3f;
     
    +	button_counter = 0;
    +
    +	RootWindow root_window(&gui, CL_Rect(150, 150, CL_Size(150, 40)));
    +	CL_PushButton button( &root_window );
    +	button.set_geometry(CL_Rect(0, 0, 150, 40));
    +	button.func_clicked().set(this, &Basic2D::on_button_clicked, &button);
    +	button.set_text("Press Me!");
    +
     	unsigned int last_time = CL_System::get_time();
     
     	// Run until someone presses escape
    @@ -122,6 +150,10 @@
     
     		gc.pop_cliprect();
     
    +		wm.process();
    +		wm.draw_windows(gc);
    +
    +
     		// Flip the display, showing on the screen what we have drawed
     		// since last call to flip()
     		window.flip(1);
    @@ -149,3 +181,11 @@
     }
     
     
    +
    +void Basic2D::on_button_clicked(CL_PushButton *button)
    +{
    +	button_counter++;
    +
    +	CL_String text(cl_format("Pressed: %1", button_counter));
    +	button->set_text( text);
    +}
    Index: Sources/basic2d.h
    ===================================================================
    --- Sources/basic2d.h	(revision 5541)
    +++ Sources/basic2d.h	(working copy)
    @@ -38,7 +38,9 @@
     private:
     	void on_input_up(const CL_InputEvent &key, const CL_InputState &state);
     	void on_window_close();
    +	void on_button_clicked(CL_PushButton *button);
     
     private:
    +	int button_counter;
     	bool quit;
     };
    Index: Sources/precomp.h
    ===================================================================
    --- Sources/precomp.h	(revision 5541)
    +++ Sources/precomp.h	(working copy)
    @@ -3,4 +3,5 @@
     #include <ClanLib/core.h>
     #include <ClanLib/application.h>
     #include <ClanLib/display.h>
    +#include <ClanLib/gui.h>
     #include <cmath>
    Index: Sources/program.cpp
    ===================================================================
    --- Sources/program.cpp	(revision 5541)
    +++ Sources/program.cpp	(working copy)
    @@ -70,6 +70,9 @@
     			CL_SetupGL setup_gl;
     		#endif
     
    +		CL_SetupGUI setup_gui;
    +
    +
     		// Start the Application
     		Basic2D app;
     		int retval = app.start(args);

    The source...

    http://esoteric.clanlib.org/~rombust/GUI_Basic2D.zip


    The patch...

    Basic2D_GUI.patch

  4. #4
    Lesser Knight
    Join Date
    Sep 2010
    Location
    Germany
    Posts
    36

    Default

    Many thanks, rombust!

Similar Threads

  1. I need a direct link to daisypark
    By jimbobbucky in forum Funeral Quest
    Replies: 5
    Last Post: 09-20-2003, 09:50 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •