#ifndef CODE_GFXKNOB_CXX
#define CODE_GFXKNOB_CXX

/*-----------------------------------------------------------------------
 * Xclasses code file
 * ($Id: gfx_knob.cxx,v 1.2 1998/10/06 00:01:19 schmitzj 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_knob.h>
#include <Xclasses/gadget.h>
#include <Xclasses/Xcolors.h>
#include "include/gfx_knob_p.h"
#include "../include/defaults.h"

gfx_knob::gfx_knob() : gfx_object()
{
	while (!(p=new pgfx_knob))
	{
		outOfMemory("gfx_knob");
	}
	p->o=this;
	Name("gfx_knob");
}
gfx_knob::~gfx_knob()
{
	if (p) delete p;
}

pgfx_knob::pgfx_knob(void)
{
	adjust=ADJUST_LEFT|ADJUST_TOP;
}
pgfx_knob::~pgfx_knob()
{
}

void gfx_knob::Adjust(int a)
{
	p->adjust=a;
}
void gfx_knob::draw_normal(class gadget *g,int x,int y,int w,int h)
{
	x++; y++;
	h-=2; w-=2;
	h=h/2; w=w/2; if (w<h) h=w;

	XSetForeground(display(),g->gg_gc(),col_background());
	for(int i=2;i<=h;i++)
	{
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+h+h-i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+h+h-1,y+h);
	}
	XSetForeground(display(),g->gg_gc(),col_shine());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x+h+h,y+h);
	XSetForeground(display(),g->gg_gc(),col_shine2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+h+h-1,y+h);

	XSetForeground(display(),g->gg_gc(),col_shadow());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x+h+h,y+h);
	XSetForeground(display(),g->gg_gc(),col_shadow2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+h+h-1,y+h);
}
void gfx_knob::draw_selected(class gadget *g,int x,int y,int w,int h)
{
	x++; y++;
	h-=2; w-=2;
	h=h/2; w=w/2; if (w<h) h=w;

	XSetForeground(display(),g->gg_gc(),col_selected());
	for(int i=2;i<=h;i++)
	{
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+h+h-i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+h+h-1,y+h);
	}
	if (defaults.new3D)
		XSetForeground(display(),g->gg_gc(),col_shadow2());
	else
		XSetForeground(display(),g->gg_gc(),col_shadow());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x+h+h,y+h);
	if (defaults.new3D)
		XSetForeground(display(),g->gg_gc(),col_shadow());
	else
		XSetForeground(display(),g->gg_gc(),col_shadow2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+h+h-1,y+h);

	if (defaults.new3D)
		XSetForeground(display(),g->gg_gc(),col_shine2());
	else
		XSetForeground(display(),g->gg_gc(),col_shine());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x+h+h,y+h);
	if (defaults.new3D)
		XSetForeground(display(),g->gg_gc(),col_shine());
	else
		XSetForeground(display(),g->gg_gc(),col_shine2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+h+h-1,y+h);
}
void gfx_knob::draw_locked(class gadget *g,int x,int y,int w,int h)
{
	x++; y++;
	h-=2; w-=2;
	h=h/2; w=w/2; if (w<h) h=w;

	XSetForeground(display(),g->gg_gc(),col_background());
	for(int i=2;i<=h;i++)
	{
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+h+h-i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+h+h-1,y+h);
	}
	XSetForeground(display(),g->gg_gc(),col_shine());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x+h+h,y+h);
	XSetForeground(display(),g->gg_gc(),col_shadow2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+h+h-1,y+h);

	XSetForeground(display(),g->gg_gc(),col_shadow());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x+h+h,y+h);
	XSetForeground(display(),g->gg_gc(),col_shine2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+h+h-1,y+h);
}
void gfx_knob::draw_selectedlocked(class gadget *g,int x,int y,int w,int h)
{
	x++; y++;
	h-=2; w-=2;
	h=h/2; w=w/2; if (w<h) h=w;

	XSetForeground(display(),g->gg_gc(),col_selected());
	for(int i=2;i<=h;i++)
	{
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+i,x+h+h-i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+i,y+h);
		XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-i,x+h+h-1,y+h);
	}
	XSetForeground(display(),g->gg_gc(),col_shadow());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y,x+h+h,y+h);
	XSetForeground(display(),g->gg_gc(),col_shine2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+1,x+h+h-1,y+h);

	XSetForeground(display(),g->gg_gc(),col_shine());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h,x+h+h,y+h);
	XSetForeground(display(),g->gg_gc(),col_shadow2());
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+1,y+h);
	XDrawLine(display(),g->gg_win(),g->gg_gc(),x+h,y+h+h-1,x+h+h-1,y+h);
}

int gfx_knob::height(class gadget *g)
{
	return NOLIMIT;
}
int gfx_knob::width(class gadget *g)
{
	return NOLIMIT;
}

#endif
