Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2010-03-13
The Bar instruction, as it appears in a Monkeybone Image (a text file with .mob ending) is a line with at least five parameters. The color of the bar, the X and Y position of the bar, the width and height of the bar. The following lines in a .mob file creates a green rectangular image with a centered yellow box in it:
Clear 200x200 #337733 Bar #ffff00 X:50 Y:50 W:100 H:100
Optionally, you can set the percentage of the fill in either horizontal or vertical direction using HFill or VFill, followed by a percent value. The following code will give a 50 pixel high box. The specified height is 100 (pixels) but VFill:50% tells Monkeybone Viewer to only display half height of the box:
Clear 200x200 #337733 Bar #ffff00 X:50 Y:50 W:100 H:100 VFill:50%
One way of producing an image like this, is to use Notepad to create a text file that ends with .mob instead of .txt. Using Notepad is not the easiest way, and rather impossible if you want to generate dynamic images. For dynamically generate Monkeybone Images, the Monkeybone .NET library or the Monkeybone .NET control can be used.
The Monkeybone .NET library is a class library that contains a writer with the capability of streaming Monkeybone instructions to a file. The following Visual Basic code requires a reference to Monkeybone.dll, and produces a file called “Bars.mob” that can be opened using the Monkeybone Viewer.
Using Sw As New Monkeybone.MonkeyboneWriter("C:\Bars.mob", 200, 200, _ System.Drawing.Color.FromArgb(51, 119, 51)) Dim Bar As New Monkeybone.Instructions.Bar(50, 50, 100, 100) Bar.BarFillPercent = 50 Bar.Color = System.Drawing.Color.FromArgb(255, 255, 0) Bar.Orientation = Monkeybone.Instructions.Bar.BarOrientation.Vertical Sw.WriteLine(Bar) End Using
If you want your image to display on a form, you can use the Monkeybox control. The Monkeybox control displays your image directly on screen, with an option to save it as a .mob file that can be opened in Monkeybone Viewer. The following code is written in the Shown event of a form that has a Monkeybox control on it, called MBox1. Here, I do not actually save the image, just displays the source in a messagebox. The messagebox will contain exactly the same two instructions as the last example produces. Also, on the screen, you will see a green Monkeybone image with a yellow box in it.
Public Class Form1 Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown 'Size is normaly set in the designer, but here I set it manually. MBox1.Width = 200 MBox1.Height = 200 'Set the background color. MBox1.BackColor = System.Drawing.Color.FromArgb(51, 119, 51) 'Add a bar. MBox1.AddBar(Color.FromArgb(255, 255, 0), 50, 50, 100, 100, 50, _ Monkeybox.Bar.BarOrientation.Vertical) 'Redraw is not trigged by adding and instruction. MBox1.Invalidate() MessageBox.Show(MBox1.GetSource()) End Sub End Class
Categories: Microsoft .NET
Tags: Monkeybone
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
[…] Monkeybone: The Bar instruction – WinSoft.se […]
[…] Monkeybone: The Bar instruction – WinSoft.se […]