02 Feb 2016 @ 9:19 PM 

A Demo Project covering the content of this post can be downloaded Here.

Sometimes, a standard Windows.Forms.ListView just doesn’t cut it. Sometimes you just want to present more information, or customize the way the information is presented. With Windows Presentation Foundation, you typically accomplish this with Data Templates. Unlike Windows Forms adding a Progress bar to a ListView, for example, is fairly straightforward, since WPF effectively allows elements to be used as content anywhere.

One feature that sometimes finds itself to be useful is the addition of a Standard button within a ListView subitem. Generally speaking, the preferred approach is to use a right-click menu, but depending on the context of the application and the intended userbase, there could be a different set of expectations. Furthermore, a button in a subitem is much more clear with regards to the possible functionality then hiding a capability behind a otherwise invisible right-click context menu.

In the particular case that I found purpose for this ability, was for a invoice/finance related task. In particular, when voiding/nullifying an invoice, users had to provide a reason for the invoice to be voided. In the application that lists invoices, it made sense to make this reason available, but the maximum length of such reasons made it untenable to simply add a new column, and as I mentioned, placing it in a right-click menu was rejected because users simply wouldn’t know to try that to find new features. As a result, the consensus was to try to add a button within the subitem to allow viewing the Reason, and only make that button visible where a reason was present.

For obvious reasons I cannot share the actual code involved, but since it was specifically tailored to that application, it wouldn’t be particularly useful anyway. It makes more sense when sharing code such as this to provide a more generic solution, so I set about creating a more generic implementation.

The Windows Forms ListView

As I mentioned in the introductory paragraph, the Windows Forms ListView is not as flexible as the Windows Presentation Foundation ListView. The reason for this is largely a result of Windows Forms being a Framework built in .NET that abstracts the standard Windows API. There are some advantages to this approach, in particular Windows will be more easily inspectable by accessibility programs. (without additional work). One of the disadvantages is that Windows Forms inherits the limitations of those original controls. One of these limitations is that, by default, the ListView itself really only knows about drawing small images and text for various subitems. If you want to do something fancier, then you have to do it yourself.

Owner-draw

One common extensibility approach that is taken throughout the Win32 API is the concept of “owner-draw”. This is a capability whereby the control effectively defers to the Owner (eg. your code) to perform the task of drawing. This provides a rather copious amount of flexibility in terms of the presentation, without making the control logic itself too complicated, so from a design perspective it made sense.

Taking the above into account, we can see a clearer picture of how we can have a button in a ListView’s subitem. Clearly, the solution is that we take over the drawing of that subitem, and we draw a button. But now we have a new problem- How do we draw the button?

We could mimic a button control by drawing a square with some text in the middle, but that seems like a cop-out- If we draw a button, we want it to look like all the other buttons in the User Interface. But we also aren’t about to commit to a study of the particulars of the buttons on various Windows Platforms and their appearance. Thankfully, the Win32 API does in fact provide us a solution- well, two solutions, really. We can use functions in uxtheme to draw themed components, and- if theming is off, for some reason- we can fallback to using DrawEdge.

The Native Methods

As per standard .NET Convention, we’ll slap out Native methods into an appropriate “NativeMethods” class. I’ve opted to have the class as a private class within the larger class (ListViewButton) such that a single source file can be included in projects to use the capability. But of course different classes can easily be separated into their own files. Here is the NativeMethods class:

Additionally, we will want to define some enumerations and constants:

And now, we can write the code to Draw the button. Naturally, we make it a separate routine, rather then embedding it into, say, the ListView Ownerdraw method like some sort of uncultured savage:

Alright, so now we have some logic to draw the button. For convenience, we’ll plop the functionality into a class, that can be used at run-time to basically say “hey, Class instance, draw a button for this column alright? In the code this is accomplished by Storing state information in a Dictionary which indexes Column information by column index, and the column information class has it’s own item information which maps a ListView Item to the appropriate button state information for the button, which includes information such as whether to draw the button at all. We can map an X-coordinate in the ListView’s client area to an appropriate column by taking the columns in display order and finding the column where it “crosses over” width wise. This can be done by ordering the columns by their display index. I took a rather straightforward/basic approach and just go through them and add them to an int=>int Dictionary, then return the sorted values:

