/*
* Seven Kingdoms: Ancient Adversaries
*
* Copyright 1997,1998 Enlight Software Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
//Filename : OBOX.CPP
//Description : A collection of box objects
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//----------- Define constant -------------//
enum { BOX_LINE_SPACE = 8,
MAX_BOX_WIDTH = 600,
BOX_X_MARGIN = 30, // Horizontal margin
BOX_TOP_MARGIN = 20,
BOX_BUTTON_MARGIN = 32,
BOX_BOTTOM_MARGIN = 42 }; // margin for display the box button
//------- constant for arrow box ----------//
enum { ARROW_HEIGHT = 20, // Height of the thick end of the arrow
ARROW_MARGIN = 10, // Y margin of the arrow between the box top
ARROW_X_DISTANCE = 40, // X distance of the object to the box
ARROW_Y_DISTANCE = 35 }; // Y distance of the object to the box
//----- Define static member variables ------//
char Box::opened_flag=0;
//----------- Begin of function Box::open ---------//
//
// Open the box with the given coordinations
//
// x1, y1, x2, y2 - coordination of the box
// (default : use current settings)
//
// [int] downCentre - whether paint down the center of the box
// (default : 1)
//
void Box::open(int inX1, int inY1, int inX2, int inY2, int downCentre)
{
box_x1 = inX1;
box_y1 = inY1;
box_x2 = inX2;
box_y2 = inY2;
paint( downCentre );
}
//------------ End of function Box::open -----------//
//----------- Begin of function Box::open ---------//
//
// Given the width & height of the box, and open the box
//
// boxWidth, boxHeight - width & height of the box
//
// [int] downCentre - whether paint down the center of the box
// (default : 1)
//
void Box::open(int boxWidth, int boxHeight, int downCentre)
{
box_x1 = (VGA_WIDTH-boxWidth) / 2;
box_x2 = box_x1 + boxWidth - 1;
box_y1 = (VGA_HEIGHT-boxHeight) / 2;
box_y2 = box_y1 + boxHeight - 1;
paint( downCentre );
}
//------------ End of function Box::open -----------//
//----------- Begin of function Box::paint ---------//
void Box::paint(int downCentre)
{
err_when(opened_flag); // double open
vga_front.save_area_common_buf( box_x1, box_y1, box_x2, box_y2 ); // save to Vga::image_buf
vga_front.d3_panel_up( box_x1, box_y1, box_x2, box_y2, 2 );
if( downCentre )
vga_front.d3_panel_down( box_x1+4, box_y1+4, box_x2-4, box_y2-4, 1 );
opened_flag = 1;
}
//------------ End of function Box::paint -----------//
//----------- Begin of function Box::close --------//
//
// Close the previously opened box
//
void Box::close()
{
err_when(!opened_flag); // double open
vga_front.rest_area_common_buf();
mouse.get_event(); // post the click, prevent effect on other windows
opened_flag = 0;
}
//------------ End of function Box::close -----------//
//----------- Begin of function Box::calc_size ------//
//
// Given a string and then calculate the size of the box
// which can contain the string.
//
// msgStr = the message string
// minHeight = minimum height of the box
// [int] x1, y1 = the top left corner of the box
//
void Box::calc_size(char* msgStr, int minHeight, int x1, int y1)
{
int width = BOX_X_MARGIN*2 + font_san.text_width(msgStr, -1, MAX_BOX_WIDTH-BOX_X_MARGIN*2);
int height = minHeight + font_san.text_height(BOX_LINE_SPACE);
if( x1 < 0 )
{
box_x1 = (VGA_WIDTH - width) / 2;
box_y1 = (VGA_HEIGHT - height) / 2;
}
else
{
box_x1 = x1;
box_y1 = y1;
}
box_x2 = box_x1+width-1;
box_y2 = box_y1+height-1;
}
//---------- End of function Box::calc_size -------------//
//---------- Begin of function Box::ok_button ---------//
//
// [int] timeOut - 1=enable inactive timeout
// 0=disable inactive timeout
// (default : 1 )
//
void Box::ok_button(int timeOut)
{
Button button;
button.paint_text( box_x1+(box_x2-box_x1+1)/2-10, box_y2-BOX_BUTTON_MARGIN, "Ok" );
if( sys.debug_session )
sys.blt_virtual_buf();
button.wait_press(timeOut);
}
//------------ End of function Box::ok_button ---------//
//---------- Begin of function Box::ask_button ---------//
//
// Display two buttons, and wait for player to click one of them
//
// [char*] buttonDes1 = the description of button 1 (default : "Ok")
// [char*] buttonDes2 = the description of button 2 (default : "Cancel")
// [int] rightClickClose = whether pressing the right button will close the window
// (default: 1)
//
int Box::ask_button(char* buttonDes1, char* buttonDes2, int rightClickClose)
{
int width;
width = box_x2-box_x1+1;
Button buttonOk, buttonCancel;
int buttonWidth1 = 20 + font_san.text_width(buttonDes1 ? buttonDes1 : (char*)"Ok");
buttonOk.create_text( box_x1+width/2-buttonWidth1, box_y2-BOX_BUTTON_MARGIN,
(buttonDes1 ? buttonDes1 : (char*)"Ok") );
buttonCancel.create_text( box_x1+width/2+2 , box_y2-BOX_BUTTON_MARGIN,
(buttonDes2 ? buttonDes2 : (char*)"Cancel") );
buttonOk.paint(); // paint button
buttonCancel.paint();
if( sys.debug_session )
sys.blt_virtual_buf();
//..........................................//
while( 1 )
{
sys.yield();
mouse.get_event();
if( sys.debug_session )
sys.blt_virtual_buf();
if( buttonOk.detect(buttonOk.str_buf[0], KEY_RETURN) )
return 1;
if( buttonCancel.detect(buttonCancel.str_buf[0], KEY_ESC)
|| (rightClickClose && mouse.any_click(1)) ) // detect right button only when the button is "Cancel"
{
mouse.get_event();
return 0;
}
}
}
//--------- End of function Box::ask_button --------//
//---------- Begin of function Box::ask_button ---------//
//
// Display a Ok and Cancel button, and wait for player to click one of them
//
//