Fun with google calculator

| No Comments | No TrackBacks
My favorite part of physics class was the abstract units.  For instance, knowing that an acre hz per mile an hour is a unit of length.

Google calculator- which is the fancy name for google search being able to do some pretty powerful math in its searches- is also capable of resolving units.  This is best exemplified by the search:

number of horns on a unicorn acre in tea spoons per light year

This makes me giggle.  So I sat down today and tried my own hand at it.  Here's what I came up with:

pi parsec yard square league newton per light year times once in a blue moon per lb mph mph mph mph

Which is about the time it takes to eat a slice of pizza.

Blogtype: Review

| No Comments | No TrackBacks
I've been reading, again, the Animorphs series.  It's about five special young people who gain the power to acquire the DNA of any creature they touch, then transform into it any time they want, with some (rather arbitrary) limitations for dramatic appeal.

It's aimed at very young teenagers.  It is/was published by Scholastic.  It shares shelf space with Goosebumps.  I am so ashamed.

Yet.. I had told myself that my faint memories of the stories being a bit mature for the intended audience were nostalgia- that from the perspective of my 13-year-old (ok, fourteen) self, the stories were mature.  But that now, at 24, they would be laughable.

Honestly, though, the stories touch on some very adult themes.  It's like Harry Potter- targeted at youngsters, but even more so than HP, it hits these dark and tragic undertones as well.  War, famine, the killing of innocents, the psychological toll, civil-war-style brother vs. brother, the definition of humanity and its difference from sentience and sapience.

A minor complaint is the somewhat forced, episodic nature of the series.  It does not feel like a story that needs to be told in 51 minibooks, but of course this was the market structure they had adopted.

The bigger problem is that I have an increasingly hard time believing in the characters.  NOT that their personalities are flat, or that they are unbelievable for being stereotyped, either.  But because they're supposed to be in their early to mid teens, and their personalities and thoughts and decisions, exposed to us, flat out don't seem believable.

I was a pretty mature young teen.  These characters are something else.  They are adults shoehorned into a youth book series.  And it's annoying.

If you can get past that, gloss over the clearly obligatory references to parents and school and homework, which are in every book but never seem to actually matter, and decide in your head that these kids are something closer to very late teens or early to mid twenties, it works better.  The characters are the strength of it, not because they're believable, but because they are singularly, wholly sympathetic.

So yeah, I'm reading books that I stopped reading at an appropriate age, five years ago.  But I have to say I've read worse books, and even worse series, in my adult life, and they weren't jumping through Scholastic hoops.  These books are good.  Brain candy.

You can view them online, apparently standing in Scholastic's blind spot, here.

Blogtype: Scrapbook

| No Comments | No TrackBacks
Click to pop.

diabeetus.jpg


puss-in-boots-totally-looks-like-i-made-you-a-cookie-cat.jpg

(This blogtype was actually the hardest so far, because I had to figure out wtf was wrong with movable type.)

Blogtype: Copypasta

| No Comments | No TrackBacks
Via joemygod:

And yet the Christianists will pull their children out of school rather than allow them to participate in any anti-bullying protest. Via GLSEN:
An 11-year-old Massachusetts boy, Carl Joseph Walker-Hoover, hung himself Monday after enduring bullying at school, including daily taunts of being gay, despite his mother's weekly pleas to the school to address the problem. This is at least the fourth suicide of a middle-school aged child linked to bullying this year. Carl, a junior at New Leadership Charter School in Springfield who did not identify as gay, would have turned 12 on April 17, the same day hundreds of thousands of students will participate in the 13th annual National Day of Silence by taking some form of a vow of silence to bring attention to anti-LGBT (lesbian, gay, bisexual and transgender) bullying and harassment at school. The other three known cases of suicide among middle-school students took place in Chatham, Evanston and Chicago, Ill., in the month of February.
The National Day Of Silence is April 17th. While little Carl's tragic end happened in their own backyard, anti-gay hate group MassResistance is leading the wingnut movement to yank their kids out of school that day, rather than witness any peaceful observation that bullying gay students is morally wrong.
Local churches here are advocating the pull-out on that day.

Blogtype: Feed

| No Comments | No TrackBacks
What I'm reading now:
  The Misenchanted Sword
  With a Single Spell

Sites I'm surfing:
  fmylife.com
  jayisgames.com
  joemygod.com

News:
  NM same-sex marriage rights move forward
  The unfortunately-named NOM has failed to register the domain for their recently-announced 2M4M campaign- it is now being subverted by "2 Men For Marriage".  Nice.
 

Blogtype: Abandoned

| No Comments | No TrackBacks
04/10/2002

hey this is my new blog there's not much here yet but there will be soon

Update (04/10/2005): hey guys I'm back and going to be blogging again! check back soon!

Update (04/11/2005): hey sorry guys things have been really crazy lately but I'm going to be writing more

Update (05/20/2005): it sucks to write here because nobody comments!  If you guys would comment I'd write more

Update (04/10/2008): I was going to set up a new blog but it looks like I already have one.  Check this space soon for more posts- or don't. I don't really care if anyone reads it or not, it's just for me.

Update (04/10/2009): I suck.

Scrolling controls in Windows Forms

| No Comments | No TrackBacks
In Windows Forms, Controls are Components which are visible.  This is how I undersand it, at least.  That is, they are pasties.

If a fridge was your form, magnets would be your controls.  Only, some of them would glow, and talk, and change their words and size and slide around.  And some would have magnets stuck to them.  (I'm surprised how well the analogy is still holding..)

Each control has a Bounds property, and this property returns a rectangle, which defines a location and size of a rectangle in Cartesian coordinates, with the top-left corner being 0,0.

The bounds of a control are defined in MSDN thusly:
"Gets or sets the size and location of the control including its nonclient elements, in pixels, relative to the parent control."

Nonclient elements- things that have been generated for you and on which you may not (probably) draw.  For instance, automatic scroll bars triggered inside a panel when its contents are put outside of its bounds.

Did you catch that?

So say a form has a panel with Bounds of 50,50,100×100.  That means that on the form, there is a panel 100×100, at 50,50.

Now say that our panel has a button at 0,0,20×20.  This means that at the top left corner of the panel (not the form) there is a button 20×20.

This is all sensible.

Now let's say we add a button dynamically, at run time, to the panel.  The code for this is:


Button b1 = new Button();
b1.Text="Clicky!";
ThePanel.Controls.Add(b1);

So we construct a button, are kind enough to give it text, throw it on the panel.  Add() will automatically set b1's parent, and b1 enters he form's message loop appropriately.  Windows Forms is lovely like that.

But we didn't set coordinates for the button.  Size, Location, Left, Top, Width, and Height are all synonyms for components of the Bounds property, previously mentioned.  The difference is that because Bounds returns a rectangle, which is a value, its members cannot be modified in place.  These properties can.

b1.Size = new Size(10,10);
b1.Left = 0; b1.Top = 0;

This is better.  But remember, it's in a panel.  If the panel moves, they will too.  There are functions for calculating a controls absolute position relative to its form, or even to the screen the form is being shown on, but this should probably not matter.  If you have a control inside another, it shouldn't ever need to know about the outside.

Controls which can hold other controls are called containers.  The thing about containers is that they don't necessarily do bound checking the way you would think.  In other words, if you place a subcontrol outside of the bounds of its parent control, it will simply clip, showing only the part of the subcontrol that has not strayed, if any.  This, also, is sensible.

The thing about panels is they have an AutoScroll property you can turn on.  And when this property is turned on, panels (and any other control descended from ScrollableControl, apparently) will do something quite handy- they will automaticaly draw scroll bars, and expand their content without expanding their on-screen dimensions.

This is incredibly handy, but the coordinates involved become absurd.

This is what I think SHOULD happen but DOES NOT:
The coordinates of a control within a scrolling container are relative to the top-left corner of the parent's surface- that is, the virtual space which is only exposed to the client through scrolling.
Here is what does happen:
The coordinates of a control within a scrolling container are relative to whatever the top-left corner of the visible portion of the parent's surface happens to be at the time you check.

I cannot begin to guess why this design choice was made.

So let's, I suppose, start with an example of how this is insane.  First, we take our panel and button from before:


Panel 100×100
Button 0,0, 10×10

We move the button so that part of it is off the panel's dimensions:

   b1.Top = 100;
When this finishes, several things happen.  First, the Panel, having discovered that one of its controls is no longer within its bounds, will sort of split.

Its bounds will not change- the panel is still positioned on its parent control (the form) at the same coordinates and with the same size.  However, its virtual size has enlarged so that it is larger- 110x100, because the button has 'stretched' it out.  At this point, some of the other properties of the panel will change.

DisplayRectangle will now have a size of 110x100.  Bounds will be unchanged, at 100x100.  ClientRectangle will shrink, becoming less than 100x100 (about 100x90).  This is because ClientRectangle represents the size of the box that is visible to the user, and now that scroll bars have been drawn inside the panel, there is less of the panel's contents exposed to the user!

This is all done automatically for you as long as the panel's AutoScroll attribute is set to true. The scroll bars will function without any additional code- the user can pan around the virtual surface of the panel.

But when you go to add another button to the panel, you may discover things operating a little strangely.  Let's say that you want to add another button at the bottom of the panel, extending it outward some more.  We add the function:


void AddButton() {
  Button nb = new Button();
  nb.Width = 10;
  nb.Height = 10;
  Panel1.Controls.Add(nb);
  nb.Left = 0;
  nb.Top = Panel1.DisplayRectangle.Height;
}

So this code should create a new button, size it to 10x10, add it to the panel, then position it at the bottom of the Panel's DisplayRectangle, causing the panel to stretch itself downward again, adding more virtual space. And this is exactly what it does- sometimes. The problem is this. If you happen to have already scrolled the panel down, the button will end up being out of place- too far down the panel. This is because a child control's bounds are not absolute when in a scrolling container.

The MSDN documentation for Control.Bounds specifies that it represents the control's size and position relative to the top-left corner of its container.  What it does not directly state is that it is relative, in fact, to the top-left corner of whatever portion of the container is currently visible.

So say you're scrolled 10 pixels down on the panel, then add a button at 100,0.  Relative to the virtual surface of the panel, it is actually at 110,0.  Say you're scrolled 1000 pixels down.  That same button is now at (and Bounds/Top will return) -890,0.

Any time the user scrolls the panel, all its child control's positions are changing to reflect their position relative to the top-left corner of ClientRectangle, rather than DisplayRectangle.  To manage positions relative to the DisplayRectangle, you will have to subtract Panel1.VScrollPosition from the result.

So to use the previous example, the button is located, relative to the virtual surface of the panel, at (button.Top - button.parent.VScrollPosition, button.Left - button.Parent.HScrollPosition).  To move it to 200,0, regardless of where the panel is scrolled to, you must set:

button.Top = 200 - button.Parent.VScrollPosition;
button.Left = 0 - button.Parent.HScrollPosition;
There does not appear to be any way to toggle this strange behavior in windows forms.  At least, none that I have found.  I'm still struggling with a few aspects of this behavior myself- there appear to be certain cases where the panel does not resize itself accurately to reflect the new positions/sizes of its child controls on the first try- but later attempts correct this.  I'll write another post on that when I figure it out- or get stuck.

I hope this helps people trying to work with dynamic forms using scrolling containers, and finding their buttons being placed strangely while debugging!

Blogtype: Technical

| No Comments | No TrackBacks
Intro

I am working the last few days on a pet project, ostensibly for work, but with applications outside.

My language of choice for most projects tends to be C#, and I use Windows Forms, having not yet acquired a legitimate copy of Visual Studio 2008.

The project requires a rich list box- the kind which contains controls of any type.  For instance, I should be able to create a list of frames which contain an icon, text, and one or more buttons.  These frames should be templated and extensible (though I decided against abstract) so that the behavior of their buttons can be hooked without adding new rich list code.

This makes it ideal for adding into my personal C# library of collected classes, JLib, but this is a little narrower, so I split off some of JLib (which had been bothering me) into JWin.

Problems almost immediately arose. For one thing, the tutorial I read about simply adding whatever you wanted into the list and having it render automagically neglected to mention that it required WPF- something I do not have and am not much interested in learning just yet.

So I created my own controls: an item control with an image and label, and a list control with a panel inside (for scrolling).

I've never been a very visually-minded person so it was difficult to wrap my head around some of the necessary concepts.  For instance, I understand how to dynamically create objects.  But learning to position them was a little wonky.

It doesn't help that, at least in C#, frames do not act anything at all like you would expect them to in terms of positioning when they are scrolled from their natural position.  Next post.

Cliche

| No Comments | No TrackBacks
It's inevitable.

I am not much of a blogger.  I think a lot, but I rarely write.  I think it's because, on some level, I'm afraid.  Who wants to have all their neatly compartmentalized sub-lives linked together?

But the core of me, the one that sees the ludicrous conglomeration of stereotypes and archetypes and career types and sexual types and body types I am, longs for expression.  That phrase was hard to type.  But it's inevitable.

I express myself well, but really, how many ways are there to start a blog?  Actually, maybe that's the answer.