#include
#include
/*********************************************************************
* Parameters
*/
float minwidth = 50;
float minheight = 25;
boolean footer = false;
boolean selected = false;
displayitem leftfoot = "";
displayitem rightfoot = "";
persist(resizable);
persist(footer);
persist(leftfoot);
persist(rightfoot);
float borderN = 26;
float borderW = 5;
float borderE = 5;
float borderS()
{
return footer ? 26 : 5;
}
/*********************************************************************
* Painting
*/
#define GAP 20
#define MAR 10
#define MAR2 (MAR*2)
void PaintActive()
{
setcolor(BG);
if (resizable)
rectpath(13,h - 5,w - 26,2);
else
rectpath(borderW,h - 5,w - (borderW + borderE),2);
rectpath(borderW,h - borderN,w - (borderW + borderE),3);
fill();
if ((!@freezer) && (currentinputfocus == cv)) {
if (resizable)
OLHLine(false,13,h - 4,w - 26);
else
OLHLine(false,borderW,h - 4,w - (borderW + borderE));
OLHLine(false,borderW,(h - borderN) + 2,w - (borderW + borderE));
}
}
void PaintBorder()
{
setcolor(BG);
rectframe(5,0,0,w,h);
eofill();
setcolor(FG);
rectframe(selected ? 3 : (resizable ? 2 : 1),0,0,w,h);
eofill();
if (dragable && resizable) {
OLReshapeSW(false,0,0);
OLReshapeNW(false,0,h);
OLReshapeNE(false,w,h);
OLReshapeSE(false,w,0);
}
}
void PaintClose(boolean down)
{
gsave();
setcolor(BG);
rectpath(5,h-23,35,18);
fill();
translate(14,h-21);
OLMenuBut(true,down);
grestore();
}
void PaintLabel()
{
float W;
if (w > 45) {
setcolor(BG);
rectpath(40,h - 23,w-45,18);
fill();
}
if (w > 60) {
setfont(headerfont);
setcolor(FG);
W = DIWidth(framelabel);
if (W < (w - 80))
DIPaintCentered(framelabel,40,h-22,w-80,16);
else
OLShow(framelabel,40,h-22,w-50,16);
if (@freezer) {
setcolor(BG);
rectpath(40,h-22,w-80,16);
OLStipple();
}
}
}
void PaintFooter()
{
float W1, W2;
if (footer) {
setcolor(BG);
rectpath(5,5,w-10,borderS-5);
fill();
if ((w > (MAR2 + GAP + 10)) && (leftfoot != null) && (rightfoot != null)) {
setfont(footerfont);
setcolor(FG);
W1 = DIWidth(leftfoot);
W2 = DIWidth(rightfoot);
if ((W1 + W2 + GAP) < (w - MAR2)) {
DIPaintLeft(leftfoot,MAR,6,w-MAR2,19);
DIPaintRight(rightfoot,MAR,6,w-MAR2,19);
} else if (W1 > ((w * 0.75) - (MAR + GAP/2))) {
OLShow(leftfoot,MAR,6,(w * 0.75) - (MAR + GAP/2),19);
W2 = min(W2,(w/4) - (MAR + GAP/2));
OLShow(rightfoot,w - (W2 + MAR),6,W2,19);
} else {
DIPaintLeft(leftfoot,MAR,6,w-(MAR + GAP/2),19);
OLShow(rightfoot,W1 + MAR + GAP,6,w - (W1 + MAR2 + GAP) ,19);
}
}
}
}
void Paint()
{
setcolor(BG);
clippath();
fill();
PaintBorder();
PaintClose(false);
PaintActive();
PaintLabel();
PaintFooter();
}
/*********************************************************************
* focus
*/
void focus_change()
{
gexec(/PaintActive);
}
void frost_change()
{
gexec(/PaintLabel);
}
/*********************************************************************
* tracking
*/
#define DIST 8
boolean trackinpath = false;
void track_close()
{
boolean b = pointinpath(trackx, tracky);
if (b != trackinpath)
PaintClose(trackinpath = b);
}
void OnSelect()
{
float X = mouseevent.XLocation, Y = mouseevent.YLocation;
rectpath(14,h-21,OLButW,OLButH);
if (pointinpath(X,Y)) {
track(/track_close);
if (trackinpath) {
PaintClose(false);
close();
}
unpromote(/trackinpath);
} else if (dragable && resizable) {
if ((X < DIST) && (Y < DIST)) {
OLReshapeSW(true,0,0);
resizeSW();
OLReshapeSW(false,0,0);
} else if ((X < DIST) && (Y > (h-DIST))) {
OLReshapeNW(true,0,h);
resizeNW();
OLReshapeNW(false,0,h);
} else if ((X > (w-DIST)) && (Y > (h-DIST))) {
OLReshapeNE(true,w,h);
resizeNE();
OLReshapeNE(false,w,h);
} else if ((X > (w-DIST)) && (Y < DIST)) {
OLReshapeSE(true,w,0);
resizeSE();
OLReshapeSE(false,w,0);
} else
super.OnSelect();
} else
super.OnSelect();
}
void OnMenu()
{
float X = mouseevent.XLocation, Y = mouseevent.YLocation;
rectpath(14,h-21,OLButW,OLButH);
if (pointinpath(X,Y)) {
PaintClose(true);
super.OnMenu();
PaintClose(false);
} else
super.OnMenu();
}
void setfooters(displayitem left, displayitem right)
{
if ((leftfoot != left) || (rightfoot != right)) {
leftfoot = left;
rightfoot = right;
gexec(/PaintFooter);
}
}
void setleftfooter(displayitem left)
{
setfooters(left,rightfoot);
}
void setrightfooter(displayitem right)
{
setfooters(leftfoot,right);
}