March 9th, 2010
The Objective-C code from Rick’s World,
int i; // Loop counter.
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Enable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:YES];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
// Loop through all the files and process them.
for( i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
// Do something with the filename.
}
}
I was actually messing around with Monobjc and wondering how to work with NSOpenPanel, the code above provided a bit of a starting point for me. Here’s my code, which is not a translation of what’s above, but gives an example of how things work with C# and Monobjc,
NSOpenPanel openPanel = new NSOpenPanel();
openPanel.AllowsMultipleSelection = false;
openPanel.CanChooseFiles = true;
openPanel.CanChooseDirectories = false;
openPanel.SetContentSize(new NSSize(600, 600));
int dialogResult = openPanel.RunModal();
if (dialogResult == NSPanel.NSOKButton)
{
picFileName = openPanel.Filename.ToString();
}
The properties are self-explanatory and the code is simple enough, so I won’t bother with any sort explanation.
Tags: cocoa, file open dialog, monobjc, NSOpenPanel, objective-c, os x
Posted in OS X and Cocoa | No Comments »
February 27th, 2010
The amazing, but unused, child-killer illustration from Fallout 2, created by Brian Menze.

This image was unused and the only Vault Boy image to ever be cut from Fallout 2. (I’m sure you can figure out why) I remember when I got the request to do a perk illustration for “child Killer” that there would be no way to keep in from being offensive. I mean really! How do you make an illustration of “child killer” and keep it from being offensive? Anyway for some reason, I thought this was the least offensive way to do it. I have no idea what i was thinking. Even the designer who requested it realized it was a bad idea, so we nixed it. Looking back on it now, I can’t believe I drew this.
h/t HellForge
Tags: child-killer, fallout, fallout 2, illustration, perk, vault boy
Posted in Random | No Comments »
February 13th, 2010
STS-130 Space Shuttle Endeavor launch from the Intracoastal Waterway Bridge in Ponte Vedra, Florida; about 115 miles from the launch pad. This launch was extra special because it is NASA’s last scheduled night launch of the space shuttle program.

Credit & copyright: James Vernacotola
Tags: NASA, photo, shuttle, STS-130
Posted in Random | No Comments »
February 11th, 2010
After spending some time attempting to P/Invoke the stat() function, I discovered the wonderful Mono.Unix.Native namespace (found in the Mono.Posix assembly) which has some great stuff for lower-level Unix/Linux work.
Here’s what I did to pull a file’s inode number:
static public ulong GetFileInodeNum(string path)
{
Mono.Unix.Native.Stat statOut = new Mono.Unix.Native.Stat();
int statRet = Mono.Unix.Native.Syscall.stat(path, out statOut);
if(statRet == -1)
{
throw new IOException("stat on " + path + " failed.");
}
return statOut.st_ino;
}
Tags: inode, Mono.Unix.Native, stat
Posted in Mono | No Comments »
February 11th, 2010
Unfortunately, the method mentioned in the Mono Technical FAQ, where you can check System.Environment.OSVersion.Platform for a value of 6 doesn’t work (as of Mono 2.6). I got the following code from this thread, which works well enough,
[DllImport("libc")]
static extern int uname(IntPtr buf);
static bool IsRunningOnMac()
{
IntPtr buf = IntPtr.Zero;
try
{
buf = Marshal.AllocHGlobal(8192);
if (uname(buf) == 0)
{
string os = Marshal.PtrToStringAnsi(buf);
if (os == "Darwin") return true;
}
}
catch { }
finally
{
if (buf != IntPtr.Zero) Marshal.FreeHGlobal(buf);
}
return false;
}
Tags: os x, PlatformID, System.Environment.OSVersion.Platform
Posted in Mono | No Comments »
January 26th, 2010
This involved drawing a filled rectangle with a TextureBrush, using a 1x[whatever] texture and setting it to be tiled.
TextureBrush tb = new TextureBrush(firesync.Properties.Resources.target_highlight2_run);
tb.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
e.Graphics.FillRectangle(tb, 0, 0, 32, 32);
The code above works correctly and here is what it produces,

Unfortunately if the y (top) coordinate of the rectangle is changed to anything other than 0, the rendering gets screwed up. Here is what occurs if the y-coordinate is set to 1 (which should, effectively, push everything down 1 pixel),

