File: gui.c | Size: 5,811 bytes | Download file | Back to directory listing | BWPOW's homepage
#include <string.h>
#include <stdio.h>
#include <allegro.h>
#include <jpeg.h>
 
#include "main.h"
#include "headers.h"
 
#include "fonty.h"
#include "bgfx.h"
 
extern MINFO minfo;
 
TLACIDLO tlacidlo[10];
int num_tl=0;
 
void std_box(BITMAP *bmp,short x,short y,short w,short h,char mode)
{
  int c1,c2,c3,c4;
 
  if(mode>=5){
    rectfill(bmp,x,y,x+w,y+h,makecol(128,128,128));
    mode-=5;
  }
 
  rect(bmp,x-1,y-1,x+w+1,y+h+1,0);
  if(mode==1){
    c1=makecol(200,200,200);
    c2=makecol(56,56,56);
 
    c3=makecol(164,164,164);
    c4=makecol(96,96,96);
  }
  else{
    c2=makecol(200,200,200);
    c1=makecol(56,56,56);
 
    c4=makecol(164,164,164);
    c3=makecol(96,96,96);
  }
 
  hline(bmp,x,y,x+w,c1);
  hline(bmp,x+1,y+1,x+w-1,c3);
  vline(bmp,x,y,y+h,c1);
  vline(bmp,x+1,y+1,y+h-1,c3);
 
  hline(bmp,x,y+h,x+w,c2);
  hline(bmp,x+1,y+h-1,x+w-1,c4);
  vline(bmp,x+w,y,y+h,c2);
  vline(bmp,x+w-1,y+1,y+h-1,c4);
}
 
 
void add_tlac(int x,int y,int w,int h,int a)
{
	if(num_tl>=10) return;
	tlacidlo[num_tl].x=x;
	tlacidlo[num_tl].y=y;
	tlacidlo[num_tl].w=w;
	tlacidlo[num_tl].h=h;
	tlacidlo[num_tl].a=a;
 
	num_tl++;
}
 
int check_tlac(int x,int y)
{
	char i;
 
	for(i=0;i<num_tl;i++){
		if(tlacidlo[i].x<=x&&tlacidlo[i].y<=y&&
			tlacidlo[i].x+tlacidlo[i].w>=x&&
			tlacidlo[i].y+tlacidlo[i].h>=y)
			return i;
	}
 
	return -1;
}
 
void nakresli_tlac(int i)
{
	if(i>=num_tl) return;
	if(i<0) return;
 
	draw_sprite(actual,bgfx[tlac1+tlacidlo[i].a].dat,tlacidlo[i].x,tlacidlo[i].y);
}
 
void bigbox(BITMAP *bmp,int x,int y,int w,int h,char tlac[7])
{
	BITMAP *temp;
	char i,l;
	int xx;
 
	num_tl=0;
 
	temp=create_bitmap(w-10,h-10);
	clear_to_color(temp,makecol(0,128,160));
 
	set_trans_blender(0,0,0,220);
	draw_trans_sprite(bmp,temp,x+5,y+5);
	destroy_bitmap(temp);
 
	draw_rle_sprite(bmp,bgfx[lu].dat,x-16,y-16);
	draw_rle_sprite(bmp,bgfx[ru].dat,x+w-32,y-16);
	draw_rle_sprite(bmp,bgfx[lb].dat,x-16,y+h-32);
	draw_rle_sprite(bmp,bgfx[rb].dat,x+w-32,y+h-32);
 
	stretch_sprite(bmp,bgfx[up].dat,x+32,y-16,w-64,24);
	stretch_sprite(bmp,bgfx[bottom].dat,x+32,y+h-8,w-64,24);
 
	stretch_sprite(bmp,bgfx[left].dat,x-16,y+32,24,h-64);
	stretch_sprite(bmp,bgfx[right].dat,x+w-8,y+32,24,h-64);
 
	num_tl=0;
	l=strlen(tlac);
	xx=w-15-l*40;
	set_trans_blender(0,0,0,64);
	for(i=0;i<l;i++){
		draw_trans_sprite(bmp,bgfx[tlac1+tlac[i]-'0'].dat,x+xx,y+h-50);
		add_tlac(x+xx,y+h-50,32,32,tlac[i]-'0');
		xx+=40;
	}
 
}
 
void smallbox(BITMAP *bmp,int x,int y,int w,int h)
{
 
	draw_rle_sprite(bmp,bgfx[slu].dat,x-4,y-4);
	draw_rle_sprite(bmp,bgfx[sru].dat,x+w-8,y-4);
	draw_rle_sprite(bmp,bgfx[slb].dat,x-4,y+h-8);
	draw_rle_sprite(bmp,bgfx[srb].dat,x+w-8,y+h-8);
 
	stretch_sprite(bmp,bgfx[sup].dat,x+8,y-4,w-16,6);
	stretch_sprite(bmp,bgfx[sbottom].dat,x+8,y+h-2,w-16,6);
 
	stretch_sprite(bmp,bgfx[sleft].dat,x-4,y+8,6,h-16);
	stretch_sprite(bmp,bgfx[sright].dat,x+w-2,y+8,6,h-16);
 
}
 
