In my
previous post I described some work I spent optimizing my .NET code to make it perform well on an iPhone. I expect I'll have a follow up post when I do more optimizations in the future, but next I want to take a slight detour from coding to discuss a small battle I had with getting Blogger to work well with the type of info I'm posting.
Before getting into that discussion I want briefly give an update on the game. These blog posts are lagging actual development by a couple months. Basically it takes me a while to finish a blog entry, so I try to queue them up and revise them when I have time. So, in reality the game is coming along pretty well. It is still slow going because I can only put in a few hours here and there, but it is progressing nicely.
Now, on to fighting with Blogger...
So, as mentioned above, I wanted to be able to post source code that looks good and has syntax highlighting. Initially I tried a simple solution that I know worked to some degrees from my previous experience, simply copy the code from Visual Studio (VS) and paste into Blogger. Oops, no, that doesn't quite work. If you do that no formatting is included. But, if you copy and paste into Word then it is included. Hmm, ok, how about copying and pasting into Word, then re-copying from Word and pasting into Blogger? Yep, that works, and gives output like below:
/// <summary>
/// Binds the texture.
/// </summary>
/// <param name="textureData">The texture data.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>The texture's bound id.</returns>
private static uint BindTexture(byte[] textureData, int width, int height)
{
uint textureId = 0;
GL.GenTextures(1, ref textureId);
GL.BindTexture(All.Texture2D, textureId);
All format = (System.Environment.OSVersion.Platform == PlatformID.Win32NT) ? All.Bgra : All.Rgba; // useless comment placed here just to make the line very long
GL.TexImage2D(All.Texture2D, 0, (int)format, width, height, 0, format, All.UnsignedByte, textureData);
textureData = null;
GL.TexParameter(All.Texture2D, All.TextureMinFilter, (float)All.Linear);
GL.TexParameter(All.Texture2D, All.TextureMagFilter, (float)All.Linear);
GL.Enable(All.Texture2D);
return textureId;
}
Actually, the above is wrapped in a
pre, which I have styled to make the grey background and such. But, there's still a problem, the long lines wrap and make it harder to read. So, what I really want is for the code area to scroll horizontally when the lines are too long. Fortunately, a bit of CSS can do that:
.csharpcode
{
font-family: Consolas, "Courier New", Courier, Monospace;
margin: 0em;
padding: 0.5em;
border: solid 0.1em #000000;
background: #222222;
white-space: pre;
white-space: nowrap;
overflow: auto;
overflow-y: hidden;
}
So, if I change the simple
pre to
pre class="csharpcode" then I get the following instead. Notice the horizontal scrollbar and the long lines no longer wrap.
/// <summary>
/// Binds the texture.
/// </summary>
/// <param name="textureData">The texture data.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>The texture's bound id.</returns>
private static uint BindTexture(byte[] textureData, int width, int height)
{
uint textureId = 0;
GL.GenTextures(1, ref textureId);
GL.BindTexture(All.Texture2D, textureId);
All format = (System.Environment.OSVersion.Platform == PlatformID.Win32NT) ? All.Bgra : All.Rgba; // useless comment placed here just to make the line very long
GL.TexImage2D(All.Texture2D, 0, (int)format, width, height, 0, format, All.UnsignedByte, textureData);
textureData = null;
GL.TexParameter(All.Texture2D, All.TextureMinFilter, (float)All.Linear);
GL.TexParameter(All.Texture2D, All.TextureMagFilter, (float)All.Linear);
GL.Enable(All.Texture2D);
return textureId;
}
The only remaining problem is that this HTML that comes from VS via Word is
very verbose. Just the very first line, a comment, contains all of this HTML:
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: grey; font-family: Consolas; font-size: 12pt;">///</span><span style="color: green; font-family: Consolas; font-size: 12pt;"> </span><span style="color: grey; font-family: Consolas; font-size: 12pt;"><summary></span><span style="font-family: Consolas; font-size: 12pt;"></span></div>
So, the entire code block ends up being quite a lot of HTML.
To address this issue I actually jumped through a number of other hoops to create less verbose HTML. In fact, the earlier pages in this blog use that simpler HTML. But, going forward, I've decided to use the above method. It is easier and creates more nicely formatted output. It is a bit more verbose, but then if you look at all of the other CSS that Blogger includes the pages are pretty heavy to start with.
I actually might go back and reformat the previous pages at some point, so the above statement might become inaccurate.
Anyway, I guess my fight with Blogger is a lot less interesting that I thought. As I was figuring out how to do all of the above it was annoyingly painful. But not that I have a solution it is pretty simple.
Next time:
More MonoTouch Gotchas.