However, there is a way to hack around the issue, keep the y-coordinate at 0 and use Graphics.TranslateTransform() to do the y translation.
TextureBrush tb = new TextureBrush(firesync.Properties.Resources.target_highlight2_run);
tb.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
e.Graphics.TranslateTransform(0, 1);
e.Graphics.FillRectangle(tb, 0, 0, 32, 32);
Tags: FillRectangle, GDI+, TextureBrush
Posted in .NET Platform | No Comments »
January 21st, 2010
A while back I wrote about 2 applications, The KMPlayer and JCreator not behaving well when attempting to run both concurrently (see post).
Now, I have an incredibly weird situation on my system. KMPlayer and JCreator don’t play nice together. If they’re both open, some JCreator panels and menus are suddenly blank and don’t refresh and the side tabs panel is transparent, showing thru to the desktop. As for KMPlayer, I can’t open anything, clicking play (which plays the last file opened when nothing else has been loaded) does nothing, and certain items are mysteriously missing from the context menu. This hasn’t been a big deal for me, and I still use both JCreator and KMPlayer, but it would be nice if they worked together. Also, I have to wonder, what is the common component causing the conflict here, what would a media player and a java IDE both be using or trying to access concurrently? (assuming there is a conflict for a common component, which I suspect might be the issue here)
My suspicion was wrong, it was not a conflict between the applications or a common component, it was the system running out of User objects. In Winforms (and I suspect most other GUI toolkits as well) any GUI control or window will consume at least 1 user object (more complex controls, with multiple sub-components will consume more User objects), and when the system or process hits the limit (65,536 for the user session, 200 – 18,000 per-process; default is 10,000 on Windows XP), creation of new User objects will fail, even if the system has enough memory to support whatever it is that’s being created. On the .NET Framework, you’ll notice this if you get an exception that looks similar to the following,
System.ComponentModel.Win32Exception: Error creating window handle.
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
I’m still puzzled as to why there simply isn’t a limit based on available memory, but I haven’t been able to find a whole lot written on User objects in general much less details on why they exist.
Tags: GUI, User objects, winforms
Posted in Win32 Platform | No Comments »
January 15th, 2010
I spent some time recently investigating file tagging on Windows Vista and Windows 7, and I was less than happy with my findings. The problem is that only certain file formats that support metadata can be tagged, for file types without such support it’s simply not possible to do any tagging. This is a major limitation and without ubiquitous tagging support, the feature itself becomes all but useless; as an end-user, I don’t care about file type, if I’m searching for a document should I have to remember whether it’s a Word document or a plain-text file? JPEG or TIFF? Absolutely not. The confusing thing is, at some point, Microsoft seemed to believe this as well, by default Win 2000 and higher hides file extensions for know file types – isn’t it then completely counter-intuitive to present a limitation based on file type. What this ultimately boils down to is the question of why would I bother tagging anything if only a subset of my files, based on file type, an attribute I don’t care much about, would benefit from the additional metadata?
This isn’t to say that there is necessarily an easy solution. I found this blog post to be the best write up on the topic which explains several approaches that could be taken to implement tagging and why storing metadata in the files themselves was chosen as the best approach. However, I don’t think storing metadata in the file system would be such a bad idea, I can understand the issues about losing metadata when copying to another volume, typically one with a older file system, but at some point you have to do what’s best for the future, not the present, by that I mean the only way you’d actually start to see file systems with proper support for metadata (via. NTFS-esque alternative streams or whatever) in use is by providing an imperative for users to buy or format devices with those file systems; as-is, we’ll continue to use systems such as FAT32 and programmers will continue to remain agnostic to metadata. At the very least, a hybrid approach, storing metadata both in the file itself, when supported, and within the file system would seem a worthwhile solution.
Tags: FAT32, file system, files, metadata, NTFS, tagging, windows, windows 7, windows vista
Posted in Random | No Comments »
January 13th, 2010
I’m not an artist, but I think this is a pretty great message and can be extrapolated pretty easily to other professions and to those of us who are starving artists in spirit,
Link
Tags: inspiration, life, pixar, Will Draw For Food
Posted in Random | No Comments »
December 30th, 2009
As the TSA pushes forward another round of absurd “security” measures, a notable quote from Bruce Schneier,
Only two things have made flying safer [since 9/11]: the reinforcement of cockpit doors, and the fact that passengers know now to resist hijackers.
Tags: Bruce Schneier, security, TSA
Posted in Random | No Comments »