micolous.id.au

the result of a blogging accident

Tuesday, August 24, 2010

portal2 API v2.8.3

Filed under: Coding, Lanning, Projects — micolous @ 00:40

There’s been a minor change to the portal2 API as of v2.8.3 (to be deployed at LAN 10.09). Functions which attempt to identify you (usage, usage_history and whoami) will attempt to use cookie-based authentication before attempting to identify your computer by MAC address.

This will allow in-browser applications to determine the identity of who you are logged in as before attempting to fall back to who owns the computer.

In other news, portal2 v2.8.3 now has a couple of other changes to it, such as support for clustering and a new graph on the usage page which is generated client side (and much faster than the server-side graph).

Sunday, July 18, 2010

Xbox 360 Big Button: Round 2

Filed under: Coding, Toys — micolous @ 18:29

So, time for round 2 with the Big Button controllers. I covered this stuff a bit yesturday.

I’ve since updated the driver so that it treats the directional buttons on the big button controllers as the X and Y axes. This means that joydev.c will now detect the xbox360bb as a joystick driver, and so ordinary programs that use Linux’s joystick API can receive events from the controllers (and not just those that use evdev).

I also wrote a simple pygame version of Simon. This works whenever you have four joystick devices attached to your computer. You play by pressing any button on the controller. The colours match up to how the Big Button controllers are presented in xbox360bb. As soon as one person makes a mistake, the game ends. The loser is reported on the console.

Saturday, May 1, 2010

portal2 2.8.1 API documentation

Filed under: Coding, Lanning, Projects — micolous @ 05:57

There have been some requests that I make portal2’s API documentation available online and not just available at LANs. So I have published a copy of the portal2 API v2.8.1. This covers the (at the time of writing) current version of portal2’s HTTP GET and XMLRPC APIs.

Unfortunately, there’s no online “simulator” available, but that should be trivial for someone to write if they’re testing their program.

Thursday, April 22, 2010

TrolledFS: A filesystem with fake file contents

Filed under: Coding — micolous @ 06:30

My friend [gm] had this idea for a filesystem. It would take a real filesystem, and then whenever a user requested to open a file, it would instead give them a contents of another file from another folder, determined by it’s file extension. For example, it would map all AVI files to a single AVI file in another folder.

Because he didn’t implement it, and I got bored, I ended up writing “TrolledFS” as a FUSE filesystem module in Python.

The module requests two options, root, which is the directory that provides the structure of the filesystem (ie: it will appear to be a copy of this folder), and fakes, a folder containing replacement files. So if you requested example.avi, it would map it to the first file with the AVI extension in the fakes folder.

It is based on the Xmp.py (example) filesystem module from FUSE’s Python bindings, with all of the write calls filtered out. Instead, filesystem will say it is a read-only filesystem. If a file has no match in the fakes folder, the filesystem will say there was an I/O error.

Tuesday, April 20, 2010

Smooth scrolling marquees in GTK#

Filed under: Coding — micolous @ 05:36

Marquees aren’t normally supported in GTK#. You have to write an implementation yourself, using the ViewPort and Label controls. You can do that with this bit of code. It’s a bit of a hack, you need to add a bunch of whitespace to your text to display so that the text properly “scrolls in” at the start, and scrolls out properly as well without graphical glitches. This code runs nice and smooth by moving the text to the left by 3px every 33ms (so it works out to about 30fps).

Video demo (or you can watch it on YouTube):

You need to put this code inside your Gtk.Window.

public partial class MainWindow : Gtk.Window
{
	// viewport which we use to contain the label and handle the scrolling of the marquee.
	private Viewport vpMarquee = new Viewport();

	// marquee text should have some padding before and after the text, to avoid rendering errors, and
	// to allow the text to "flow in" when it is reset after reaching the end.
	private Label lblMarquee = new Label("                                                                                                 [lblMarquee] Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec metus quam, ullamcorper eu suscipit quis, rutrum sit amet massa.                                                                                                 ");//" Nunc dapibus accumsan metus, commodo placerat urna blandit non. Nullam turpis justo, dictum quis dignissim non, vehicula vel lorem. Fusce congue purus odio, lobortis pulvinar neque. Integer dui odio, venenatis sed tincidunt in, fringilla id urna. Maecenas faucibus massa eu orci tincidunt ac vulputate nibh aliquam. Aliquam ullamcorper erat nunc. Vestibulum hendrerit adipiscing neque quis interdum.");

	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		// normally you'd be using Stetic, so you need to call it's build-constructor.
		Build ();

		// add the control to the window.  in this example, i'm adding it to a VBox control as the last element.
		vpMarquee.BorderWidth = 0;
		vpMarquee.Add (lblMarquee);
		this.vbox1.PackEnd (vpMarquee, false, false, 0);

		// update marquee every 33ms (~30fps)
		GLib.Timeout.Add (33, new GLib.TimeoutHandler (MarqueeUpdate));

		// add other code here for other things...
	}

	bool MarqueeUpdate ()
	{
		Application.Invoke (delegate {
			// calculate the total amount of space the marquee requires.  this only works because I've manually set the size of the window,
			// otherwise you need another way to get the width of the window instead of this.
			double n = vpMarquee.Hadjustment.Upper - this.WidthRequest;
			if (n < 1)
				// safety incase we don't have an actual width calculated width
				n = 1;

			//Console.WriteLine("{0} > {1} ?", vpMarquee.Hadjustment.Value, n);
			if (vpMarquee.Hadjustment.Value >= n) {
				// we've reached the end.  reset the marquee to the 0-position.
				vpMarquee.Hadjustment.Value = 0;
			} else {
				// scroll the marquee to the left by 3px
				vpMarquee.Hadjustment.Value += 3;
			}

			// tell gtk# we want it to take into account the updated value.
			vpMarquee.Hadjustment.ChangeValue ();
			vpMarquee.Hadjustment.Change ();

			// redraw the control and it's children (the label).
			vpMarquee.ShowAll ();
		});

		// tell Timeout we want to be called again.
		return true;
	}

	// ... add more stuff here for other functionality.
}
Older Posts »

Powered by WordPress