Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

ui_label.cpp

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/07 19:02:03 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: ui_label.cpp,v 1.1.1.1 2002/12/07 19:02:03 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: ui_label.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:03  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00040 #include            "omicron/internal.h"
00041 #include            "omicron/render.h"
00042 #include            "omicron/image.h"
00043 #include            "omicron/gui.h"
00044 
00045 uilabel_c::uilabel_c()
00046 {
00047     classname   = "label";
00048     fnt         = gv.gui->get_font(UIF_FONT8);
00049 
00050     set_wordwrap(true);
00051 }
00052 
00053 uilabel_c::~uilabel_c()
00054 {
00055     AssertThis;
00056 }
00057 
00058 void uilabel_c::paint()
00059 {
00060     AssertThis;
00061 
00062     uiobject_c::paint();
00063 
00064     AssertReturn2(text, strlen(text));
00065 
00066     char        *buf    = new char[strlen(text)+2];
00067     char        *p      = buf;
00068     char        *p1     = buf;
00069     ushort      y       = 0;
00070     color_t     c       = disabled ? gv.gui->get_color(UIC_DISABLED) :
00071                                      gv.gui->get_color(UIC_TEXT);
00072 
00073     ushort      linelen = 0;
00074 
00075     memset(buf, 0, strlen(text)+2);
00076     strcpy(buf, text);
00077 
00078     if (wordwrap)
00079     {
00080         while(*p)
00081         {
00082             p++;
00083 
00084             while(*p1 == '\n') { p1++; y+=fnt->height; };
00085 
00086             if ((*p == 0 || *p == '\n'))
00087             {
00088                 char oldchar = *p;
00089 
00090                 *p = 0;
00091         
00092                 do
00093                 {
00094                     linelen = gv.renderer->get_string_pixelwidth(p1, fnt);
00095                     if (linelen >= width)
00096                     {
00097                         char *p2 = strrchr(p1, ' ');
00098                         if (p2)
00099                         {
00100                             *p  = oldchar;
00101                             p   = p2;
00102                             *p  = 0;
00103                             oldchar = ' ';
00104                             linelen = gv.renderer->get_string_pixelwidth(p1, fnt);
00105                         }
00106                         else
00107                         {
00108                             linelen = 0;
00109                         }
00110                     }
00111                 } while(linelen>=width);
00112 
00113                 img->draw_string(0, y, p1, fnt, c);
00114                 y += fnt->height;
00115 
00116                 p1 = ++p;
00117             }
00118         }
00119     }
00120     else
00121     {
00122         img->draw_string(0, 0, buf, fnt, c);
00123     }
00124 
00125     SafeArrayDelete(buf);
00126 }

Generated on Wed Dec 18 15:48:48 2002 for omicron engine by doxygen1.2.18