kahrn's abode

kahrn's abode: where dreams slowly become reality!

December 4th, 2009

I thought I’d share a little snippet on displaying forms in .NET that allow a window/form to dynamically resize, without encountering GUI lockups (due to thread delays), and without having to know the original form dimensions. It’s relatively simple.

First you can define the intended size variables, and also create instances of the Clock class.

public partial class Form1 : Form
{

// Define the intended height and width
int INTENDED_WIDTH;
int INTENDED_HEIGHT;

// Create two clock instances.
Timer Clock1;
Timer Clock2;

Then comes the constructor for this form. In my case (and the default of C# .NET projects) is the Form1 constructor.

public Form1()
{
InitializeComponent();

// Define intended dimensions
INTENDED_HEIGHT = this.Height;
INTENDED_WIDTH = this.Width;

// Reset current dimensions
this.Width = 0;
this.Height = 0;

// Initialize the clocks
Clock1 = new Timer();
Clock1.Interval = 1;
Clock1.Start();
Clock1.Tick += new EventHandler(IncreaseWidth);

Clock2 = new Timer();
Clock2.Interval = 1;
Clock2.Start();
Clock2.Tick += new EventHandler(IncreaseHeight);

}

Now it’s just a matter of incrementing the width and height on each tick of the previously defined clocks. This is defined within the event handlers for those clocks.

private void IncreaseWidth(object sender, EventArgs eArgs)
{
if (this.Width != INTENDED_WIDTH)
{
this.Width += 1;
}
else { Clock1.stop(); }
}

private void IncreaseHeight(object sender, EventArgs eArgs)
{
if (this.Height != INTENDED_HEIGHT)
{
this.Height += 1;
}
else { Clock2.stop(); }
}

That concludes my first informative C# / .NET post.

December 26th, 2008

I recently spoke with an old friend about managing projects. I had a little experience using svn (once compiled Miranda IM from svn) and have used git for checking out stuff from the wine project, but had never really considered using it myself as my host does not offer such a service.

He put forward the idea of using it locally to just manage stuff on the local machine or across the network. Of course!

The advantage of using such a system is that you don’t waste your code, things can be fixed easier, and it’s a lot better than either only keeping the latest version you are working on or creating copies of it at random intervals. You’ll also be much more prepared for working on something across multiple machines or collborating with others.

Here is a little quick-start guide to the basics of it all.

First and foremost, you will need the server packages. For all of this I ran both the server and client on my IBM Thinkpad to manage projects locally. For the server I used VisualSVN — http://visualsvn.com
As for the client, I used TortoiseSVN — http://tortoisesvn.tigris.org

Once you have both of these installed (they’re pretty simple install packages like any other windows app) you should start VisualSVN.

Visual SVN (Start/Stop)

You will want to create a repository (repository: Simply a project) from within VisualSVN. It will ask you if you want to create a default set of directories. For basic projects, you will probably want this unticked, at least until you understand some more of the SVN lingo.

Visual SVN (Adding Repo)If everything is working correctly, you should now be able to view your repository in a web browser. Go ahead and browse to https://youmachinename:8443/svn/ (or https://127.0.0.1:8443/svn/, if you prefer) and you should see all the available repositories listed.

Now to put some initial code into one. In this instance, I am initialising a project called HelloWorld and importing the initial code/files into the repository for the first revision.

Visual SVN (Init Repo)

If all has gone well you should be able to view all the code from your web browser (in my instance, https://127.0.0.1:8443/svn/HelloWorld/)

Now, in order to checkout (retrieve a copy of) the project, you can use the SVN Checkout option. This will download the latest revision or a revision you specify. Pretty simple, eh?

As for terminlogy, http://modetwo.net/darkmod/wiki/index.php/SVN_Glossary, http://en.wikipedia.org/wiki/Trunk_(software)

May 25th, 2008

Greenfoot LogoI recently had the opportunity to visit Kent University and attend a day with Michael Kölling (key figure in BlueJ and Greenfoot development and senior lecturer at Kent University) and play with the Greenfoot development environment. What interested me about Greenfoot originally is that it is a simplified game development environment (similar to Game Maker by Mark Overmars) but is in some respects more simplified.

Rather than using a newly created language (GML in Game Maker) Greenfoot simply interfaces with Java, and you actually end up writing pure Java code using the Greenfoot library. Despite this, Greenfoot is actually incredibly simple to use and ideal for small simulations/experiments or very simple games.

Personal dislike towards Java aside, The main difference in Game Maker and Greenfoot is perhaps the overall goal. Over the years Game Maker has distanced itself from the academic side and more to the amateur game development side, whereas Greenfoot remains purely for academic purposes. The original goal was to create a development tool which can be picked up easily, and interest high school students in programming through the practice of simple game development.

I don’t think Greenfoot will ever evolve into something like Game Maker purely because of it’s main goal. That said, it’s still a pretty cool tool if you want to learn code. It teaches you REAL code and not that sissy VB crap that they teach elsewhere. One other advantage perhaps is the ability to export projects. This means that after producing something you can export to whatever device Java supports — something that GM users have wanted for a long time.

Will I be releasing anything? Maybe.

See links below for Greenfoot and other resources.

http://www.greenfoot.org
http://www.youtube.com/watch?v=Tcwx-I6Arwk / Micheal Kölling @ googletechtalk
http://www.yoyogames.com/make
http://greenfootgallery.org
http://en.wikipedia.org/wiki/Michael_K%C3%B6lling

April 8th, 2008

I was browsing through my personal codebase/codesnippets and I found a piece of code I wrote in 2007 that obtains CPU usage. It uses the Win32/COM Python extensions (http://sourceforge.net/projects/pywin32/).

You can find it on the tdlabs forums — http://tdlabs.co.uk/forums/showthread.php?tid=13

Have fun.