/***************************************************************************
                            QCanvas.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QCanvas.h>
#include <qtobjc/QCanvas.h>
#include <qtobjc/QPixmap.h>
#include <qtobjc/QPoint.h>
#include <qtobjc/QRect.h>
#include <qtobjc/QCanvasItem.h>
#include <qtobjc/QCanvasView.h>

@implementation  QCanvas


- initWithObject: (QObject *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QCanvas((qt_QObject *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QCanvas(0, 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithInt: (int)w h: (int)h
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QCanvas1((int)w, (int)h)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithPixmap: (QPixmap *)p h: (int)h v: (int)v tilewidth: (int)tilewidth tileheight: (int)tileheight
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QCanvas2((qt_QPixmap *) [p qt], (int)h, (int)v, (int)tilewidth, (int)tileheight)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld] && [self parent] == nil) {
			qt_del_QCanvas((qt_QCanvas *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- setTiles: (QPixmap *)tiles h: (int)h v: (int)v tilewidth: (int)tilewidth tileheight: (int)tileheight
{
	qt_QCanvas_setTiles((qt_QCanvas *)[self qt], (qt_QPixmap *) [tiles qt], (int)h, (int)v, (int)tilewidth, (int)tileheight);
	return self;
}

- setBackgroundPixmap: (QPixmap *)p
{
	qt_QCanvas_setBackgroundPixmap((qt_QCanvas *)[self qt], (qt_QPixmap *) [p qt]);
	return self;
}

- (QPixmap*) backgroundPixmap
{
	return (QPixmap*) [QtSupport objectForQtKey: qt_QCanvas_backgroundPixmap((qt_QCanvas *)[self qt]) withClass: [QPixmap class] allocatedInObjcWorld: YES];
}

- setBackgroundColor: (QColor *)c
{
	qt_QCanvas_setBackgroundColor((qt_QCanvas *)[self qt], (qt_QColor *) [c qt]);
	return self;
}

- (QColor*) backgroundColor
{
	return (QColor*) [QtSupport objectForQtKey: qt_QCanvas_backgroundColor((qt_QCanvas *)[self qt]) withClass: [QColor class] allocatedInObjcWorld: YES];
}

- setTile: (int)x y: (int)y tilenum: (int)tilenum
{
	qt_QCanvas_setTile((qt_QCanvas *)[self qt], (int)x, (int)y, (int)tilenum);
	return self;
}

- (int) tile: (int)x y: (int)y
{
	return (int) qt_QCanvas_tile((qt_QCanvas *)[self qt], (int)x, (int)y);
}

- (int) tilesHorizontally
{
	return (int) qt_QCanvas_tilesHorizontally((qt_QCanvas *)[self qt]);
}

- (int) tilesVertically
{
	return (int) qt_QCanvas_tilesVertically((qt_QCanvas *)[self qt]);
}

- (int) tileWidth
{
	return (int) qt_QCanvas_tileWidth((qt_QCanvas *)[self qt]);
}

- (int) tileHeight
{
	return (int) qt_QCanvas_tileHeight((qt_QCanvas *)[self qt]);
}

- resize: (int)width height: (int)height
{
	qt_QCanvas_resize((qt_QCanvas *)[self qt], (int)width, (int)height);
	return self;
}

- (int) width
{
	return (int) qt_QCanvas_width((qt_QCanvas *)[self qt]);
}

- (int) height
{
	return (int) qt_QCanvas_height((qt_QCanvas *)[self qt]);
}

- (QSize*) size
{
	return (QSize*) [QtSupport objectForQtKey: qt_QCanvas_size((qt_QCanvas *)[self qt]) withClass: [QSize class] allocatedInObjcWorld: YES];
}

- (QRect*) rect
{
	return (QRect*) [QtSupport objectForQtKey: qt_QCanvas_rect((qt_QCanvas *)[self qt]) withClass: [QRect class] allocatedInObjcWorld: YES];
}

- (BOOL) onCanvas: (int)x y: (int)y
{
	return (BOOL) qt_QCanvas_onCanvas((qt_QCanvas *)[self qt], (int)x, (int)y);
}

- (BOOL) onCanvas: (QPoint*)p
{
	return (BOOL) qt_QCanvas_onCanvas1((qt_QCanvas *)[self qt], (qt_QPoint*) [p qt]);
}

- (BOOL) validChunk: (int)x y: (int)y
{
	return (BOOL) qt_QCanvas_validChunk((qt_QCanvas *)[self qt], (int)x, (int)y);
}

- (BOOL) validChunk: (QPoint*)p
{
	return (BOOL) qt_QCanvas_validChunk1((qt_QCanvas *)[self qt], (qt_QPoint*) [p qt]);
}

- (int) chunkSize
{
	return (int) qt_QCanvas_chunkSize((qt_QCanvas *)[self qt]);
}

- retune: (int)chunksize maxclusters: (int)maxclusters
{
	qt_QCanvas_retune((qt_QCanvas *)[self qt], (int)chunksize, (int)maxclusters);
	return self;
}

- retune: (int)chunksize 
{
	qt_QCanvas_retune((qt_QCanvas *)[self qt], (int)chunksize, 100);
	return self;
}

- (BOOL) sameChunk: (int)x1 y1: (int)y1 x2: (int)x2 y2: (int)y2
{
	return (BOOL) qt_QCanvas_sameChunk((qt_QCanvas *)[self qt], (int)x1, (int)y1, (int)x2, (int)y2);
}

- setChangedChunk: (int)i j: (int)j
{
	qt_QCanvas_setChangedChunk((qt_QCanvas *)[self qt], (int)i, (int)j);
	return self;
}

- setChangedChunkContaining: (int)x y: (int)y
{
	qt_QCanvas_setChangedChunkContaining((qt_QCanvas *)[self qt], (int)x, (int)y);
	return self;
}

- setAllChanged
{
	qt_QCanvas_setAllChanged((qt_QCanvas *)[self qt]);
	return self;
}

- setChanged: (QRect*)area
{
	qt_QCanvas_setChanged((qt_QCanvas *)[self qt], (qt_QRect*) [area qt]);
	return self;
}

- setUnchanged: (QRect*)area
{
	qt_QCanvas_setUnchanged((qt_QCanvas *)[self qt], (qt_QRect*) [area qt]);
	return self;
}

- addItemToChunk: (QCanvasItem*)arg1 i: (int)i j: (int)j
{
	qt_QCanvas_addItemToChunk((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt], (int)i, (int)j);
	return self;
}

- removeItemFromChunk: (QCanvasItem*)arg1 i: (int)i j: (int)j
{
	qt_QCanvas_removeItemFromChunk((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt], (int)i, (int)j);
	return self;
}

- addItemToChunkContaining: (QCanvasItem*)arg1 x: (int)x y: (int)y
{
	qt_QCanvas_addItemToChunkContaining((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt], (int)x, (int)y);
	return self;
}

- removeItemFromChunkContaining: (QCanvasItem*)arg1 x: (int)x y: (int)y
{
	qt_QCanvas_removeItemFromChunkContaining((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt], (int)x, (int)y);
	return self;
}

//- (QCanvasItemList*) allItems
//{
//	return (QCanvasItemList*) [QtSupport objectForQtKey: qt_QCanvas_allItems((qt_QCanvas *)[self qt]) withClass: [QCanvasItemList class] allocatedInObjcWorld: YES];
//}

//- (QCanvasItemList*) collisions: (QPoint*)arg1
//{
//	return (QCanvasItemList*) [QtSupport objectForQtKey: qt_QCanvas_collisions((qt_QCanvas *)[self qt], (qt_QPoint*) [arg1 qt]) withClass: [QCanvasItemList class] allocatedInObjcWorld: YES];
//}

//- (QCanvasItemList*) collisions: (QRect*)arg1
//{
//	return (QCanvasItemList*) [QtSupport objectForQtKey: qt_QCanvas_collisions1((qt_QCanvas *)[self qt], (qt_QRect*) [arg1 qt]) withClass: [QCanvasItemList class] allocatedInObjcWorld: YES];
//}

//- (QCanvasItemList*) collisions: (QPointArray*)pa item: (QCanvasItem*)item exact: (BOOL)exact
//{
//	return (QCanvasItemList*) [QtSupport objectForQtKey: qt_QCanvas_collisions2((qt_QCanvas *)[self qt], (qt_QPointArray*) [pa qt], (qt_QCanvasItem*) [item qt], (int)exact) withClass: [QCanvasItemList class] allocatedInObjcWorld: YES];
//}

- drawArea: (QRect*)arg1 p: (QPainter *)p double_buffer: (BOOL)double_buffer
{
	qt_QCanvas_drawArea((qt_QCanvas *)[self qt], (qt_QRect*) [arg1 qt], (qt_QPainter *) [p qt], (int)double_buffer);
	return self;
}

- drawArea: (QRect*)arg1 p: (QPainter *)p 
{
	qt_QCanvas_drawArea((qt_QCanvas *)[self qt], (qt_QRect*) [arg1 qt], (qt_QPainter *) [p qt], 0);
	return self;
}

- addView: (QCanvasView*)arg1
{
	qt_QCanvas_addView((qt_QCanvas *)[self qt], (qt_QCanvasView*) [arg1 qt]);
	return self;
}

- removeView: (QCanvasView*)arg1
{
	qt_QCanvas_removeView((qt_QCanvas *)[self qt], (qt_QCanvasView*) [arg1 qt]);
	return self;
}

- drawCanvasArea: (QRect*)arg1 p: (QPainter *)p double_buffer: (BOOL)double_buffer
{
	qt_QCanvas_drawCanvasArea((qt_QCanvas *)[self qt], (qt_QRect*) [arg1 qt], (qt_QPainter *) [p qt], (int)double_buffer);
	return self;
}

- drawCanvasArea: (QRect*)arg1 
{
	qt_QCanvas_drawCanvasArea((qt_QCanvas *)[self qt], (qt_QRect*) [arg1 qt], 0, 1);
	return self;
}

- drawViewArea: (QCanvasView*)view p: (QPainter *)p r: (QRect*)r dbuf: (BOOL)dbuf
{
	qt_QCanvas_drawViewArea((qt_QCanvas *)[self qt], (qt_QCanvasView*) [view qt], (qt_QPainter *) [p qt], (qt_QRect*) [r qt], (int)dbuf);
	return self;
}

- addCanvasItem: (QCanvasItem*)arg1
{
	qt_QCanvas_addItem((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt]);
	return self;
}

- addAnimation: (QCanvasItem*)arg1
{
	qt_QCanvas_addAnimation((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt]);
	return self;
}

- removeCanvasItem: (QCanvasItem*)arg1
{
	qt_QCanvas_removeItem((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt]);
	return self;
}

- removeAnimation: (QCanvasItem*)arg1
{
	qt_QCanvas_removeAnimation((qt_QCanvas *)[self qt], (qt_QCanvasItem*) [arg1 qt]);
	return self;
}

- setAdvancePeriod: (int)ms
{
	qt_QCanvas_setAdvancePeriod((qt_QCanvas *)[self qt], (int)ms);
	return self;
}

- setUpdatePeriod: (int)ms
{
	qt_QCanvas_setUpdatePeriod((qt_QCanvas *)[self qt], (int)ms);
	return self;
}

- setDoubleBuffering: (BOOL)y
{
	qt_QCanvas_setDoubleBuffering((qt_QCanvas *)[self qt], (int)y);
	return self;
}

- advance
{
	qt_QCanvas_advance((qt_QCanvas *)[self qt]);
	return self;
}

- update
{
	qt_QCanvas_update((qt_QCanvas *)[self qt]);
	return self;
}

- drawBackground: (QPainter*)arg1 area: (QRect*)area
{
	qt_QCanvas_drawBackground((qt_QCanvas *)[self qt], (qt_QPainter*) [arg1 qt], (qt_QRect*) [area qt]);
	return self;
}

- drawForeground: (QPainter*)arg1 area: (QRect*)area
{
	qt_QCanvas_drawForeground((qt_QCanvas *)[self qt], (qt_QPainter*) [arg1 qt], (qt_QRect*) [area qt]);
	return self;
}

@end
