Accidental Scientist
 Subscribe to this blog    Add to Technorati Favorites

Monday, November 26, 2007

How I Spent My Thanksgiving Vacation: A TreeView Control

So after basking in the turkey afterglow, what does any self-respecting programmer do?

He takes a nap.

What does he do after that though?

He gets soused on eggnog, with real nog in it.

But after that?

Well, dear reader, I took it upon myself to write a Tree View control in C# (.NET framework 2.0) from scratch.

My TreeView Control
A little proof... here it is in all its glory... well, how it stands right now anyway... Not that impressive looking, to be honest, but it's mine - all mine!

Now, you may be thinking to yourself... why on earth would he go ahead and do that? There's a perfectly good TreeView control right there! In the framework!

Well, there's a damn good reason for this. I like reinventing the wheel. No! Er... I mean, the existing TreeView control doesn't support a few things I needed.

What can't the existing control do?

  • Variable size items
    I needed a way to custom draw items which might or might not be more than one line of text high.
  • Sub-item handling
    I needed a way to implement sub-items within an item, while retaining proper focus handling. Which means I need to be able to pass all of the selection handling and keyboard focus traversal to the nodes themselves when rendered.
  • Flags
    Somewhat like OneNote, I needed a way of adding flags to the left of items in the TreeView.
  • Windowless Controls
    I needed a way to implement this control so that it could be embedded within another control without a lot of heartache. For example, I want to be able to paint three trees in a row, while only having one scrollbar.

I also looked at using a ListView control for this, but unfortunately, that would only get me part of the way there.

(Some of you may be wondering why I didn't do it using the new Windows Foundation framework... yes, I agree, it would most likely be <strong>much</strong> easier. However, unfortunately, it won't install on my laptop until I lobotomize it [thank you, beta software]).

What I Ended Up With

So this is version 1 of my ComplexTreeControl, which frankly isn't architected in entirely the best manner, but should be pretty easily refactorable as I go on.

What do I have implemented so far?

  • OneNote style flags to the left of the expand/collapse node.
  • Full keyboard traversal of the tree (with the correct behavior), including Home and End keys.
  • Context menus with Default menu item support, and auto-insertion of Collapse/Expand if it's a node with children.
  • Variable height nodes.
  • Rendered layout information separated from the node structure. (Basically, it builds a list of nodes with indent information by iterating over the tree).
  • Selection of a single node based on the current location of keyboard focus.
  • Tree Collapse/Expand icons stored in a resource on the control itself. All other icons come from a custom image list that can be set by the user.

It's not yet windowless, and the painting logic for nodes still leaves a lot to be desired (mainly because I need to pass around not only the clip rect, but the client rect, and the item rect as well).

To Do:

  • Implement Focus handling correctly. (Right now, I'm missing a piece of that puzzle, and the control doesn't end up with focus).
  • Windowless painting & layout.
  • DPI awareness (mainly so that I can print out the tree).
  • Line-buttons (buttons which appear to the left or right of the item, for use in a visual merge app; kind of like the ones you get in Araxis Merge).
  • SubItem focus traversal. (Not too hard to do - just need to pass handling of it through to the underlying node).
  • Rendering info caching. (I should at least cache the extents of the visible items)
  • Scrolling (yeah, I know, it's not exactly a big one... shouldn't be too hard though... the trick will be doing it in a way that I can still make the control windowless when I need to).

Of course, if I do my homework right, I should be able to wrap this all up in a rather nice bow and have it available for sale to interested parties. :-D

It's interesting coming back to writing .NET C# UI controls for the first time in, oh, I dunno, nearly 10 years since I worked on the .NET framework back in 1998. Its gotten easier. I've learned a lot since then.

Oh yeah... why am I doing this?

Well, frankly, I'm sick of having to handle Visual C++ project merges by hand. Sure, Visual Studio Team Server might have all kinds of wonderful support for this, but at work we're using VC++ 2005 Pro with Perforce, so we don't get that useful tool.

And merging project files - actually, merging any kind of XML - is a pain in the ass. Sure, I could use the XML Diff Patch tool that Microsoft has on their site, but that just gives me a hard to read DiffGram, and besides, I'd want a UI on the top of it anyway. (I like UI's ... they make life easier).

So screw that for a game of soldiers. I'm writing my own damn merge tool. It's going to be at least a Tree based view of the project, and I'll probably turn it into a generic VC++ 2005 project file editor. With support for solutions. Etc etc.

