#ifndef CODE_GFXARROW_CXX
#define CODE_GFXARROW_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: gfx_arrow.cxx,v 1.1.1.1 1998/07/16 19:29:31 cvs Exp $)
 * 
 * Copyright (C) 1998 Jürgen Schmitz
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 *-----------------------------------------------------------------------
 */

#include "types.h"
#include <Xclasses/gfx_arrow.h>
#include <Xclasses/gadget.h>
#include <Xclasses/Xcolors.h>
#include "include/gfx_arrow_p.h"

gfx_arrow::gfx_arrow() : gfx_object()
{
	while (!(p=new pgfx_arrow))
	{
		outOfMemory("gfx_arrow");
	}
	p->o=this;
	Name("gfx_arrow");
}
gfx_arrow::gfx_arrow(int d) : gfx_object()
{
	while (!(p=new pgfx_arrow))
	{
		outOfMemory("gfx_arrow");
	}
	p->o=this;
	p->dir=d;
	Name("gfx_arrow");
}
gfx_arrow::~gfx_arrow()
{
	if (p) delete p;
}

pgfx_arrow::pgfx_arrow(void)
{
	dir=ARROW_UP;
}
pgfx_arrow::~pgfx_arrow()
{
}
void pgfx_arrow::draw(class gadget *g,int x,int y,int w,int h)
{
#define PTSC	5
	XPoint pts[PTSC];
	int h2,w2;
	w2=w/2; w=w2*2;
	h2=h/2; h=h2*2;

	switch (dir)
	{
		case ARROW_UP:
			pts[0].x=x; 	pts[0].y=y+h;
			pts[1].x=x+w2; 	pts[1].y=y;
			pts[2].x=x+w;	pts[2].y=y+h;
			pts[3].x=x+w2;	pts[3].y=y+h2;
			pts[4].x=x+1; 	pts[4].y=y+h;
			break;
		case ARROW_DOWN:
			pts[0].x=x; 	pts[0].y=y;
			pts[1].x=x+w2; 	pts[1].y=y+h;
			pts[2].x=x+w;	pts[2].y=y;
			pts[3].x=x+w2;	pts[3].y=y+h2;
			pts[4].x=x; 	pts[4].y=y;
			break;
		case ARROW_LEFT:
			pts[0].x=x+w; 	pts[0].y=y;
			pts[1].x=x; 	pts[1].y=y+h2;
			pts[2].x=x+w;	pts[2].y=y+h;
			pts[3].x=x+w2;	pts[3].y=y+h2;
			pts[4].x=x+w; 	pts[4].y=y;
			break;
		case ARROW_RIGHT:
			pts[0].x=x; 	pts[0].y=y;
			pts[1].x=x+w; 	pts[1].y=y+h2;
			pts[2].x=x;		pts[2].y=y+h;
			pts[3].x=x+w2;	pts[3].y=y+h2;
			pts[4].x=x; 	pts[4].y=y;
			break;
	}

	XSetLineAttributes(g->display(),g->gg_gc(),0,LineSolid,CapNotLast,JoinMiter);
//  shape: Complex, Convex, or Nonconvex
	XFillPolygon(g->display(),g->gg_win(),g->gg_gc(),pts,PTSC,Nonconvex,CoordModeOrigin);
//	XSetForeground(g->display(),g->gg_gc(),g->col_shadow2());
//	XDrawLines(g->display(),g->gg_win(),g->gg_gc(),pts,PTSC,CoordModeOrigin);
	XSetLineAttributes(g->display(),g->gg_gc(),0,LineSolid,CapButt,JoinRound);
}
void gfx_arrow::Adjust(int a)
{
//	p->adjust=a;
}
void gfx_arrow::draw_normal(class gadget *g,int x,int y,int w,int h)
{
	XSetForeground(display(),g->gg_gc(),col_text());
	p->draw(g,x,y,w-1,h-1);
}
void gfx_arrow::draw_selected(class gadget *g,int x,int y,int w,int h)
{
	XSetForeground(display(),g->gg_gc(),col_selectedtext());
	p->draw(g,x+1,y+1,w-1,h-1);
}
void gfx_arrow::draw_locked(class gadget *g,int x,int y,int w,int h)
{
	XSetForeground(display(),g->gg_gc(),col_shine2());
	p->draw(g,x+1,y+1,w-1,h-1);
	XSetForeground(display(),g->gg_gc(),col_shadow2());
	p->draw(g,x,y,w-1,h-1);
}
void gfx_arrow::draw_selectedlocked(class gadget *g,int x,int y,int w,int h)
{
	draw_locked(g,x,y,w,h);
}

int gfx_arrow::height(class gadget *g)
{
	return NOLIMIT;
}
int gfx_arrow::width(class gadget *g)
{
	return NOLIMIT;
}
void gfx_arrow::Direction(int d)
{
	p->dir=d;
}

#endif
