Virtual Glass Images on the fly : Part 1

Posted by Darin Rousseau | Filed under ,

I am sure that you have personally witnessed the new trends in UI.  Everything seems to be 'glassy', reflective or whatever the term is these days. 

I think it was Apple that first mass-produced virtual glass on iTunes in their CoverFlow control - but it has been in other applications and now all over the web.  I recently had a requirement within one of my web projects that asked for glass - but it had a twist.  The client also wanted the site to be able to be themed.

Creating a shadow in an object in code is simple - you take the image, add some space to the bottom, flip the image and draw it upside down, add a gradient from partially opaque to the background color as you go down, and, you have a fancy, glassy, faded shadow!  

But what if you can't determine what the background is at runtime, for example like on a website?  This is the exact problem with themes and glass together.  The design of the site meant that anything could be a background - even another image.  I could never use a project like Kel whipped up on CodePlex - because I can't pass in a background Color parameter, since I don't know it.  I could have forced the theme to a consistent color, but that would be limiting, and potentially not what the client wants. 

Our next course of action was to see if Internet Explorer and the other browsers could handle Alpha-Blending in the PNG format, since PNG is one of the formats that supports alpha. (JPG and GIF don't, although GIF can have fully transparent sections.)  Luckily, most modern browsers could. 

The final challenge - how do you get an alpha-blended shadow in an image?

I went back to some Windows Mobile code that I had worked on that I had based on another article on-line (where, oh where did that article go?)  - where I copied the alpha from a GradientFill stencil. The basic process for the entire operation is as follows:

  • Take the original image and resize it to add space for the shadow.
  • Draw the original image at the top
  • Rotate the original image 180 degrees and flip it.
  • Draw the "shadowed" image under the original.
  • Create a new bitmap as a stencil
  • Draw a GradientRect with alpha blending
  • Lock the bits of the stencil
  • Copy the bitmap bits into an array
  • Lock the new image, put the new image bits into an array
  • Copy the alpha channel from the stencil to the new image.
  • Release the bits for the new image.

... Stay tuned for part 2 and source...

Coding challenge

Posted by Darin Rousseau | Filed under ,

During the hiring process, Fundamental Software Solutions has always passed small tests of skill to potential developer hires.  We don't ask much - just spot some commonly made mistakes, or identify what will most likely happen with some sample code.  Now, we haven't been been the only ones doing this - and for good reason.  Programming skill is highly varied.  Does it work?  So far.

Now for some fun.  We have stumbled across the results of one particular interviewee of a pretty major company looking for C++ programmers.  The interviewee was asked to create a small, efficient program that would take the input from a user and make it lowercase, without using any pre-made library functions to do the 'lowercasing.'  The text will be plain, old ascii english characters, so don't worry about UNICODE or anything like that.

Here is a modified result of what was written.  (We modified it to protect the job seeker from being googled, but the code is essentially the same.)

  1. char * MakeTextLower(char *ptr) 
  2. {   
  3.    while (*ptr != '\0'
  4.    {   
  5.       if (*ptr > 'A' && *ptr < 'Z'
  6.       {   
  7.          *ptr -= 'A' - 'a';   
  8.       }   
  9.       *ptr++;   
  10.    }   
  11.    return ptr;   
  12. }  

 There are at least two problems with this code that make it non-functional.  Can you spot them? 

 [Edit: For extra credit, the function is also going to return the wrong thing.  Can you tell us what will be returned?]

Retrieving Mobile Peak Schedule from ActiveSync

Posted by Darin Rousseau | Filed under ,

I had the pleasure of creating and working with some "always up to date" applications on my Windows Mobile Device, and have tested some other manufacturer's products that do similar things.  One thing I really hate is having to set peak times or configure when data transfers should occur in every application differently.

For some people, it may be beneficial to have mail syncing at a separate schedule than for something like phone-coordinate tracking, but sometimes it is nice to should be able to set those settings ONCE if I choose, and let all my software follow that one setting.  For example, I often reset ActiveSync's schedule when I travel to avoid costly data transfers when I don't need to check my mail.  I really hate when I get the bill the next month after I forget one app!  Maybe allow the user to choose "follow activesync" or "use custom settings" or something like that if you need more precision than just M-F and a start/end time.  For most of our customers, ActiveSync's schedule is exactly what they needed.

So, For all the developers out there making software that communicates over the air - I have posted some source code(below) that will tell you if the current time is "syncable" and if not, will tell you the next time when a transfer should be allowed.

For example:

if(FSSI.Mobile.ActiveSync.Settings.IsInPeak(DateTime.Now))
{
   // Do something.
}

or, to check when the next sync time is (such as when planning when to wake the device to Sync....)

DateTime TimeToWake = DateTime.Now + new TimeSpan(60,0,0);
TimeToWake = FSSI.Mobile.ActiveSync.Settings.MakePeakTime(TimeToWake);
if(TimeToWake == DateTime.MaxValue)
{
     // The sync settings say that no future days are valid (no sync days)
}
else
{
     // TimeToWake is set to the next available Sync time on or after the passed in value.
}

Project Source and Demo Project: