Results 1 to 9 of 9

Thread: Custom InputBox

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

    Default Custom InputBox

    Hey,

    I'm trying to make a custom InputBox class but I'm stuck.



    When I try to set the func_close() of the window vc says that:

    error C2660: 'CL_Callback_0<RetVal>::set' : function does not take 3 arguments

    IntelliSense: no instance of overloaded function "CL_Callback_0<RetVal>::set [with RetVal=bool]"


    CInputBox.hpp
    Code:
    #include "includes.hpp"
    
    class CInputBox
    {
        private:
    		CL_Window *m_pWin;
    		CL_PushButton *m_pButton;
    		CL_LineEdit *m_pEdit;
    
    		CL_String m_sTheme;
    		CL_GUIManager *m_pGUI;
    
    		CL_String m_sCaption;
    		CL_String m_sPrompt;
    		CL_String m_sInput;
    
    		CL_String on_button_clicked( void );
    		void on_close( CL_Window *pWin );
    
        public:
    		CInputBox( void );
    
    		void Set( CL_String sCaption, CL_String sPrompt );
    		void ShowDialog( void );
    };


    CInputBox.cpp
    Code:
    #include "CInputBox.hpp"
    
    CInputBox::CInputBox( void )
    {
    	if (CL_FileHelp::file_exists("Resources/GUIThemeAero/theme.css"))
    		m_sTheme = "Resources/GUIThemeAero";
    	else if (CL_FileHelp::file_exists("Resources/GUIThemeBasic/theme.css"))
    		m_sTheme = "Resources/GUIThemeBasic";
    	else
    		throw CL_Exception("No themes found for CInputBox!");
    
    	m_pGUI = new CL_GUIManager( m_sTheme );
    
    	CL_DisplayWindowDescription desc;
    
    	desc.set_allow_resize( true );
    	desc.set_title( m_sCaption );
    	desc.set_position( CL_Rect( 200, 200, 500, 350), false );
    
    	m_pWin = new CL_Window( m_pGUI, desc );
    	m_pWin->func_close().set( this, &CInputBox::on_close, &m_pWin ); <--- Error here
    	
    }
    
    
    
    CL_String CInputBox::on_button_clicked( void )
    {
    	m_sInput = m_pEdit->get_text();
    
    	return( m_sInput );
    }

    But when I'm doing it like this it works:


    Code:
    #include "includes.hpp"
    #include "CMain.hpp"
    #include "CProgram.hpp"
    
    int CProgram::start( const std::vector<CL_String> &args )
    {
    	
    	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_GUIManager gui( theme );
    
    	CL_String sCaption;
    	CL_String sPrompt;
    	CL_String sInput;
    
    	CL_DisplayWindowDescription desc;
    	desc.set_allow_resize( true );
    	desc.set_title( sCaption );
    	desc.set_position( CL_Rect( 200, 200, 500, 350), false );
    	
    	CL_Window window( &gui, desc );
    	window.func_close().set( this, &CProgram::on_close, &window );
    
    	CL_Rect client_area = window.get_client_area();
    
    	CL_PushButton button( &window );
    	button.set_geometry( CL_Rect( client_area.left + 95, client_area.top + 70, CL_Size(100, 35) ) );
    	button.func_clicked().set(this, &CProgram::on_button_clicked);
    	button.set_text( "OK" );
    
    	edit = new CL_LineEdit( &window );
    	edit->set_geometry( CL_Rect( client_area.left + 65, client_area.top + 35, CL_Size( 160, 25 ) ) );
    
    	CL_Label label( &window );
    	label.set_text( sCaption );
    	label.set_geometry( CL_Rect( client_area.left + 110, client_area.top + 10, CL_Size( 160, 25 ) ) );
    
    	CL_InputDevice board = window.get_ic().get_keyboard();
    
    	m_bRunning = true;
    
    	while( m_bRunning )
    	{
    	    gui.exec(false);
    	}
    
    	return( 0 );
    }
    
    void CProgram::on_button_clicked( void )
    {
           // Do something
    }
    
    bool CProgram::on_close( CL_Window *win )
    {
    	win->exit_with_code( 0 );
    	m_bRunning = false;
    
    	return( true );
    }


    Thanks!

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

    Default

    Code:
    	m_pWin = new CL_Window( m_pGUI, desc );
    	m_pWin->func_close().set( this, &CInputBox::on_close, &m_pWin ); <--- Error here
    Try changing "&m_pWin" to "m_pWin"

    You are passing the address of the pointer variable, not the pointer itself.

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

    Default

    I did but it didn't change anything.
    Still the same error.

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

    Default

    Good question!

    It works passing integers and even pointers to integers, but not pointer to classes

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

    Default

    In callback_v1.h, you have:
    Code:
    	template<class InstanceClass, typename UserData>
    	void set(InstanceClass *instance, void (InstanceClass::*function)(P1, UserData), const UserData &user_data)
    	{
    		impl = CL_SharedPtr< CL_Callback_Impl_v1<P1> >(new CL_Callback_Impl_v1_member_user<P1, InstanceClass, UserData>(instance, function, user_data));
    	}
    If you add the following after it:
    Code:
    template<class InstanceClass, typename UserData>
    	void set(InstanceClass *instance, void (InstanceClass::*function)(P1, UserData), const UserData *user_data)
    	{
    		impl = CL_SharedPtr< CL_Callback_Impl_v1<P1> >(new CL_Callback_Impl_v1_member_user<P1, InstanceClass, UserData>(instance, function, user_data));
    	}
    It works.

    Why? Who knows .... a ClanLib and C++ expert is required

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

    Default

    Thanks for your reply.

    I tried it but it didn't work.
    I think it's because the error is in callback_0.h and not callback_1.h

    IntelliSense: no instance of overloaded function "CL_Callback_0<RetVal>::set [with RetVal=bool]" matches the argument list

    So I tried it with the v0 like this:

    Code:
    	template<class InstanceClass, typename UserData>
    	void set(InstanceClass *instance, void (InstanceClass::*function)(P1, UserData), const UserData *user_data)
    	{
    		impl = CL_SharedPtr< CL_Callback_Impl_v1<P1> >(new CL_Callback_Impl_v1_member_user<P1, InstanceClass, UserData>(instance, function, user_data));
    	}
    But still no change.



    Or did I something wrong? Because I think so.

  7. #7
    Lesser Knight
    Join Date
    Mar 2009
    Posts
    54

    Default

    IntelliSense: no instance of overloaded function "CL_Callback_0<RetVal>::set [with RetVal=bool]"

    The error is saying the callback function you've passed has incorrect return type

    try changing:

    void on_close( CL_Window *pWin );

    to

    bool on_close( CL_Window *pWin );

    and &m_pWin to m_pWin

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

    Default

    Yes, "bool on close(...)"

    Here is my patch that I used to test it.

    ClanLib Source Patch

    Code:
    Index: API/Core/Signals/callback_v1.h
    ===================================================================
    --- API/Core/Signals/callback_v1.h	(revision 5174)
    +++ API/Core/Signals/callback_v1.h	(working copy)
    @@ -220,6 +220,12 @@
     		impl = CL_SharedPtr< CL_Callback_Impl_v1<P1> >(new CL_Callback_Impl_v1_member_user<P1, InstanceClass, UserData>(instance, function, user_data));
     	}
     
    +	template<class InstanceClass, typename UserData>
    +	void set(InstanceClass *instance, void (InstanceClass::*function)(P1, UserData), const UserData *user_data)
    +	{
    +		impl = CL_SharedPtr< CL_Callback_Impl_v1<P1> >(new CL_Callback_Impl_v1_member_user<P1, InstanceClass, UserData>(instance, function, user_data));
    +	}
    +
     	void clear()
     	{
     		impl = CL_SharedPtr< CL_Callback_Impl_v1<P1> >();

    And Utilities/TexturePacker patch
    Code:
    Index: Sources/main_window.cpp
    ===================================================================
    --- Sources/main_window.cpp	(revision 5173)
    +++ Sources/main_window.cpp	(working copy)
    @@ -45,7 +45,7 @@
     {
     	set_id_name("mainwindow");
     
    -	func_close().set(this, &MainWindow::on_close);
    +	func_close().set(this, &MainWindow::on_close, this);
     	func_resized().set(this, &MainWindow::on_resized);
     
     	workspace = new ViewWorkspace(this);
    @@ -156,7 +156,7 @@
     	menubar->add_menu("File", menu_file);
     }
     
    -bool MainWindow::on_close()
    +bool MainWindow::on_close( MainWindow *window )
     {
     	exit_with_code(0);
     	return true;
    Index: Sources/main_window.h
    ===================================================================
    --- Sources/main_window.h	(revision 5173)
    +++ Sources/main_window.h	(working copy)
    @@ -64,7 +64,7 @@
     
     	int find_view_index(View *view);
     
    -	bool on_close();
    +	bool on_close( MainWindow * );
     	void on_close2();
     	void on_resized();
     	void on_view_close(View *view);
    I still don't know why that works though

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

    Default

    Thanks guys!

    @huntercool
    I was so focused on the "func_close()" thingy that I totally forgot to change this
    omg, thats a bit embarassing
    Thank you!

    Great support on that forum!

Similar Threads

  1. How to use a custom TTF-Font?
    By Impz0r in forum Official ClanLib SDK Forums
    Replies: 8
    Last Post: 05-26-2010, 06:54 PM
  2. New example in ClanLib 2.0: Custom GUI Component
    By sphair in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-19-2009, 02:08 PM
  3. custom resource
    By oilen in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 12-07-2007, 12:12 PM
  4. A patch to ClanLib 8.0: added RichEdit, remaked InputBox and some other issues.
    By ValkaVALES in forum Official ClanLib SDK Forums
    Replies: 7
    Last Post: 07-10-2007, 11:15 PM
  5. InputBox in 0.8 - fixed some bugs and added functionality
    By ValkaVALES in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 07-03-2007, 09:47 AM

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
  •