Code Snippets

A forum to store posts deemed exceptionally wise and useful
Post Reply
Battlestations
Posts: 10
Joined: Sun Jan 18, 2004 10:46 pm
Location: USA
Contact:

Code Snippets

Post by Battlestations »

I'm thinking this would be a cool idea for everyone to get neat little ideas in one location. I have posted a few that already got buried. As I find more neat little things to do with the engine(and hopefully other people too) they could share an interesting little piece of code to help someone else out.
Heres One Now.

In the UserInterface Demo. I wanted to be able to run it and see where my mouse x, y location would be over the entire screen so i could map out where i want to place things, But i only wanted them to show in Debug mode.
so i added this:

Code: Select all

bool MyEventReceiver::OnEvent(SEvent event)
{
	//mouse events
	if (event.EventType == EET_MOUSE_INPUT_EVENT)
	{
		switch(event.MouseInput.Event)
		{
			//! Left mouse button was pressed down.
			case EMIE_LMOUSE_PRESSED_DOWN:// = 0,

			//! Right mouse button was pressed down.
			case EMIE_RMOUSE_PRESSED_DOWN:
				
				break;
			//! Middle mouse button was pressed down.
			case EMIE_MMOUSE_PRESSED_DOWN:
				
				break;
			//! Left mouse button was left up.
			case EMIE_LMOUSE_LEFT_UP:
				
				break;
			//! Right mouse button was left up.
			case EMIE_RMOUSE_LEFT_UP:
				
				break;
			//! Middle mouse button was left up.
			case EMIE_MMOUSE_LEFT_UP:
				
				break;
			//! The mouse cursor changed its position.
			case EMIE_MOUSE_MOVED:
			{
#ifdef _DEBUG
				//spits out the x,y coords for the mouse position
				//helpful for designing a layout or sizing Gui items
				char cpos[12];
				wchar_t pos[12];
				for(int j=0;j<12;j++) //pre-format the string data
				{
					cpos[j] = '\0';
					pos[j]='\0';
				}

				wsprintf(cpos,"%u %u",device->getCursorControl()->getPosition());
				wprintf(L"x:%u y:%u\n", device->getCursorControl()->getPosition());
				mbstowcs(pos , cpos , 12);
				device->setWindowCaption(&pos[0]);
				
#endif
				break;
			}

			default:

				break;

		}
	}
	//end mouse events
...//more code
continue code

The code sets the windows caption to x,y coordinates of the mouse location
Post Reply