<?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)

 Borderless window demonstration

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

//------------------------------------------------------------ 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("APPNAME", "WinBinder Borderless Window");	// The window title will be seen in the taskbar and on Alt+tab

define("WIDTH", 	576);
define("HEIGHT",	400);

define("ID_ONTOP",	101);

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

// Only one instance of application allowed

if(wb_get_instance(APPNAME, TRUE))
	die;

// Create main window

$font_title = wb_create_font("Verdana", 20, 0x80FFFF, FTA_BOLD);
$font_text = wb_create_font("Tahoma", 10, WHITE, FTA_BOLD);

$mainwin = wb_create_window(NULL, NakedWindow, APPNAME, WBC_CENTER, WBC_CENTER, WIDTH, HEIGHT,
  WBC_INVISIBLE | WBC_NOTIFY | WBC_CUSTOMDRAW, WBC_REDRAW);
wb_set_area($mainwin, WBC_TITLE, 0, 0, WIDTH, 86);

// Set some cursors

$cursor = wb_load_image(PATH_RES . 'finger.cur');
wb_set_cursor(ImageButton, $cursor);
wb_set_cursor($mainwin, 'cross');

// Create some ImageButtons

$states = wb_load_image(PATH_RES . 'states.bmp');

$btn = wb_create_control($mainwin, ImageButton, "Toggle Always on Top",	10, 346, 32, 32, ID_ONTOP, 0);
wb_set_image($btn, $states, GREEN);
wb_set_cursor($btn, 'uparrow');

$btn = wb_create_control($mainwin, ImageButton, "Button 2", 			42, 346, 32, 32, 0, 0);
wb_set_image($btn, $states);

$btn = wb_create_control($mainwin, ImageButton, "Button 3",				74, 346, 32, 32, 0, 0);
wb_set_image($btn, $states);

$btn = wb_create_control($mainwin, ImageButton, "Button 4",				106, 346, 32, 32, 0, WBC_DISABLED);
wb_set_image($btn, $states);

$btn = wb_create_control($mainwin, ImageButton, "Close this window",	WIDTH -  40, 346, 32, 32, IDCLOSE, 0);
wb_set_image($btn, $states);
wb_destroy_image($btn);

// Last touches

wb_set_handler($mainwin, "process_main");
wb_set_image($mainwin, PATH_RES . 'hyper.ico');		// Icon will be seen in the taskbar and on Alt+tab
wb_set_visible($mainwin, TRUE);

wb_main_loop();

//-------------------------------------------------------------------- FUNCTIONS

/* Process main window commands */

function process_main($window, $id, $ctrl, $lparam1=0, $lparam2=0)
{
    switch($id) {

		case IDDEFAULT:

			if($lparam1 & WBC_REDRAW) {
				$dim = wb_get_size($window, true);
				$winwidth = $dim[0];
				$winheight = $dim[1];
				draw_on_window($lparam2, $winwidth, $winheight);
			}
			break;

        case IDCLOSE:
            wb_destroy_window($window);
            wb_destroy_font();				// Destroy all fonts
            break;

		case ID_ONTOP:
			static $ontop = false;
			$ontop = !$ontop;
			wb_set_style($window, WBC_TOP, $ontop);
    }
}

/* Draw main window image */

function draw_on_window($buffer, $width, $height)
{
	global $font_title, $font_text;

	// Create a bitmap and draw on it

	wb_draw_rect($buffer, 0, 0, $width, $height, BLACK);
	wb_draw_rect($buffer, 0, 0, $width, 70, 0x8D5A2D);
	wb_draw_rect($buffer, 0, 326, $width, 70, 0x8D5A2D);

	// Create a repeating pattern

	$pattern = wb_create_image(16, 16);
	wb_draw_rect($pattern, 0, 0, 16, 16, 0x704010);
	wb_draw_rect($pattern, 3, 3, 10, 10, 0xB08050);
	wb_draw_rect($pattern, 6, 6, 4, 4, 0x704010);
	for($i = 0; $i < $width; $i += 16) {
		wb_draw_image($buffer, $pattern, $i, 0);
		wb_draw_image($buffer, $pattern, $i, 70);
		wb_draw_image($buffer, $pattern, $i, 326);
		wb_draw_image($buffer, $pattern, $i, $height - 16);
	}
	wb_destroy_image($pattern);

	// Draw some text

	wb_draw_text($buffer, APPNAME, 0, 22, $width, 40, $font_title, WBC_CENTER);
	for($x = 10, $y = 95; $y < 310; $x += 5, $y += 20)
		wb_draw_text($buffer, "To put this application on top on other windows, click the first button below.",
		  $x, $y, 0, 0, $font_text);
}

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

?>