<?php

/*******************************************************************************

 WINBINDER - The native Windows binding for PHP for PHP

 Copyright © Hypervisual - see LICENSE.TXT for details
 Author: Rubem Pechansky (http://winbinder.org/contact.php)

 Various methods of displaying bitmaps and icons

*******************************************************************************/

//------------------------------------------------------------ SYSTEM PARAMETERS

define("PATH_SCRIPT",	dirname(__FILE__) . "/");
define("PATH_DATA",		PATH_SCRIPT);
define("PATH_INC",		PATH_SCRIPT . "../include/");
define("PATH_RES",		PATH_SCRIPT . "../resources/");

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------------- CONSTANTS

define("ID", 0);
define("APPNAME", "Images");

//-------------------------------------------------------------- EXECUTABLE CODE

// NOTE: This kind of application does not need a window handler function
// NOTE: All frame dimensions must be equal or greater than the image dimensions.

// Create window

$mainwin = wb_create_window(NULL, PopupWindow, APPNAME, WBC_CENTER, WBC_CENTER, 530, 320, 0, 0);

// Create an opaque bitmapped frame

$frame = wb_create_control($mainwin, Frame, "", 4, 20, 512, 15, ID, WBC_IMAGE);
wb_set_image($frame, PATH_RES . 'toolbar.bmp', NOCOLOR);

// Create a transparent bitmapped frame

$frame = wb_create_control($mainwin, Frame, "", 4, 40, 512, 15, ID, WBC_IMAGE);
wb_set_image($frame, PATH_RES . 'toolbar.bmp', GREEN);

// Create a frame with a transparent 32 x 32 icon

$frame = wb_create_control($mainwin, Frame, "", 4, 70, 32, 32, ID, WBC_IMAGE);
wb_set_image($frame, PATH_RES . 'viewer.ico');

$frame = wb_create_control($mainwin, Frame, "", 45, 70, 32, 32, ID, WBC_IMAGE);
wb_set_image($frame, PATH_RES . 'viewer.ico', 0, 0, 1);

// Create a transparent bitmap on the fly (adapted from ooi_winmine.phpw by Alexandre)

$tobuild[] = "               .";
$tobuild[] = " KKKKKKKKKKKKK K";
$tobuild[] = " K............ K";
$tobuild[] = " K...-IIII-... K";
$tobuild[] = " K..-ILLLLI-.. K";
$tobuild[] = " K.-IL--ILLI-. K";
$tobuild[] = " K.IL-  -ILHI. K";
$tobuild[] = " K.IL-  -ILHI. K";
$tobuild[] = " K.ILI--ILLHI. K";
$tobuild[] = " K.ILLIILLHHI. K";
$tobuild[] = " K.-ILLLLHHI-. K";
$tobuild[] = " K..-IHHHHI-.. K";
$tobuild[] = " K...-IIII-... K";
$tobuild[] = " K............ K";
$tobuild[] = "               K";
$tobuild[] = ".KKKKKKKKKKKKKKK";

$im = wb_create_image(16, 16);

for($y = 0; $y < sizeof($tobuild); $y++)
	for($x = 0; $x < strlen($tobuild[$y]); $x++)
		wb_draw_point($im, $x, $y, colorTableConvert($tobuild[$y][$x]));

function colorTableConvert($index)
{
	$ctable = Array(
		' ' => WHITE,
		'.' => GREEN,
		'-' => 0x8080FF,
		'I' => 0x6060FF,
		'L' => RED,
		'H' => 0x0000C0,
		'K' => DARKGRAY,
		'W' => BLACK,
	);
	return $ctable[$index];
}

$frame = wb_create_control($mainwin, Frame, "", 90, 80, 16, 16, ID, WBC_IMAGE);
wb_set_image($frame, $im, GREEN);

// Set the main window icon

wb_set_image($mainwin, PATH_RES . 'hyper.ico');

// Use an image to paint the main window

$img = wb_load_image(PATH_RES . 'treeview.bmp');
wb_draw_image($mainwin, $img, 10, 120);
wb_draw_image($mainwin, $img, 10, 140, 96, 15, NOCOLOR, 32, 0);
wb_draw_image($mainwin, $img, 10, 160, 96, 15, NOCOLOR, 48, 0);
wb_draw_image($mainwin, $img, 10, 180, 96, 15, NOCOLOR, 64, 0);
wb_destroy_image($img);

wb_main_loop();

//-------------------------------------------------------------------------- END

?>