The column information has it’s own dictionary associating ListView Items, which is used to retrieve the appropriate state information. We can determine the “Row” position fairly easily by using the ListView’s HitTest and then using that ListItem (if any) as the indexer into this dictionary paired with the determined column. This allows us to take a mouse position and determine what “button” it is over and react accordingly.

For mousing over a button, we want to have it show the “Hot” button image. Furthermore, we of course also want to have any other “Hot” button stop being hot. Since a Windows system can only have one mouse, we can presume there can only ever be one hot button and one pressed button, so we’ll store the button information for the pressed and hot buttons into an instance variable. On Mouse Over, if we detect the mouse is not over the hot button, we’ll change the current hot button back to normal; if it is over a button, we then change that to the hot button. For added effect, we also unpress the pressed button while the mouse is not over the button, to emulate a typical Windows Button control. Mouse Up will only activate the event for the button- fired by the helper class, and passing along information about the listview item and the column index clicked – if the mouseup event occurs over the pressed button. Lastly, there is some helper logic where the MouseLeave event is hooked to make sure there are no buttons pressed or hot when the mouse leaves the listview.

One interesting caveat I found is that if FullRowSelect and MultiSelect are off, the ListView appears to fire a MouseUp event immediately after the MouseDown event; It’s unclear if this can be fixed through code, but I wasn’t able to do so; it’s something to keep in mind. Of course, with Multiselect on, the selection rectangle looks a tad wonky with the buttons there, too.

Posted By: BC_Programming
Last Edit: 02 Feb 2016 @ 09:19 PM

EmailPermalinkComments (0)
Tags
 11 May 2015 @ 11:50 AM 

A bit of a shorter post. Sort of a “progress” report on some of the personal stuff I’ve worked on recently.

BASeBlock

I’ve come to form a love/hate relationship with BASeBlock. This is mostly because there are a lot of things I like about it’s design, and a lot of things I hate, and the things I dislike tend to be difficult to change. Some of the basic dislikes includes a lack of DPI support and how it won’t actually scale to larger sizes. On my monitor it is now tiny which is annoying and pretty much trash in the form of an action game. I’ve brainstormed a few solutions. The simplest would be to simply scale up the bitmap that get’s drawn to the screen. That is still a pain but is doable. Another would be to go a step further and actually scale everything in the game itself to larger sizes. That would be a rather large undertaking, to the point that I’m not even sure it would be worth the effort. I made a few minor revisions to try to get it to scale using the first method but ended up shelving that work for the moment. It’s rather disappointing to find such glaring problems with your old projects that you put so much time into, and almost painful to even consider just shelving the project entirely and just moving on. I certainly made a lot of mistakes with BASeBlock but I think it does well for a game using such basic capabilities (GDI+ drawing for a Game is rather unorthodox!).

Prehender

3-D programming is incredibly annoying and uses math that is far beyond my abilities to actually comprehend. Viewmatrices, rotation matrices, dot products. It’s basically a case of Googling to find out how to do things, then hoping I can figure out how to get the math to work with OpenTK. Nonetheless, I have managed to make a bit of progress.

As with BASeBlock and realistically any game I make going forward most likely, it’s primary purpose is for learning stuff. BASeBlock is at this point “learning” how to refactor an old codebase to improve it, whereas originally it was for learning C#. Prehender is going to be both applying the design techniques I learned since creating BASeBlock as well as being my first 3-D game. With that in mind, it is a rather simple concept.

Originally, I was going to just create some sort of 3-D Block breaker. I have a rather unhealthy fetish with them or something. But I decided to change it up a bit. I decided to “steal” a bit of the design of the 2-D Game, “Spring-up Harmony” which effectively uses a physics engine, and you shoot coloured balls at coloured blocks. If you hit a matching block it will “loosen” from the static background and will interact with other blocks. Then you can catch them with your “bucket” at the bottom of the screen. I haven’t worked out all the details but right now I have it so you shoot coloured balls at an arrangement of cubes, and when a coloured ball touches a coloured block, the block loosens and will fall. I haven’t actually figured out the gameplay specifics, though. That does bring me to the title, though- 3-D programming is quite difficult. I haven’t used Unity before, I may give it a go at some point, however my interest in creating games is typically in what I can learn about actually making them- Unity seems to be more for people interested in making games, as it abstracts some of the parts I find interesting. But in my case, I’m using C# and OpenTK. Unfortunately this means I get the fun of dealing with concepts such as Projection and View Matrices, Dot Products, cross products, and the like. My math also fails me as I’m not able to determine the Camera position from the projection and view matrix, which is a bit goofy when I want to shoot the balls from the position of the camera.

