text.cpp

Go to the documentation of this file.
00001 #ifndef TEXT_IMPLEMENTATION_FILE
00002 #define TEXT_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : text                                                              *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "text.h"
00019 #include "khwmuser.h"
00020 #include "wp_implementation.h"
00021 
00022 text::text(char *to_print, const c_point &origin, canvas *draw_on,
00023   fontID font_to_use) : _font(font_to_use), _rotation(0),
00024   _contents(to_print), drawable(origin, draw_on) {}
00025 
00026 text::~text() {}
00027 
00028 void text::set_contents(char *to_print) { _contents = to_print; }
00029 
00030 fontID text::font() const { return _font; }
00031 
00032 void text::set_font(fontID text_font) { _font = text_font; }
00033 
00034 int text::rotation() const { return _rotation; }
00035 
00036 void text::set_rotation(int rotation) { _rotation = rotation; }
00037 
00038 void text::goto_xy(float x, float y) { goto_xy(c_point(x, y)); }
00039 
00040 char *text::contents() { return _contents; }
00041 
00042 void text::draw()
00043 {
00044   screen_change_prefix();
00045   c_point position(origin().x, warp_y(origin().y + height() - 1));
00046   int col = _color.color();
00047   KHWM_font_setAttrib(_font, col, _rotation);
00048   KHWM_font_outstring(_canvas()->handle(), position.x, position.y, _contents);
00049   screen_change_suffix();
00050 }
00051 
00052 void text::erase()
00053 {
00054   screen_change_prefix();
00055   c_point position(origin().x, warp_y(origin().y + height() - 1));
00056   int col = _canvas()->background();
00057   KHWM_font_setAttrib(_font, col, _rotation);
00058   KHWM_font_outstring
00059     (_canvas()->handle(), position.x, position.y, _contents);
00060   screen_change_suffix();
00061 }
00062 
00063 c_rectangle text::dimensions()
00064 {
00065   KHWM_font_setAttrib(_font, _color.color(), _rotation);
00066   return c_rectangle(origin(), origin()
00067     + c_point(KHWM_font_getwidth(_contents),
00068         KHWM_font_getheight(_contents)) );
00069 }
00070 
00071 fontID text::read_font(char *font_filename)
00072 {
00073   int return_code = KHWM_font_load(font_filename);
00074   if (return_code < 0) _font = 0;
00075   else _font = return_code;
00076   return return_code;
00077 }
00078 
00079 void text::goto_xy(const c_point &xy)
00080 {
00081   string hold_contents(_contents);
00082   _contents = "X";
00083   float font_height = height();
00084   float font_width = width();
00085   _contents = hold_contents;
00086   set_origin(c_point(xy.x * font_width + 1,
00087       warp_y(xy.y * font_height + font_height + 1)));
00088 }
00089 
00090 #endif //TEXT_IMPLEMENTATION_FILE
00091 

Generated on Fri Nov 21 04:29:36 2008 for HOOPLE Libraries by  doxygen 1.5.1