Page: 0 ... 5 ... 10 ... 15 ... 20 ... 25 ... 30 ... 35 ... 40 ... 45
User Interface Code-fu
Date: 21/10/2005
Note: This is aimed purely at coders, so don't get too worried if it doesn't make any sense.

Background: In the world of programming user interfaces it is common to have an object wrap each user interface element (window), which virtual methods that trigger when various things happen, like "OnMouseClick" and "OnPaint". These methods are implemented by the application to add functionality to the base controls provided by the application framework. In C++ these are virtual member functions in the parent C++ window class.

Ideally the code inside these event handlers, as implemented by the specific application, would take minimal time to run and be generally well behaved. But in reality it sometimes needs to do a lot of work in the event handler and can do nasty things like delete the current window object processing an event. So I'm getting to grips with this in Lgi and I've come up with a reasonably neat solution.

Firstly for the issue of long running event handlers, you often want to know that the handler "hung" for a while. This is reasonably easy to check, just take a tick count at the start, and another at the end and work out the milliseconds the handler ran for. If it's over some threshold you can change the post event handler behaviour. I do this in the list control when the application puts up a right click menu and "hangs" the event handler. Normally I trigger a timer to check if the user has started a drag and drop operation, but if the handler hangs, a d'n'd operation should NOT be started.

The second issue is the one of the event handler destroying the window during it's processing of the event. Now you could setup a complicated system of return values on the events to indicate whether the application has deleted the window, but that is prone to error because it puts the responsibility on the application to "Do The Right Thing(TM)". I'd prefer a system that doesn't require any smarts on the application side to work correctly. So I came up with a better way (And sorry if it's obvious). Basically the problem with the current object being deleted during the event handler is that you can not access any of the member variables or methods after the event handler. However anything on the stack is still fair game, and I use this fact to get notification of the objects destruction. e.g. my code to call the event handler now looks like this:

bool DeleteFlag = false;
this->pDeleteFlag = &DeleteFlag;
if (DeleteFlag)
this->pDeleteFlag = NULL;

I have put a pointer to the delete flag in the object so that in the destructor of the object I can return information of the destruction event to some interested party (i.e the event handler calling code furthur up the call stack):
    if (pDeleteFlag)
        *pDeleteFlag = true;
    // other stuff....
This way if the event handler deletes the object, the flag on the stack gets set, and I can trap that AFTER the event handler has returned and the current object no longer exists. Nice, neat and robust.
(0) Comments | Add Comment

DirectShow Filters
Date: 18/10/2005
I'm trying to write a DirectShow app that previews video/audio from my TV tuner card. So far so good, the video is working fine and I can change channels and fine tune. But I'm kinda stumped as to why the audio isn't working. This is what my filter graph looks like:

The TV card has an analogue out which has a cable running around to the sound card's Line-In. I've got some code that runs through the pins on the Sound Card's capture filter, finds the "Line In" pin and enables it and sets the volume to "1.0". Maybe the next step is playing with the crossbar to get the audio routed to the right place.

Update: Well when it rains it pours. I followed my nose and starting playing with the crossbar interface. I decided to route the "Audio Tuner In" pin to the "Audio Decoder Out" pin. Seems logical enough. And whoooo sound! But now the problem is that I have 2 copies of the audio, slightly offset from each other, creating an echo. Interestingly as soon as the graph starts running, 1 lot of sound is heard, but when the message loop starts the 2nd lot is added. Then when the application quits the 1st lot of sound remains. Interesting.

Update2: This is what the final working graph looks like. Which is really just the bottom section of the first graph above:

(3) Comments | Add Comment

Firefox 1.5 "Oh Yes"
Date: 18/10/2005
Out of pure frustration I decided that I would download and install Firefox 1.5 to see if it fixes the "flicker" bug that has been driving me slowly insane for the last 4-5 months. Basically in all the "Designed By Corperate Committee(TM)" sites that I use from time to time cause Firefox 1.0.x to flicker badly when you use the combo drop down fields. Some other part of the page briefly flickers to a new (wrong) position and then back to it's correct position every time the combo box changes value. And when your scrolling through the list of values in the combo box it's a nightmare.

But yay for progress, 1.5 fixes that (so far). So I'm a happy little camper...

Update: My net banking didn't work in 1.5 so back I go into land of pain. Also 1.5 had issues with some pages, spraying javascript goop into the visible document. Ok not ready for prime time then.
(1) Comment | Add Comment

Subaru Goodness
Date: 12/10/2005
Ok so I should eat my words, Subaru have released the 2.0r engine here in Australia. The new Impreza range has replaced the old 2.5 RS model with the Impreza 2.0r, a nice step up in the technology being used. Yay for DOHC and AVCS. Hopefully this engine will also end up in the Liberty (Legacy) range as well. I don't even mind so much that the Australian 2.0r engine only puts out 118kw and the Japanese 2.0r puts out 140kw, because it still runs on 90 octane fuel! Thats heaps of grunt for 2L and 90 octane. Most engines in that catagory are premium only, 95 octane or more.

I'm currently thinking about how to downgrade from my twin turbo Legacy to something a little more affordable, so I've been looking into the whole compact car market. I really like the Jazz but I also really like Subaru AWD... and now I can have both! Well actually I can't because they only sell them in Japan, but hey it's affordable, a mere A$15,500-16,500 buys you a R2 type S[upercharger]. That doesn't include getting it here though :( The R2 looks great, it cheap to run at about 5.5L/100km and comes in a sporty version with a nice interior. Who knows why they don't export it. But I'd certainly seriously entertain getting one if it was available over here.
(0) Comments | Add Comment

Finally. DVD + Car Stereo + MP3
Date: 11/10/2005
Finally someone put a DVD drive into a car stereo so that you can have a decent music library in your car. It's not cheap, but for A$599 there is the Sony MEXR1. There is no OGG playback so I'm not running out to buy one but it's starting to tempt me. Bonus points for looking like it belongs in a car.
(1) Comment | Add Comment

Date: 10/10/2005
Back in the day, like I think 1994 I wrote an application in DOS that could extract a bitmap image out of a binary file of an unknown format. It did this by displaying an interactive view of the file on the screen, and you could change the parameters of the image, like width and bit depth in real time. This let you "explore" the binary data in visual form, which often lead to seeing patterns in the data, and those patterns were sometimes bitmaps (or pixmaps/DIBs etc), stored in the file.

Well I needed this sort of functionality the other day so rewrote it for windows. Thus the windows version of BitHack was born. If you want to play with it I suggest practising on a .bmp file. It's an easy way to get some data to play with.
(0) Comments | Add Comment