Limegarden.net Personal site of Wouter Lindenhof

17May/100

Events in C++

This week I have decided to do some little work on Nova as I would like to use it for a game. But I’m currently missing a GUI. Since writing a GUI is often a pain while a nice GUI is its weight worth in gold it was worth to invest some time in it.
One of the very first things I have decided on is that I want a good and proper event management system. I like how it is done in C#


myButton.Click += new EventHandler(this.myButton_Click);

However something equally nice doesn't exist in plain C++, so I have decided to write one.


struct GuiEvent
{
	bool cancel;
	GuiEvent() : cancel(false) {}
};

class Button
{
public:
	Event<GuiEvent> OnDown;
	Event<GuiEvent> OnUp;

	void FireClickEvent()
	{
		size_t cycle = 0; GuiEvent e;
		while(OnDown.Fire(cycle, e)) {
			if(e.cancel == true) return;
		}
		e = GuiEvent(); cycle = 0;
		while(OnUp.Fire(cycle, e));
	}
};

class Application : public BaseEvent::Receiver<Application>
{
	Button m_StartButton;
public:
	Application()
	{
		RegisterEvent<GuiEvent>(m_StartButton.OnDown, &Application::StartDown);
		RegisterEvent<GuiEvent>(m_StartButton.OnUp,	&Application::StartUp);
		m_StartButton.FireClickEvent();
	}

	void StartUp(GuiEvent& eventParam)
	{
		std::cout << "The start button was released" << "\n";
	}
	void StartDown(GuiEvent& eventParam)
	{
		// If you set event param to true the release will never be called
		//eventParam.cancel = true;
		std::cout << "The start button is pressed down" << "\n";
	}
};

int main(int argc, const char* argv[])
{
	Application myApp;
	return 0;
}

The above is rather primitive as I have written it quickly, but it looks nice and is code that is easy to understand. For the full source click here (C++ example of events)

4May/100

How to write school papers

Everybody who knows me only a little bit now that I have a huge dislike for writing papers. Papers are too much theory and to little substance for me.

Because of school I'm finding myself on the other side and I have to write a paper instead which, as you might guess, I find even less enjoyable than having to read one.

The problem however is that if I don't write a good paper I won't graduate and frankly I do want to graduate.

So instead of focusing myself on the problem (me disliking papers) I try to focus on the solution (write a good paper to get my pass) and here are a few tips and ideas to write your school paper.

1. A thousand words each day

When I first started working on my paper the progress was slow. I know that my paper needs to have 4000 words at least and after a week I had only 1200 words. Since I only work a few days in the week on my school work I would come at an average of 400 words every day, which is about a page a day. So I decided that for every day in the week I would write at least 1 thousand new words and remove at most 1 thousand words. Because of that I will always add more words than I remove.
As soon as I have added a thousand new words I would allow myself to take the rest of the day free. If I would write 17 words each minute and keep it up for an hour I would be done with my work within an hour. If you have four weeks left and only work on your paper three days of the week you would have a total of 4*3*1000 = 12000, which would be 3 times the required minimum.

If you keep track of your word count from day to day it becomes something enjoyable (and rewarding since it takes only an hour a day) instead of tedious.

2. Learn how to use Word

The majority of the people don't know how to use Microsoft Word but if you want to write a lot (and you want to write quickly) try to not use custom formatting at all (don't touch bold, cursive, etc) but use the styles ("Header 1", "Header 2" and so on). Formatting the text is something you will do only when everything is finished and if you have used styles the formatting is easy as you only have to adjust the style.
Images are the one thing that only always cause me trouble. I know that they need to be there, but I don't want to waste time now on creating them. What I always do is reserve one style in which I describe what image should be placed there. Later I just look for that style and I know how to replace it.
Also using comments and "keep track of changes" can be an aid. And using the grammar checker is useful to ensure that you are writing normal sentences.

3. Ignore spelling and grammar

Normally I would strongly advise against the above but I learned from creative writing (stories) that there are times you don't want to know that you type a certain word wrong or that your grammar is a long way off, but if you are typing about some complex algorithm (which is the part I really hate, just give me the code instead) you just want to continue typing. Fixing can be done later.

That are a few of the things I use to write my school paper. I hope they provide some aid if you have also the same amount of trouble writing paper.

Tagged as: , No Comments