label.cpp

Go to the documentation of this file.
00001 /*
00002  * label.cpp
00003  *
00004  * Copyright (C) 2008  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Implementation of a text-only dialog element (static label).
00032  */
00033 
00034 // includes --------------------------------------------------------------------
00035 #include "element.h"                    // always include our own header first!
00036 
00037 #include "dialog.h"
00038 
00039 #include "common/wave_ex.h"
00040 #include "datahash/datahash_util.h"
00041 
00042 
00043 namespace dialog {
00044 
00045 
00046 ////////////////////////////////////////////////////////////////////////////////
00047 //
00048 //      Label -- class that implements the Element interface for text elements
00049 //
00050 ////////////////////////////////////////////////////////////////////////////////
00051 
00052 class Label : public Element {
00053 public:
00054         Label(void) throw();
00055         ~Label(void) throw() { }
00056 
00057         // public class methods ------------------------------------------------
00058         void initialize(IN const Datahash * hash,
00059                                 IN smart_ptr<Drawer>& drawer);
00060 
00061         // dialog::Element class interface methods -----------------------------
00062         int getWidth(void) { return m_width; }
00063         int getHeight(void) { return m_height; }
00064         void draw(IN const point_t& offset);
00065         void cursor(IN const point_t& pos) { }
00066         const char * button(IN int button, IN int state,
00067                                 IN const point_t& pos) { return NULL; }
00068 
00069 private:
00070         // private helper methods ----------------------------------------------
00071 
00072         // private member data -------------------------------------------------
00073         std::string             m_value;
00074         int                     m_width;
00075         int                     m_height;
00076         smart_ptr<Drawer>       m_drawer;
00077 };
00078 
00079 
00080 
00081 Label::Label(void) throw()
00082 {
00083 }
00084 
00085 
00086 
00087 void
00088 Label::initialize
00089 (
00090 IN const Datahash * hash,
00091 IN smart_ptr<Drawer>& drawer
00092 )
00093 {
00094         ASSERT(hash, "null");
00095         ASSERT(drawer, "null");
00096 
00097         m_drawer = drawer;
00098         m_value = getString(hash, "value");
00099 
00100         font_size_t fs =
00101             m_drawer->getFontSizing(eElement_Label, m_value.c_str());
00102 
00103         m_width = fs.width;
00104         m_height = fs.height;
00105 }
00106 
00107 
00108 
00109 void
00110 Label::draw
00111 (
00112 IN const point_t& offset
00113 )
00114 {
00115         ASSERT(m_drawer, "null");
00116 
00117         m_drawer->drawString(eElement_Label, offset, m_value.c_str());
00118 }
00119 
00120 
00121 
00122 ////////////////////////////////////////////////////////////////////////////////
00123 //
00124 //      public API
00125 //
00126 ////////////////////////////////////////////////////////////////////////////////
00127 
00128 smart_ptr<Element>
00129 createLabelElement
00130 (
00131 IN Manager * mgr,
00132 IN const Datahash * hash
00133 )
00134 {
00135         ASSERT(mgr, "null");
00136         ASSERT(hash, "null");
00137 
00138         smart_ptr<Label> local = new Label;
00139         ASSERT(local, "out of memory");
00140 
00141         smart_ptr<Drawer> drawer = mgr->getDrawer();
00142         local->initialize(hash, drawer);
00143 
00144         return local;
00145 }
00146 
00147 
00148 
00149 };      // dialog namespace
00150