And its current title? VC Project Magic.

Unfortunately, it's not going to be finished in time for me to get out of merging one last set of 4 project files by hand. Grrrrrr.

Wednesday, November 21, 2007

Kill the Silent Polygamist? Never!

New posting up on the Surreal Game Design blog.

At some point (probably 2 months from now) I'll start resyndicating those posts here. But for now, go check 'em out!

Labels: , , , ,

Monday, November 19, 2007

The Power of Blankets

Blankets are great.

I don't know about you, but whenever I'm alone at night in a big house with too many windows without blinds or curtains, and I get spooked, I turn to my friend, the blanket.

My blanket is impervious to all demons, serial killers, vampires and deformed mutant zombies. It must be made of titanium, or maybe woven carbon fiber. Certainly at the very least somewhere on a molecular level it's inscribed with all kinds of protective sigils, and the fabric itself was washed in the most holiest of holy water.

Its powers disappear when the sun rises. Until then, however, I'll be stuck underneath it, waiting for the bad things to go away.

Labels:

Help Me Finish Little Miss Litty

Help I'm stuck!

Throughout the story, I have a demon insisting that people play the game with him.

The little girl (Anna) plays the game, but doesn't play fair. And she won't reveal the rules to Sarah Littern.

The demon so far has not revealed what the rules of the game are, or what the game is?

So what can it be?

I'm stumped. I think I have a vague idea of a direction to go in... but to be honest all I really know for sure is that it's not a "Rumplestiltskin" game.

Anyone got any suggestions?

Labels: ,

Sunday, November 18, 2007

A Little Family History

So I'm sitting here on the couch watching Sicko (Michael Moore's investigation into America's healthcare system vs. socialized medicine in the UK & Canada), and at one point he's interviewing the Rt. Hon. Tony Benn (Labour MP).

And what did I spy in one shot?

A SOGAT mug from 1982.

Most people won't know what SOGAT is... in fact, for the longest time I didn't. It's a print-workers trade union in the UK (specifically, the "Society of Graphic and Allied Trades").

Why do I know this?

