micolous.id.au

the result of a blogging accident

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.
}

Thursday, April 15, 2010

Clearing the “Mounted Devices” database in Windows

Filed under: Computers — micolous @ 08:31

Something I found useful when doing image deployment of Windows: being able to clear the mount devices list. In some instances, Windows will not boot properly or it will boot from the wrong device until you do it. You don’t need to do this with sysprep (it does it for you), however sysprep won’t work in an iSCSI configuration due to redetecting the network card and resetting all the iSCSI configuration.

For this, you can use the chntpw utility.

First of all, mount the Windows partition.

Then crack it open with chntpw’s registry editor, and remove the entries.

# chntpw -e WINDOWS/system32/config/system
chntpw version 0.99.6 080526 (sixtyfour), (c) Petter N Hagen
Hive  name (from header): 
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c 
Page at 0x54f000 is not 'hbin', assuming file contains garbage at end
File size 5767168 [580000] bytes, containing 1254 pages (+ 1 headerpage)
Used for data: 108658/5500560 blocks/bytes, unused: 1836/21680 blocks/bytes.

Simple registry editor. ? for help.

> cd MountedDevices

You can now show the mounted devices table. This one is populated with a bunch of stuff:

\MountedDevices> ls
Node has 0 subkeys and 8 values
  size     type            value name             [value if type DWORD]
    12  REG_BINARY        <\??\Volume{a04045a6-480a-11df-8146-806d6172696f}>
    12  REG_BINARY        <\??\Volume{a04045a7-480a-11df-8146-806d6172696f}>
   238  REG_BINARY        <\??\Volume{a04045a8-480a-11df-8146-806d6172696f}>
   164  REG_BINARY        <\??\Volume{a04045a9-480a-11df-8146-806d6172696f}>
    12  REG_BINARY        <\DosDevices\C:>
    12  REG_BINARY        <\DosDevices\D:>
   164  REG_BINARY        <\DosDevices\A:>
   238  REG_BINARY        <\DosDevices\E:>

Removing it is as simple as the ‘delallv’ command.

\MountedDevices> delallv

\MountedDevices> q

Hives that have changed:
 #  Name
 0  
Write hive files? (y/n) [n] : y
 0   - OK

And then it’s done. You can unmount the partition, and boot Windows again.

Tuesday, March 2, 2010

Internode Radio playlist files for XBMC (and others)

Filed under: Uncategorized — micolous @ 13:07

I got bored and created playlist files for all the radio stations that Internode mirror. They point to the playlist files on the page so should keep updated if the servers get changed again.

This file doesn’t update at all if a station gets added or removed from the list.

In XBMC, you just have to put this ZIP file in a folder it uses as a source, and you can browse into it and play radio stations without extracting the archive. In other players, you have to extract it yourself.

Download the archive.

Update (2010-03-16): Internode added automatically generated playlist files to their website in various formats, rendering this obsolete.

Wednesday, February 17, 2010

SDL VNC Server module (v2)

Filed under: Coding — micolous @ 02:01

Time for a version two! There’s a new version of the patch to SDL 1.2.14. You need a clean source tree with this, so remove v1 of the patch before applying this one.

Changes:

  • Mouse cursors now work correctly.
  • You can now disable the “always shared” function of the VNC server and allow a client to take exclusive control with SDL_VNC_ALWAYS_SHARED="0".
  • You can change the display number manually with SDL_VNC_DISPLAY.
  • 8 bpp displays are now supported.
  • pygame applications work at 16, 24 and 32 bpp display depths. 8 doesn’t work properly.
  • This module now lies by default about the supported display depths reported by SDL_ListModes. It defaults to 16 bpp only, in order to make pygame work properly. You can change what it says this with SDL_VNC_DEPTH, or setting it to 0 to say all depths are supported. This doesn’t limit calls to SDL_SetVideoMode.
  • You can tell the VNC server to ignore all client events by setting SDL_VNC_VIEW_ONLY="1".

There’s also a README.VNC included, which documents the functionality of the library and use of it’s environment variables.

Tuesday, February 16, 2010

SDL VNC Server module

Filed under: Coding — micolous @ 05:15

I keep writing things related to VNC, and coding in C. It’s seriously starting to worry me.

I’ve spent the last couple of days writing a new SDL video output module, which acts as a VNC server using libvncserver. Here are the patches against SDL 1.2.14. To use VNC support, you need to run ./configure with --enable-video-vnc, and once built and installed, run the SDL application with the environment variable SDL_VIDEODRIVER="vnc".

What works:

  • 16, 24 and 32-bit true-colour displays.
  • Mouse events.
  • Keyboard events.

What’s left to do:

  • Fix mouse cursors so they display correctly.
  • 8-bit (paletted) displays.
  • Handle surface locking properly.
  • Reduce/eliminate tearing on frequent screen updates.
  • Run the libvncserver event loop inside SDL’s event loop system.
  • Implement a password on the VNC server and some sort of simple access control.
  • Implement a view-only mode.
  • Allow setting the display number manually.
  • pygame applications.
  • Fix screen resolution change colour issues.

What will never work:

  • OpenGL surfaces.
  • CDROMs, Joysticks and Sound over VNC.
  • YUV video output.

I’ve had a lot of success with using the Origyn web browser (a WebKit/SDL-based web browser) and cgterm (a SDL C64/C128 telnet client) with this output method. Any SDL application that doesn’t use OpenGL surfaces should be able to run with this output module.

Some pictures:

[origyn web browser in tightvnc] [cgterm in tightvnc]

« Newer PostsOlder Posts »

Powered by WordPress