Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualiwoplaza

Posted 23 July 2012 - 06:55 AM

I would like to create buttons. And when you click them, do some functions.
But i have problem with button actions Posted Image.

Some of my code:

//---- Header File----
class Button{
	public:
		//variables initiating like float x,y,z...
		void func(void);
		void draw(){
			//Some drawing
		}
		void CheckButtonClick(float mx, float my,int key,int state){
			if(mx >= x && mx <= x+w &&
			   my >= y && my <= y+h &&
			   state == 0 && key == 0){
				  click = true;
				  func();
			}else
				  click = false;
		}
};

//----Main File----

void AddButton(Button &button,string text,void func(),float x,float y,float z,float w,float h,float s,float r,float g,float b,GLuint tex,GLuint clicktex){
	 button.tex = tex;
	 button.clicktex = clicktex;
	 button.func() = func();
	 button.textsize = s;
	 button.text = text;
	 button.x = x;
	 button.y = y;
	 button.z = z;
	 button.w = w;
	 button.h = h;
	 button.color[0] = r;
	 button.color[1] = g;
	 button.color[2] = b;
}


Button button_file,

void close(){
	 exit(0);
}


void InitRendering(){

	_buttondark = loadTexture ("Data/IvoGui/buttondark.tga");
	_buttondark_click = loadTexture ("Data/IvoGui/buttondark_click.tga");

	AddButton(button_help,"Pomoc",close(),133,5,0.001f,64,16,0.9f,1.0f,1.0f,1.0f,_buttondark,_buttondark_click);
}

It gives me an error:
invalid use of void expression

Without button actions everything works fine.
Can you help me with this actions?

Thanks in advance.

#1iwoplaza

Posted 23 July 2012 - 06:54 AM

I would like to create buttons. And when you click them, do some functions.
But i have problem with button actions :(.

Some of my code:

//---- Header File----
class Button{
    public:
	    //variables initiating like float x,y,z...
	    void func(void);
	    void draw(){
		    //Some drawing
	    }
	    void CheckButtonClick(float mx, float my,int key,int state){
		    if(mx >= x && mx <= x+w &&
			   my >= y && my <= y+h &&
			   state == 0 && key == 0){
				  click = true;
				  func();
		    }else
				  click = false;
	    }
};

//----Main File----

void AddButton(Button &button,string text,void func(),float x,float y,float z,float w,float h,float s,float r,float g,float b,GLuint tex,GLuint clicktex){
	 button.tex = tex;
	 button.clicktex = clicktex;
	 button.func() = func();
	 button.textsize = s;
	 button.text = text;
	 button.x = x;
	 button.y = y;
	 button.z = z;
	 button.w = w;
	 button.h = h;
	 button.color[0] = r;
	 button.color[1] = g;
	 button.color[2] = b;
}


Button button_file,

void close(){
	 exit(0);
}


void InitRendering(){

    _buttondark = loadTexture ("Data/IvoGui/buttondark.tga");
    _buttondark_click = loadTexture ("Data/IvoGui/buttondark_click.tga");

    AddButton(button_help,"Pomoc",close(),133,5,0.001f,64,16,0.9f,1.0f,1.0f,1.0f,_buttondark,_buttondark_click);
}

It gives me an error:
invalid use of void expression

Without button actions everything works fine.
Can you help me with this actions?

PARTNERS