Strangely, because my grandfather (on my mom's side) was the secretary of Sogat for a while. I don't know any more details. I'm hoping that someone will eventually read this and fill in the blanks for me.

I remember being 7 or so, and visiting him in an office building somewhere near Manchester. What do I remember from the visit?

A big wooden desk. A pen holder. Some kind of phone. And the coolest thing of all, a pen holder that looked like a little animal, with a spring like a slinky in the middle.

We got to the office via an elevator. But that's all I remember.

At one point, I visited a newspaper printers in what's now called the "PrintWorks" in Manchester - refurbished now as a cool nightlife/entertainment zone near the Manchester Arndale center. (The IRA bombing in 1996 brought about a number of changes... this was one of the cooler ones). All I remember? A big green door, and a huuuuuuuge roll of paper near the entrance in some kind of machine.

The other memory of my Granddad's work was seeing him on the news, walking and talking with Margaret Thatcher during some kind of trade dispute. They talked over everything he said, cutting to her for the soundbite.

Oh, he also had the occasional trip to Hawaii (I think he stayed at the same hotel I've been to), and had at least one meeting on Robert Maxwell's (head of the Mirror Group of newspaper publishers) yacht the Lady Gislaine - about a year before Maxwell was found dead floating overboard.

My granddad - Gerard Foley - died in 1986 of a double heart-attack. And he has this life that I know very little about.

My grandmother - Kathleen Foley - was a nurse. That much I know. She died less than a year after my grandfather of cancer.

They both grew up during World War II; my gran was evacuated to Wales if I recall correctly. She had photos, and at she still had the gas mask.

More than that? I don't remember. I was 12 or so when they died.

Some of these facts may be wrong - they're all from memory. Either way, if anyone has any more info, please let me know :)

Labels:

Thursday, November 15, 2007

Windows Desktop Search - Half Baked, Half Assed

I love the ability to search fast through OneNote and Outlook that Windows Desktop Search gives me... but...

And here's the problem. But. It's a huge but. It's an enormous but. If it had an extra t, it'd need to buy an extra seat whenever it flew.

It makes my machine run like porridge.

I don't know what it is. I disabled it scanning XML files because the XML parser runs like molasses on a cold day in January. But It Still Regularly Slows My Machine To A Crawl.

Here's a clue, Windows Desktop Search team:

I don't know what kind of uber monster machines you're running, but most people's systems these days slow down considerably whenever they hit the disk. I don't know if it's the chipsets being used, or the drivers, but nearly every machine I've seen slows to a crawl when it hits high disk utilization these days - including Quad Core, 4Gb monster machines like my system at work.

Laptops are worse. Most laptops I've seen can't handle sustained high throughput on any IO channel - USB or hard drive. It just kills them. They slow to a crawl and become unresponsive.

LIMIT YOUR DISK ACCESS. I don't care if you're in an idle thread, you can't hammer the disk the way you do.

Fix it, or bye-bye WDS. I have no idea if Google Search is any better; I uninstalled that puppy when it was still buggy enough to cause problems and crash on a regular basis. Either way, it won't provide the search functions I need in Outlook and OneNote.

Labels:

Surreal's Game Design Blog

I've finally gotten around to starting writing for the Surreal Game Design blog, where you can find all things Surreal and Game Designy.

I've got a bunch of posts coming up on there soon, so keep your eyes peeled. Meanwhile, here's my Hello World post.

Labels: , , ,

Monday, November 12, 2007

Photo: Clouds


Clouds over the deck at Surreal Software. Copyright © 2007 Simon Cooke.

Labels:

Thursday, November 08, 2007

Microsoft Money for the Smartphone... Does Not Exist

I have a smartphone (it's a Cingular 3125). I love it. It's great for making sure I show up on time to all my meetings, and it helps keep my life in some kind of order.

There used to be - for the Pocket PC - a version of Money. This was great. I could sync up my PC with the Pocket PC and keep track of all my cash.

This does not exist for the Smartphone. I'm not sure if a version ever existed; if it did, it's certainly not one that works today.

Microsoft doesn't publish an API (or any advice) for how to sync MS Money with a Smartphone over Activesync. The only choice you have is to use the exchange files that they create for communicating online with banks that are behind the times, and/or exporting/importing data to and from Quicken.

Microsoft - please, guys, come on. Either open up an API for people to use to write a third party app, or take your Pocket PC version and port it to the Smartphone. I'm sure it would be easy for y'all to do, and a lot of people would be very grateful - myself especially.

Come on guys... you know you can do it...

Update: Hey, whaddya know? A third party (Ultrasoft) stepped into the void and (somehow, given that I have no idea where they got the docs to be able to do it) have produced a Smartphone compatible app that will sync with Microsoft Money. Hurrah. It only came out last month, so I guess that's why I didn't know about it.

Labels:

Wednesday, November 07, 2007

Photo: Man On Fire


A little experiment here... I'm going to start posting some of my photos to my blog. All of these are of course copyright © 2007 Simon Cooke

Labels:

Feed Fixed

I finally noticed that the feed for this blog was pointing to the wrong location (sigh), so now it's fixed!

If you wanna subscribe, click on the "Subscribe to this blog" link at the bottom right.

:)

Labels:

Sunday, November 04, 2007

The Writing Continues... (Ghostbusters 3...?)

So I'm carrying on with Little Miss Litty, but I came up with a strangely good idea the other day, and I'm rolling with it.

I think I've figured out how to do a worthy sequel to Ghostbusters 1 & 2.

Way I figure, my script is currently looking like it has a much better storyline than what I've heard of the stalled version of the movie they want to make. (Ghostbusters go to hell? Yeesh... sorry, I can see all kinds of reasons why that script might have a few issues in terms of continuity, scope, and a whole bunch of other things).

So as soon as I finish Litty, that's what I'm going to be working on. Ghostbusters 3. I've already got most of the major plot points hammered out, and know roughly the scope of it. It'll be just a smidge darker than the others... not too dark... but you know, you gotta roll with the times.

Labels: ,

Thursday, November 01, 2007

The Right Way to develop games...

From RockPaperShotgun, an interview with Kim Swift of Valve on Portal:

KS: I think it’s the process. As far as screen-testing goes, it’s usually not until the end of the movie process. We started testing as soon as we got here. And I can understand how it would destroy a movie, because it kind of did that for Narbacular Drop. We didn’t start play-testing until really the last month of our development, and by that point it’s too late to do anything about it. It’s like, “Oh, well, that’s unfortunate.” I think it’s when you start to get user feedback that’s most important. Because we’re in an entertainment industry, and if people are not entertained, then we’re not doing our job.


Emphasis mine.

Labels: , ,