#include <pjsr/Sizer.jsh>
function MyTabPageControl( parent )
{
this.__base__ = ScrollBox;
if ( parent )
this.__base__( parent );
else
this.__base__();
this.bmp = TranslucentPlanets( planetsData );
this.autoScroll = true;
this.tracking = true;
this.initScrollBars = function()
{
this.pageWidth = this.bmp.width;
this.pageHeight = this.bmp.height;
this.setHorizontalScrollRange( 0, Math.max( 0, this.bmp.width - this.viewport.width ) );
this.setVerticalScrollRange( 0, Math.max( 0, this.bmp.height - this.viewport.height ) );
this.viewport.update();
};
this.viewport.onResize = function()
{
this.parent.initScrollBars();
};
this.onHorizontalScrollPosUpdated = function( x )
{
this.viewport.update();
};
this.onVerticalScrollPosUpdated = function( y )
{
this.viewport.update();
};
this.viewport.onPaint = function( x0, y0, x1, y1 )
{
var g = new Graphics( this );
g.fillRect( x0, y0, x1, y1, new Brush( 0xff000000 ) );
g.drawBitmap( this.parent.scrollPosition.symmetric(), this.parent.bmp );
g.end();
};
this.initScrollBars();
}
MyTabPageControl.prototype = new ScrollBox;
function MyTabbedDialog()
{
this.__base__ = Dialog;
this.__base__();
this.pages = new Array;
this.pages.push( new MyTabPageControl( this ) );
this.pages.push( new MyTabPageControl( this ) );
this.pages.push( new MyTabPageControl( this ) );
this.pages.push( new MyTabPageControl( this ) );
this.tabs = new TabBox( this );
this.tabs.setMinSize( 400, 400 );
this.tabs.addPage( this.pages[0], "First" );
this.tabs.addPage( this.pages[1], "Second" );
this.tabs.addPage( this.pages[2], "Third" );
this.tabs.addPage( this.pages[3], "Fourth" );
this.okButton = new PushButton( this );
this.okButton.text = "OK";
this.okButton.onClick = function()
{
this.dialog.ok();
}
// Group the three buttons into a horizontal row
this.buttons = new HorizontalSizer;
this.buttons.addStretch();
this.buttons.add( this.okButton );
// Setup the dialog layout.
this.sizer = new VerticalSizer;
this.sizer.margin = 6;
this.sizer.spacing = 6;
this.sizer.add( this.tabs );
this.sizer.add( this.buttons );
// Set the dialog title and geometry
this.windowTitle = "ScrollBox Test Script";
this.adjustToContents();
//this.setFixedSize(); // don't allow the user to resize this dialog
}
MyTabbedDialog.prototype = new Dialog;
/**
* The TranslucentPlanetsData object defines functional parameters for the
* TranslucentPlanets routine.
*/
function TranslucentPlanetsData()
{
this.size = 800; // Size in pixels of the generated image
this.maxRadius = 60; // Maximum planet radius
this.numberOfPlanets = 120; // Number of translucent planets
this.networkFrequency = 25; // Frequency of network lines
this.skyTopColor = 0xff000000; // Top background color (solid black by default)
this.skyBottomColor = 0xff000050; // Bottom background color (dark blue by default)
this.networkColor = 0xffff8000; // Network color (solid orange by default)
this.networkBkgColor = 0xff000000; // Network background color (solid black by default)
this.planetTransparency = 0x80; // Alpha value of all random planet colors
}
// Global TranslucentPlanets parameters.
var planetsData = new TranslucentPlanetsData;
/**
* Renders a TranslucentPlanets scene as a newly created bitmap.
*/
function TranslucentPlanets( data )
{
function ARGBColor( r, g, b )
{
return (data.planetTransparency << 24) | (r << 16) | (g << 8) | b;
}
// Working bitmap
var bmp = new Bitmap( data.size, data.size );
// Create a graphics context to draw on our working bitmap
var g = new Graphics( bmp );
// We want high-quality antialiased graphics
g.antialiasing = true;
// Fill the background with a linear gradient
var lg = new LinearGradientBrush( new Point( 0 ), new Point( bmp.height ),
[[0, data.skyTopColor], [1, data.skyBottomColor]] );
g.fillRect( bmp.bounds, lg );
// Draw random circles
for ( var i = 0; i < data.numberOfPlanets; ++i )
{
// Random colors in the range [0,255]
var red = Math.round( 255*Math.random() );
var green = Math.round( 255*Math.random() );
var blue = Math.round( 255*Math.random() );
// Avoid too dark circles
if ( red < 24 && green < 24 && blue < 24 )
{
--i;
continue;
}
// 32-bit AARRGGBB color values
var color1 = ARGBColor( red, green, blue );
var color2 = ARGBColor( red >> 1, green >> 1, blue >> 1 );
// Random center and radius
var center = new Point( data.size*Math.random(), data.size*Math.random() );
var radius = data.maxRadius*Math.random();
// Define working objects
g.pen = new Pen( color2 );
g.brush = new RadialGradientBrush( center, radius, center, [[0, color1], [1, color2]] );
// Draw this planet
g.drawCircle( center, radius );
}
// Erase the network region by drawing a dense network
g.antialiasing = false;
g.pen = new Pen( data.networkBkgColor );
for ( var i = 0; i < data.size; ++i )
g.drawLine( i-1, data.size, -1, i+1 );
// Generate the network
g.antialiasing = true;
g.pen = new Pen( data.networkColor );
for ( var i = 0; i < data.size; i += data.networkFrequency )
g.drawLine( i, data.size-1, 0, i );
g.drawLine( data.size-1, data.size-1, 0, data.size-1 );
// End painting
g.end();
return bmp;
}
var dlg = new MyTabbedDialog;
dlg.execute();