On the bright side, this does make it (IMO) a more useful learning experience. I find it rather strange that I’ve had to resort to third party libraries (OpenTK and BASS.NET) for providing 3-D display and compressed audio capabilities into my C# Program. XNA has been rather left behind (Though still works) and it has a few omissions that I found frustrating when I was working on BCDodger. I would hope that .NET is given first-party support for creating games in the future that makes the task much easier but allows us to use the full power of .NET and C#. Sort of an XNA successor allowing us to also publish to XBox One. (Heck if such a library was made available even at cost I think I could justify an XBox One.)

BCSearch .NET

BCSearch, my VB6 program works, but working on it is pretty much a non-starter these days. I am impressed with the patience I used to have working with Visual Basic 6 only 7 short years ago. Some features of the program will simply not be brought to completion.

Instead, I would like to create a modern WPF Windows Application that uses modern programming (and async await and such) for the same purpose. The effective goal is to create a rather straightforward on-demand search program. This differs from standard Start->Search and the search tool of Windows Explorer in that it is a full application oriented around searches and dealing with the results of those searches. I often find myself trying to find files based on rather specific criteria, and in that context I can see myself using an imagined BCSearch.NET that allows me to write a short C# method in a textbox for filtering each file. This would also allow me to rethink some of the weird architecture decisions I made with BCSearch, while also allowing me to work with WPF again (my work is almost exclusive Windows Forms, and the last time I really worked with WPF was with BCJobClock).

Posted By: BC_Programming
Last Edit: 11 May 2015 @ 11:50 AM

EmailPermalinkComments (0)
Tags
 22 Dec 2012 @ 1:15 AM 

In a first, I will actually post something not programming related, but not one of my innumerable nonsense stories, either. Today, I will write about Graphics Design.

Now, I’m no Graphics Designer- I don’t know the theories, and I didn’t go to Art School or any of that. So bear in mind that none of what I am about to say is expert advice in that domain area. Asking a programmer about Graphics design is the equivalent of asking a Plumber about Piloting an airplane. Thankfully, however, the former is a bit less dangerous.

My forays into “Graphic design” was basically “screw around in Paint Shop Pro until I end up with something that doesn’t look really bad”. It was really necessary; when creating a GUI Program, you need icons and other images for your User Interface, and when creating a game you need even more. Unfortunately, aside from what I had to make, I didn’t really get much practice. I had photoshop for quite a long time before I even used it, instead preferring the tools I was used to.

However I got into a subject that I found interesting, and that was ripe for use in creating various graphics. That subject was, I’ll admit, the newer “My Little Pony” Show that is becoming popular. I won’t defend that particular interest here, since this is neither the time or place for such a discussion, but the point is that it gave me something to work with. My original foray into using Photoshop to create Desktop wallpapers with that subject matter were merely for my own personal use. I shared them with some friends- one of which who is an artist himself- and they agreed that they were well done. They ended up getting featured on a site devoted to the subject as well. I continued to sharpen my skills by simply making more and more of them. Not all of them are awesome, but over time I learned quite a few photoshop tricks, and more importantly became quite familiar with the program, which I’d argue was the entire point. Now I’m also able to create the other graphics I need with ease, too. Here are some of my favourites:

This is rather one of my favourites. The Subject here is a Phoenix character, who is a pet of one of the other characters. I like this one because it really matches the character- I mean, it’s fiery and explosive- much like a phoenix. Inset and with a particular layer filter applied, the character who’s pet this is is visible too, which I thought was a nice effect. My primary three tasks when creating one of these is really just a few steps- first I create the background, then I paste in the vectors, then I create the text. The first and last usually take the most time, but it really depends on what I work with. Some compositions use 3ds Max for parts of the background, and mix them with other creations, and so forth.

