// -*- C++ -*-
//
//  This file is part of Siena, a wide-area event notification system.
//  See http://www.cs.colorado.edu/serl/dot/siena.html
//
//  Author: Antonio Carzaniga <carzanig@cs.colorado.edu>
//  See the file AUTHORS for full details. 
//
//  Copyright (C) 1998-1999 University of Colorado
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program 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 General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
//  USA, or send email to serl@cs.colorado.edu.
//
//
// $Id: Image.cc,v 1.1 2002/06/12 17:05:28 carzanig Exp $
//
#include <gtk/gtk.h>
#include "Image.h"

void Image::draw(GdkPixmap *pixmap, GdkGC *gc, const GdkPoint & point,
		 GdkRectangle * rect) const {
    this->draw(pixmap, gc, point);
    this->get_rectangle(point, rect);
}

void Circle::draw(GdkPixmap *pixmap, GdkGC *gc, const GdkPoint & point) const {
    gdk_draw_arc(pixmap, gc,
		 FALSE, point.x - radius, point.y - radius,
		 2 * radius + 1, 2 * radius + 1,
		 0, 360*64);
}

void Circle::get_rectangle(const GdkPoint & point, GdkRectangle * rect) const {
    rect->x = point.x - radius;
    rect->y = point.y - radius;
    rect->width = 2 * radius;
    rect->height = 2 * radius;
}

PixmapImage::PixmapImage(GtkWidget *pix_widget, char **data, int w, int h)
    : width(w), height(h) {
    GdkBitmap * mask;
    GdkColormap * colormap;

    colormap = gtk_widget_get_colormap(pix_widget);
    pix = gdk_pixmap_colormap_create_from_xpm_d((GdkWindow *)0, 
						colormap, & mask, 
						(GdkColor *)0, data);
    gdk_bitmap_unref(mask);
}

PixmapImage::~PixmapImage() {
    if (pix) gdk_bitmap_unref(pix);
}

void PixmapImage::draw(GdkPixmap *pixmap, GdkGC *gc, 
		       const GdkPoint & point) const {
    gdk_draw_pixmap(pixmap, gc, 
		    pix, 0, 0, 
		    point.x - width/2, point.y - height/2, 
		    width, height);
}

void PixmapImage::get_rectangle(const GdkPoint & point, 
				GdkRectangle * rect) const {
    rect->x = point.x - width/2;
    rect->y = point.y - height/2;
    rect->width = width;
    rect->height = height;
}

TextImage::TextImage(GdkFont *f, const string &s): font(f), text(s) {
    width = gdk_string_measure(font, text.c_str());
    height = gdk_string_height(font, text.c_str());
}

void TextImage::draw(GdkPixmap *pixmap, GdkGC *gc, 
		     const GdkPoint & point) const {
    gdk_draw_string(pixmap, font, gc, point.x, point.y, text.c_str());
}

void TextImage::get_rectangle(const GdkPoint & point,
			      GdkRectangle * rect) const {
    rect->x = point.x - width/2;
    rect->y = point.y - height/2;
    rect->width = width;
    rect->height = height;
}