void smallbox_trans(BITMAP *bmp,int x,int y,int w,int h)
{
/*
	BITMAP *temp;
 
	temp=create_bitmap(w,h);
	clear_to_color(temp,makecol(0,128,160));
 
	set_trans_blender(0,0,0,220);
	draw_trans_sprite(bmp,temp,x,y);
	destroy_bitmap(temp);
*/
 
	rectfill(bmp,x+1,y+1,x+w-1,y+h-1,makecol(64,64,128));
	draw_rle_sprite(bmp,bgfx[slu].dat,x-4,y-4);
	draw_rle_sprite(bmp,bgfx[sru].dat,x+w-8,y-4);
	draw_rle_sprite(bmp,bgfx[slb].dat,x-4,y+h-8);
	draw_rle_sprite(bmp,bgfx[srb].dat,x+w-8,y+h-8);
 
	stretch_sprite(bmp,bgfx[sup].dat,x+8,y-4,w-16,6);
	stretch_sprite(bmp,bgfx[sbottom].dat,x+8,y+h-2,w-16,6);
 
	stretch_sprite(bmp,bgfx[sleft].dat,x-4,y+8,6,h-16);
	stretch_sprite(bmp,bgfx[sright].dat,x+w-2,y+8,6,h-16);
 
}
 
void smallbox_rtrans(BITMAP *bmp,int x,int y,int w,int h,char tlac[7])
{
	BITMAP *temp;
	char i,l;
	int xx;
 
	temp=create_bitmap(w,h);
	clear_to_color(temp,makecol(0,128,160));
 
	set_trans_blender(0,0,0,220);
	draw_trans_sprite(bmp,temp,x,y);
	destroy_bitmap(temp);
 
	draw_rle_sprite(bmp,bgfx[slu].dat,x-4,y-4);
	draw_rle_sprite(bmp,bgfx[sru].dat,x+w-8,y-4);
	draw_rle_sprite(bmp,bgfx[slb].dat,x-4,y+h-8);
	draw_rle_sprite(bmp,bgfx[srb].dat,x+w-8,y+h-8);
 
	stretch_sprite(bmp,bgfx[sup].dat,x+8,y-4,w-16,6);
	stretch_sprite(bmp,bgfx[sbottom].dat,x+8,y+h-2,w-16,6);
 
	stretch_sprite(bmp,bgfx[sleft].dat,x-4,y+8,6,h-16);
	stretch_sprite(bmp,bgfx[sright].dat,x+w-2,y+8,6,h-16);
 
	num_tl=0;
	l=strlen(tlac);
	xx=w-8-l*40;
	set_trans_blender(0,0,0,64);
	for(i=0;i<l;i++){
		draw_trans_sprite(bmp,bgfx[tlac1+tlac[i]-'0'].dat,x+xx,y+h-40);
		add_tlac(x+xx,y+h-40,32,32,tlac[i]-'0');
		xx+=40;
	}
 
}
 
void whitebox(BITMAP *bmp,int x,int y,int w,int h)
{
	int c=minfo.whitebox;
 
	arc(bmp,x+10,y+10,itofix(64),itofix(128),10,c);
	arc(bmp,x+w-10,y+10,itofix(0),itofix(64),10,c);
	arc(bmp,x+w-10,y+h-10,itofix(192),itofix(0),10,c);
	arc(bmp,x+10,y+h-10,itofix(128),itofix(192),10,c);
 
 
	hline(bmp,x+10,y,x+w-10,c);
	hline(bmp,x+10,y+h,x+w-10,c);
 
	vline(bmp,x,y+10,y+h-10,c);
	vline(bmp,x+w,y+10,y+h-10,c);
 
}
 
#define ALERT_FONT1 TIMES2_PCX
#define ALERT_FONT2 TIMES4_PCX
 
void myalert(char *text1,char *text2)
{
	short w1,w2;
	char c=1,stl=-1;
	short mx,my,omx=-1,omy;
 
	mainmenu_vytvor_pozadie();
 
	w1=text_length(fonty[ALERT_FONT1].dat,text1);
	w2=text_length(fonty[ALERT_FONT2].dat,text2);
 
	if(w2>w1) w1=w2;
 
	w1+=50;
	smallbox_rtrans(mm_bmp,320-w1/2,180,w1,120,"2");
 
	stextout_centre(mm_bmp,fonty[ALERT_FONT1].dat,text1,320,195,minfo.white,0);
	stextout_centre(mm_bmp,fonty[ALERT_FONT2].dat,text2,320,230,minfo.white,0);
 
	while(1){
		if(c){
			blit(mm_bmp,actual,0,0,0,0,640,480);
			if(stl==0) nakresli_tlac(0);
			c=0;
		}
		show_mouse(actual);
		blit(actual,screen,0,0,0,0,640,480);
		show_mouse(0);
 
		mx=mouse_x;my=mouse_y;
 
		if(mx!=omx||my!=omy){
			c=check_tlac(mx,my);
			if(c!=stl){
				stl=c;
				c=1;
			}
			else c=0;
			omx=mx;omy=my;
		}
 
		if((mouse_b&1)&&stl==0) break;
 
		if(key[KEY_ESC]) break;
		if(key[KEY_ENTER]) break;
	}
 
 
}