Over time I did run out of subjects and characters to use from the given subject matter. (I do have around 160 Wallpapers now, so that should come as no particularly big surprise to be fair). Then I got the idea for “mixed” subject matter. For example:

 

What made this “project” appealing was how many things I needed to do. Here I mixed Stargate- which is one of my favourite shows- with the aforementioned subject matter (which I’m trying to avoid naming so this doesn’t get to high a pagerank for that subject). This required work in 3ds max (for the Stargate itself, as well as part of the “wormhole” effect shown inside as well as Photoshop to plop it all together. The image in the middle depicting several characters from the formerly named subject matter was created as a separate image, then pasted into this one. The portions that extended outside the gate area were chopped off,  and various effects as well as a layer mask were added to create something I was happy with. The text on either side are lyrics from songs that are present in the aforementioned subject matter; these are written using a Font from Stargate, which serves to make it an interesting “Easter Egg” for anybody that attempts to determine what the text says.

I guess my point is that some of what I created is- at least in my opinion- pretty awesome. Considering that I had hardly even touched photoshop a month or so previous, I’d say it was some improvement. I’m still looking for a good project that is attainable to do in 3ds Max that would go beyond standard poly editing and whatnot.

Anyway, my point? I’m sick of freelancing regardless of the task itself. It’s an unstable income source, and it requires far too much independence in the form of disparate commitments. My problem is that I can’t bring myself to overcommit; if I don’t think I can do something, I won’t even bid on a project at all, and I frequently underbid. More importantly, what do I identify as? Myself? Fake CEO of the “fake” company that I pretend to have started but which exists only as a set of logos I staple onto my products? Basically, I’m sick of it being only me. It’s nice to have your own projects, and guide the direction they take, but too much independence in that fashion is actually quite, well, annoying. The problem is sometimes I just want to program something. What I will sometimes do in that case is visit Project Euler and some of the more advanced questions, but these have pretty much no real practical application. I guess it boils down to the fact that managing and seeing a Project through to the end is something I can do, for the most part, but would prefer not to; some parts are frustrating, and most importantly it’s trying to remember all the things I haven’t done that can be annoying; I need to program  this… I need to mnake the graphic for this component… I should add something here using a graphic… maybe I should do this… The installer should handle this… etc etc. It’s overwhelming, and as my portfolio of projects grows, I find maintaining them to be more and more annoying.

Some might argue that the reason is that I have nobody but myself to blame if things go wrong. While that’s true, I don’t think blame is really the appropriate word. Fact is I think that a group of developers is far more likely to have a more diverse set of skills that they are good at, and those skills can be put to use as needed to work towards the goals of the project. One person doing all of them will result in some parts either being a massive pain, or just sucking. BASeBlock is a good example of this: the Music is downright terrible and repetitive. And yet, that short, 2 and a half minute “composition” (if we can even call it that) took nearly a month to create. Compare that to the implementation of Block Categories via Attributes into the game itself, which was maybe a few hours from start to finish, and it becomes clear that there is quite a bit of disparity in what I’m good at.

Even so, I do enjoy dipping myself in the cheese fondue of other skillsets; Sort of like how I will delve into programming languages I was otherwise unfamiliar with and attempt to learn them, because it can sometimes bring insight into my “main” focus, which of course is on the Programming. Everything else I do is either to support that goal or just faffing about.

Anyway, what I’m driving towards is that I’m sort of looking for a “proper” job. This freelancing stuff, in some ways, just makes me look like a prude. And I am always working with different people, who have different attitudes and it can be quite annoying; One project the person is an absolute peach, and the next they are complaining that a button was one pixel off. Consistency. That is the goal here.

I’ve been bumbling about and checking kijiji and Craigslist on and off for openings nearby. There have been a few and I’ve gotten a few Interviews as well but nothing has come of that yet. I’d argue that my resume “intimidates” people, but that’s ridiculous. If anything, it looks like a bunch of stapled together acronyms. Another concern I can see being the case are two things: First, somebody with this many things on his resume is probably a bit of a Jerk, and second, “we can’t possibly afford this guy”… the irony here being that me even mentioning the latter almost confirms the former; I hardly think my skills are worth that much, since only some of them are really the type of skills I feel safe marketing.

The big goal here is not to get something super lucrative, by any means. I don’t think of myself as a John Carmack or a John Romero, despite the stupid opinions of some of my friends, who seem to think that being able to replace a Video Card should qualify me for some sort of award, I’m just one person. I already tried making headway as one person, and it only worked a bit. Trying to maintain this blog, all sorts of projects, and innumerable other responsibilities is quite annoying- there really is no distinction between work and play; one minute I’m working on a Database Application, the next I’m playing Minecraft, and I’m simply sick of this sort of thing.

The ideal goal is not to find a job where I am the “smartest” person. That’s just self-indulgent. The Ideal would be to work somewhere where everybody else is smarter than I am. In some ways I already feel a bit fraudulent- I touched on this in my post about receiving the Microsoft MVP Award- But part of me also thinks this is a good thing. If you continue to think you really aren’t “qualified” for what you are doing, you will always strive to learn more. And from what I’ve read, this is a quality shared by a lot of very competent engineers, so I’m in good company. It’s also probably better to be ignorant of how good you are than ignorant of how terrible you are, too. That’s kind of why I’ve had issues selling myself- I mean, Whatever I say makes me feel like I’m self-important- which is the tricky part.

Anyway, May as well share a recent Interview experience. Perhaps my readers can learn from it- either what to do, or, more likely, what not to do. I’ve not gotten a reply back in regards to this particular opportunity, and it’s one of those ones where afterwards, you really can’t decide if it went really well, or if it went absolutely horribly. It’s one of those ones where you can imagine yourself leaving and the people inside either going “hmm, he seemed OK” or “wow what a tool that guy was”.

It started, obviously, from my typical circumstance where I occasionally browse for opportunities. According to my E-mail sent folder, I sent this application on the 3rd. Now, overwhelmingly, I don’t actually hear back anything from these places. One location, Wirestorm, had already filled the position, but added me to a “shortlist” of candidates for a position they felt they would need in the future, and let me know of this (and asked if it was OK).

I got a response on the 11th (as I write this, last Tuesday). Now, call it fate, bad luck, or the fact that the account was inundated with so much pointless facebook garbage, but for some reason I didn’t actually see the response until Thursday, which was the day said E-mail requested an interview. I partly panicked, but responded and asked if it was “too late” for that to go down that day. The response was that it would be fine. I was relieved, of course. However, at this point, I decided to, you know, figure out who I was dealing with here, seemed like a reasonable first step. Normally when I apply to a place I will do some basic research on them, too. However the issue is I do that so often, occasionally the different companies and groups of people sort of mix up. My first mistake, in this regard, was that I wasn’t able to find the correct application. This was an interesting problem. The actual response I had sent was of course to one of those obfuscated Craigslist postings- at least for this one- so I wasn’t able to easily cross-reference and find exactly which application was for this place. My mistake was that I thought one I had sent way back in September was for this location. But I had sent it much more recently.

The Interview itself, I thought went well. At least, from my perspective. Though it’s hard to really tell from the 30-40 minutes that it lasted, I think I would get on with those folks rather well. There were a few trouble-spots. First, I was really more nervous than I expected. This caused issues when enunciating things, and I think I spoke really fast too. I thought it went OK, a few side discussions about things.

I guess the one trouble spot is that I don’t really have an applicable employment history; I mean, with clients I don’t typically keep in contact beyond the project duration. Arguably, I could, but then I might seem needy. I do have some very satisfied clients that I doubt would think twice before giving me a recommendation, but they haven’t been active on the site for ages. The only other employment is far more low-rung- eg. Tim Hortons.

There is an interesting side-point to that though, since at that Job I had to deal with a rather badly-designed touch-screen interface, written in, from what I could tell by using Reflector on it, in VB.NET, using hard-coded database passwords to boot. I didn’t do anything with it, but I did make a mental note of some of the usability flaws that it had. Those “notes” came into play somewhat for BCJobClock, where I bore in mind that the application was not the focus of the task people would be performing; they were doing their Job. This meant everything should be otherwise smooth. The UI should be basically invisible, if done properly. I don’t think I quite got there with BCJobClock, but hey, it does the Job.

I’m keeping my fingers crossed for the moment,  from what I saw they seemed like a pretty epic group of people that I could learn a lot from. I was also really bored and redid their logo for some reason in Photoshop. I’ll keep it to myself, if they go with me I can show them in person, and if not I’ll probably send them a copy of it anyway; though I don’t think it’s much of an improvement from the original and I couldn’t find the correct font for it, though I found something close. It was mostly for practice.

 

Posted By: BC_Programming
Last Edit: 22 Dec 2012 @ 01:20 AM

EmailPermalinkComments (0)
Tags
Categories: Graphics
 23 Nov 2012 @ 11:04 PM 

Axialis is currently having a 50% off promotion on all their products for the weekend. I highly recommend giving their products a look see. They can be found at their website, http://www.axialis.com/.

disclaimer: I am not affiliated with Axialis in any way, and write this completely of my own accord. There are no strings attached, I do not get a special discount for sending people to their site to view their products. I just think they are doing some bloody fine work in the area of Icon designs as well as the products for making Icons and want to spread the word.

Also: Shortest post ever!

Posted By: BC_Programming
Last Edit: 23 Nov 2012 @ 11:09 PM

EmailPermalinkComments (0)
Tags
Categories: Graphics
 23 Jun 2012 @ 8:56 AM 

I made a new wallpaper. This one is simpler than some of my others, but I think that suits it well.

The tricky part was the logo. All I could find were the relatively small versions visible in some of the existing logos and headers.

I did find a slightly larger version in a tutorial of some sort being used as an example; I was able to take that small image, delete the white portion, applied a 100% black colour overlay, and used Illustrator to “trace bitmap”; then saved that as an EPS, opened that back in Photoshop with a high resolution, and used that image in a two-layered approach with different bevel settings to approximate what the logo might look like at a higher resolution. It looked a bit bland, so I also used a mask to block out part of the text of 1’s and 0’s.

Since I’m here, may as well plonk out a few other wallpapers I made.

Space & Science

This one was made for spaceandscience.co.uk:

This one was a gigantic pain. I managed to get a nice asteroid mesh by doing some funky noise and smoothing and stuff on a sphere with a bajillion (give or take a few) different faces. The comet trail is sort of a cheat though. I rendered the 3ds max image twice: one with only the asteroid visible, and one with everything else. I used the one with only the asteroid, applied a color overlay of white, merged it with an empty layer to rasterize the overlay, and then used a motion blur in the desired direction. Plopped over top of the original asteroid image, and then the “everything but the asteroid” render, and there it was. (I did some additional tweaking, such as making a third layer with the motion blur and messing with dissolve to try to make “ice particles”, or the appearance thereof) I had to add the text too, but that was pretty much the easy part. Another piece of trivia that might not be immediately obvious: the Earth is showing only the UK. Thought that was pretty cool.

BaseCamp Programming

And of course I had to make one for myself at some point!

Not much to say for this one. I did have to re-create the mountain logo at a higher resolution, which I managed to do the same way I did in the CH wallpaper (although I did mine first, having only made the CH one a few hours ago…). Basically trace in Illustrator, save as EPS, import, and profit. I use the binary 1’s and 0’s here too. (side note: I didn’t type the 1’s and zeroes, I wrote a quick C# program to do it for me:

compiled that straight at the command line, used genbinary > bin.txt, opened bin.txt in Editpad 7 (A program I should possibly write a review of) and then pasted it into the text object in Photoshop. (the const values are what I used for the CH 1’s and 0’s; I used smaller values for the BC Wallpaper).

I made over 100 other wallpapers but they are mostly MLP (there are a few star trek ones, too). If I was to write out the details of how I made them all I’d be typing for days! So I chose this subset.

I also made a wallpaper for GlitchPC.net but that’s another bag of oysters…

Posted By: BC_Programming
Last Edit: 23 Jun 2012 @ 08:56 AM

EmailPermalinkComments (0)
Tags

 Last 50 Posts
 Back
Change Theme...
  • Users » 44271
  • Posts/Pages » 365
  • Comments » 105
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

PP



    No Child Pages.

Windows optimization tips



    No Child Pages.

Software Picks



    No Child Pages.

BC’s Todo List



    No Child Pages.