Changeset 110


Ignore:
Timestamp:
06/07/13 09:25:32 (12 years ago)
Author:
shark
Message:
  • Doing a little documenting.
Location:
trunk/nv
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gfx/image.hh

    r90 r110  
    3131         * By an image we understand a group of pixels, limited to X and Y
    3232         * dimensions, of a certain depth (by depth we mean how rich
    33          * the colors are.
     33         * the colors are).
    3434         */
    3535        class image
  • trunk/nv/gfx/texture_font.hh

    r96 r110  
    1818        struct texture_glyph
    1919        {
    20                 uint16 charcode;
    21                 glm::ivec2 size;
    22                 glm::ivec2 offset;
    23                 glm::vec2 advance;
    24                 glm::vec2 tl;
    25                 glm::vec2 br;
    26                 std::unordered_map< uint16, float > kerning;
     20                uint16 charcode; ///< Character code value.
     21                glm::ivec2 size; ///< Width and height of the glyph.
     22                glm::ivec2 offset; ///< Offset of the glyph's position from the base line.
     23                glm::vec2 advance; ///< Cursor advance distance.
     24                glm::vec2 tl; ///< Top-left of the glyph's bounding box.
     25                glm::vec2 br; ///< Bottom-right of the glyph's bounding box.
     26                std::unordered_map< uint16, float > kerning; ///< Kerning space between other characters.
    2727
     28                /**
     29                 *Creates a new texture_glyph.
     30                 */
    2831                texture_glyph();
    29                 float get_kerning( const uint16 charcode );
     32
     33                /**
     34                 *Gets the kerning space between this character and the requested character.
     35                 *
     36                 *@param charcode The character to get the spacing for.
     37                 *@returns The amount of space for kerning.
     38                 */
     39                float get_kerning( const uint16 charcode );
    3040        };
    3141
     
    4050                        void generate_kerning();
    4151                private:
    42                         std::unordered_map< uint16, texture_glyph > m_glyphs;
    43                         texture_atlas* m_atlas;
    44                         std::string m_filename;
    45                         float m_size;
    46                         float m_height;
    47                         float m_linegap;
    48                         float m_ascender;
    49                         float m_descender;
    50                         bool m_hinting;
    51                         bool m_filtering;
    52                         uint8 m_lcd_weights[5];
    53                         void* m_rlibrary;
    54                         void* m_rface;
     52                        std::unordered_map< uint16, texture_glyph > m_glyphs; ///< Hash table of glyphs for this font.
     53                        texture_atlas* m_atlas; ///< Atlas Image object for this font.
     54                        std::string m_filename; ///< Name of the file.
     55                        float m_size; ///< Font size.
     56                        float m_height; ///< Height of the font. (x-height?)
     57                        float m_linegap; ///< Amount of space between lines.
     58                        float m_ascender; ///< Height of ascender lines (lines extending above the glyph's x-height).
     59                        float m_descender; ///< Height of descender lines (lines extending below the glyph's x-height).
     60                        bool m_hinting; ///< Whether or not glyph hints are used.
     61                        bool m_filtering; ///< Whether or not glyphs are color filtered for LCD displays.
     62                        uint8 m_lcd_weights[5]; ///< Color filtering weights.
     63                        void* m_rlibrary; ///< Pointer to the library.
     64                        void* m_rface; ///< Pointer to the font face.
    5565        };
    5666}
  • trunk/nv/gui/gui_element.hh

    r99 r110  
    2626                {
    2727                public:
     28
     29                        /**
     30                         *Creates a new GUI element.
     31                         */
    2832                        element() : object() {}
     33
     34                        /**
     35                         *Creates a new GUI element with the give root node and postioning data.
     36                         *
     37                         *@param aroot The root object that will be this object's parent.
     38                         *@param r The rectangle representing the position and size of this element.
     39                         */
    2940                        element( root* aroot, const rectangle& r );
     41
     42                        /**
     43                         *Gets the deepest child element that contains the indicated point.
     44                         *
     45                         *@param p The position to check.
     46                         *@returns The last child element that contains the given point.
     47                         */
    3048                        element* get_element( const position& p );
     49
     50                        /**
     51                         *Event handler for update events.  Calls on_update for all affected children.
     52                         *
     53                         *@param elapsed Time since last update.
     54                         */
    3155                        virtual void on_update( uint32 elapsed );
     56
     57                        /**
     58                         *Event handler for draw events.  Calls on_draw for all affected children.
     59                         */
    3260                        virtual void on_draw();
     61
     62                        /**
     63                         *Event handler for IO events.  Class on_event for all affected children.
     64                         *
     65                         *@param event The event data.
     66                         *@returns ???
     67                         */
    3368                        virtual bool on_event( const io_event& event );
     69
     70                        /**
     71                         *Checks if this element contains the given point.
     72                         *
     73                         *@param p The point to check.
     74                         *@returns True if the point is within the region of the element, false otherwise.
     75                         */
    3476                        virtual bool contains( const position& p ) const;
     77
     78                        /**
     79                         *Sets the position and size of this element relative to its parent.
     80                         *
     81                         *@param r The new position and size of the element.
     82                         */
    3583                        virtual void set_relative( const rectangle& r );
     84
     85                        /**
     86                         *Sets the position of this element relative to its parent.
     87                         *
     88                         *@param p The new position of the element.
     89                         */
    3690                        virtual void set_relative( const position& p );
     91
     92                        /**
     93                         *Gets the position and size of the element relative to its parent.
     94                         *
     95                         *@returns The element's position and size relative to its parent.
     96                         */
    3797                        virtual const rectangle& get_relative() const { return m_relative; }
     98
     99                        /**
     100                         *Gets the position and size of the element relative to the root (window).
     101                         *
     102                         *@returns The element's position and size relative to the root (window).
     103                         */
    38104                        virtual const rectangle& get_absolute() const { return m_absolute; }
     105
     106                        /**
     107                         *Gets the parent element of this element.
     108                         *
     109                         *@returns The parent element.
     110                         */
    39111                        virtual element* get_parent() const { return (element*)m_parent; }
     112
     113                        /**
     114                         *Gets whether this element is currently accepting events.
     115                         *
     116                         *@returns True if the element is receiving events, false otherwise.
     117                         */
    40118                        virtual bool is_enabled() const { return m_enabled; }
     119
     120                        /**
     121                         *Gets whether this element is currently visible.
     122                         *
     123                         *@returns True if the element is visible, false otherwise.
     124                         */
    41125                        virtual bool is_visible() const { return m_visible; }
     126
     127                        /**
     128                         *Gets whether this element needs to be redrawn.
     129                         *
     130                         *@returns True if the element needs to be redrawn, false if not.
     131                         */
    42132                        virtual bool is_dirty()   const { return m_dirty; }
     133
     134                        /**
     135                         *Sets whether this element is currently accepting events.
     136                         *
     137                         *@param value True to allow the element and its children to receive events, false to disable.
     138                         */
    43139                        virtual void set_enabled( bool value ) { m_enabled = value; }
     140
     141                        /**
     142                         *Sets whether this element is visible on the screen.
     143                         *
     144                         *@param value True to display the element and its children, false to hide it and its children.
     145                         */
    44146                        virtual void set_visible( bool value ) { m_visible = value; }
     147
     148                        /**
     149                         *Sets whether this element needs to be redrawn.
     150                         *
     151                         *@param value True to request that the element and its children be redrawn, false if not.
     152                         */
    45153                        virtual void set_dirty( bool value )   { m_dirty   = value; }
     154
     155                        /**
     156                         *Gets the text associated with this element.
     157                         *
     158                         *@returns A string containing the associated text.
     159                         */
    46160                        virtual const string& get_text() const { return m_text; }
     161
     162                        /**
     163                         *Sets the text associated with this element.
     164                         *
     165                         *@param text The new text to associate with this element.
     166                         */
    47167                        virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
     168
     169                        /**
     170                         *Gets the class name associated with this element.
     171                         *
     172                         *@returns A string containing the class name of this element.
     173                         */
    48174                        virtual const string& get_class() const { return m_class; }
     175
     176                        /**
     177                         *sets the class name associated with this element.
     178                         *
     179                         *@param class_ The new class name.
     180                         */
    49181                        virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
     182
     183                        /**
     184                         *Recalcuates the absolute position of the element and the element's children.
     185                         */
    50186                        virtual void recalculate_absolute();
     187
     188                        /**
     189                         *Recalculates the aboslute position of the element's children.
     190                         */
    51191                        virtual void recalculate_absolute_children();
     192
     193                        /**
     194                         *Destroys the element.
     195                         */
    52196                        virtual ~element();
    53197                protected:
    54198                        friend class environment;
    55199
    56                         string    m_class;
    57                         string    m_text;
    58                         rectangle m_relative;
    59                         rectangle m_absolute;
    60                         bool m_enabled;
    61                         bool m_visible;
    62                         bool m_dirty;
    63                         render_data* m_render_data;
     200                        string    m_class; ///< Class name.
     201                        string    m_text; ///< Displayed label or text.
     202                        rectangle m_relative; ///< Position relative to parent.
     203                        rectangle m_absolute; ///< Position relative to window/screen.
     204                        bool m_enabled; ///< Whether the element accepts events.
     205                        bool m_visible; ///< Whether the element is drawn.
     206                        bool m_dirty; ///< Whether the element needs updating.
     207                        render_data* m_render_data; ///<   -?-
    64208                };
    65209
  • trunk/nv/interface/render_state.hh

    r31 r110  
    186186        };
    187187
    188 } // namespace nova
     188} // namespace nv
    189189
    190190
    191 #endif // NOVA_RENDER_STATE_HH
     191#endif // NV_RENDER_STATE_HH
  • trunk/nv/io_event.hh

    r93 r110  
    6767        struct mouse_button_event
    6868        {
     69                /// X position where mouse was clicked.
    6970                uint16 x;
     71                /// Y position where mouse was clicked.
    7072                uint16 y;
    71                 ///
     73                /// Button that was clicked.
    7274                uint32 button;
    7375                /// True if pressed
     
    7981        struct mouse_move_event
    8082        {
     83                /// X Position the mouse moved to.
    8184                uint16 x;
     85                /// Y Position the mouse moved to.
    8286                uint16 y;
     87                /// Distance in x direction mouse was moved.
    8388                sint16 rx;
     89                /// Distance in y direction mouse was moved.
    8490                sint16 ry;
    8591                /// True if pressed
     
    9197        struct resize_event
    9298        {
     99                /// New x size of the object.
    93100                sint32 x;
     101                /// New y size of the object.
    94102                sint32 y;
    95103        };
     
    97105        struct active_event
    98106        {
     107                /// Whether focus was gained or lost.
    99108                bool gain;
    100109        };
     
    121130        };
    122131
     132        /**
     133         *Gets the name of the key given the code.
     134         *
     135         *@param key The code value of the key.
     136         *@returns The name of the key.
     137         */
    123138        const char* get_key_name( key_code key );
     139
     140        /**
     141         *Gets the name of the mouse button given the code.
     142         *
     143         *@param button The code value of the mouse button.
     144         *@returns The name of the button.
     145         */
    124146        const char* get_mouse_name( mouse_code button );
     147
     148        /**
     149         *Gets the name of the IO event given the code.
     150         *
     151         *@param event The code value of the IO event.
     152         *@returns The name of the event.
     153         */
    125154        const char* get_io_event_name( io_event_code event );
     155
     156        /**
     157         *Registers all events to the specified database.
     158         *
     159         *@param db The database to store all event data in.
     160         */
    126161        void register_io_types( type_database* db );
    127162}
  • trunk/nv/position.hh

    r108 r110  
    3535                        struct { value_type x1,y1,x2,y2; };
    3636                };
    37 
     37                /**
     38                 *Creates a new rectangle assigned to {0, 0, 0, 0}.
     39                 */
    3840                rectangle() : ul(), lr() {}
     41               
     42                /**
     43                 *Creates a new rectangle given a position.
     44                 *
     45                 *@param p The position to assign the rectangle to.
     46                 */
    3947                rectangle( position p ) : ul(p), lr(p) {}
     48               
     49                /**
     50                 *Creates a new rectangle given an upper-left and lower-right position.
     51                 *
     52                 *@param ul The position of the upper-left corner of the rectangle.
     53                 *@param lr The position of the lower-right corner of the rectangle.
     54                 */
    4055                rectangle( position ul, position lr ) : ul(ul), lr(lr) {}
     56               
     57                /**
     58                 *Creates a new rectangle given an upper-left position, width, and height.
     59                 *
     60                 *@param ul The position of the upper-left corner of the rectangle.
     61                 *@param width The width of the rectangle.
     62                 *@param height The height of the rectangle.
     63                 */
    4164                rectangle( position ul, value_type width, value_type height ) : ul(ul), lr(ul + position(width,height)) {}
     65               
     66                /**
     67                 *Sets the dimensions of the rectangle without moving the upper-left of the rectangle.
     68                 *
     69                 *@param d The new dimensions of the rectangle.
     70                 */
    4271                rectangle& dim( dimension d ) { lr = ul + d; return *this; }
     72
     73                /**
     74                 *Moves the rectangle to a new position while maintaining its size.
     75                 *
     76                 *@param p The new position of the rectangle's upper-left corner.
     77                 */
    4378                rectangle& pos( position p )  { lr = p + (lr - ul); lr = p; return *this; }
    4479
     80                /**
     81                 *Sets the dimensions of the rectangle without moving the upper-left of the rectangle.
     82                 *
     83                 *@param d The new dimensions of the rectangle.
     84                 */
    4585                void set_dimension( dimension d ) { lr = ul + d; }
     86               
     87                /**
     88                 *Moves the rectangle to a new position while maintaining its size.
     89                 *
     90                 *@param p The new position of the rectangle's upper-left corner.
     91                 */
    4692                void set_position( position p ) { lr = p + (lr - ul); ul = p; }
    4793
     94                /**
     95                 *Gets the dimensions of the rectangle.  Synonym for get_size.
     96                 *
     97                 *@returns The dimensions of the rectangle.
     98                 *@see get_size
     99                 */
    48100                dimension get_dimension() const { return lr - ul; }
     101
     102                /**
     103                 *Gets the position of the upper-left corner of the rectangle.
     104                 *
     105                 *@returns The position of the rectangle's upper-left corner.
     106                 */
    49107                position  get_position() const { return ul; }
     108
     109                /**
     110                 *Gets the dimensions of the rectangle.  Synonym for get_dimension.
     111                 *
     112                 *@returns The dimensions of the rectangle.
     113                 *@see get_dimension
     114                 */
    50115                dimension get_size() const { return lr - ul; }
     116
     117                /**
     118                 *Gets the center of the rectangle.
     119                 *
     120                 *@returns The center of the rectangle.
     121                 */
    51122                position get_center() const { return ( lr + ul ) / 2; }
     123
     124                /**
     125                 *Gets the width of the rectangle.
     126                 *
     127                 *@returns The width of the rectangle.
     128                 */
    52129                value_type get_width() const { return x2 - x1; }
     130
     131                /**
     132                 *Gets the height of the rectangle.
     133                 *
     134                 *@returns The height of the rectangle.
     135                 */
    53136                value_type get_height() const { return y2 - y1; }
     137
     138                /**
     139                 *Gets the area of the rectangle.
     140                 *
     141                 *@returns The area of the rectangle.
     142                 */
    54143                value_type get_area() const { return (y2 - y1) * (x2 - x1); }
     144
     145                /**
     146                 *Checks to see if the rectangle is backwards.
     147                 *
     148                 *@returns True if the rectangle's upper-left is above and left (or equal to) the rectangle's lower-right, false if it is not.
     149                 */
    55150                bool is_valid() const { return x2 >= x1 && y2 >= y1; }
    56151               
     152                /**
     153                 *Shifts the rectangle by a given amount.
     154                 *
     155                 *@param pos The amount to shift the rectangle by.
     156                 */
    57157                rectangle& operator+=( const position& pos ) { ul += pos; lr += pos; return (*this); }
     158
     159                /**
     160                 *Returns a rectangle shifted by a given amount.
     161                 *
     162                 *@param pos The amount to shift by.
     163                 *@returns The shifted rectangle.
     164                 */
    58165                rectangle operator+( const position& pos ) const {      rectangle r(*this); return r += pos; }
     166
     167                /**
     168                 *Shifts the rectangle by a given amount.
     169                 *
     170                 *@param pos The amount to shift the rectangle by.
     171                 */
    59172                rectangle& operator-=( const position& pos ) { ul -= pos; lr -= pos; return (*this); }
     173
     174                /**
     175                 *Returns a rectangle shifted by a given amount.
     176                 *
     177                 *@oaram pos The amount to shift by.
     178                 *@returns The shifted rectangle.
     179                 */
    60180                rectangle operator-( const position& pos ) const {      rectangle r(*this); return r -= pos; }
     181
     182                /**
     183                 *Compares two rectangles to see if they are the same.
     184                 *
     185                 *@param r The rectangle to compare to.
     186                 *@returns True if the rectangles have the same positions and dimensions, false otherwise.
     187                 */
    61188                bool operator==( const rectangle& r ) const { return r.ul == ul && r.lr == lr; }
     189
     190                /**
     191                 *Compares two rectangles to see if they are different.
     192                 *
     193                 *@param r The rectangle to compare to.
     194                 *@returns True if the rectangles have different positions or dimensions, false otherwise.
     195                 */
    62196                bool operator!=( const rectangle& r ) const { return r.ul != ul || r.lr != lr; }
    63197
     198                /**
     199                 *Checks if a position is within the bounds of this rectangle.
     200                 *
     201                 *@param r The position to check.
     202                 *@returns True if the position is inside or on the edge of the rectangle, false otherwise.
     203                 */
    64204                bool contains( const position& r ) const{ return y2 >= r.y && y1 <= r.y && x2 >= r.x && x1 <= r.x; }
     205
     206                /**
     207                 *Checks if a rectangle is within the bounds of this rectangle.
     208                 *
     209                 *@param r The rectangle to check.
     210                 *@returns True if the entire rectangle to check is inside or on the edge of this rectangle, false otherwise.
     211                 */
    65212                bool contains( const rectangle& r ) const { return contains( r.ul ) && contains( r.lr ); }
     213
     214                /**
     215                 *Checks if another rectangle overlaps this one.
     216                 *
     217                 *@param r The rectangle to check.
     218                 *@returns True if any part of the rectangle to check overlaps this rectangle, false otherwise.
     219                 */
    66220                bool collides( const rectangle& r ) const { return y2 > r.y1 && y1 < r.y2 && x2 > r.x1 && x1 < r.x2; }
    67221
     222                /**
     223                 *Limits the region of the rectangle to the inidicated rectangle.
     224                 *
     225                 *@param r The rectangle that this rectangle is confined to.
     226                 *@returns True if the rectangle was changed, false otherwise.
     227                 */
    68228                bool clamp_to( const rectangle& r )
    69229                {
     
    75235                }
    76236
     237                /**
     238                 *Limits the size of the rectangle to the given rectangle's size.
     239                 *
     240                 *@param r The rectangle representing the maximum dimensions this rectangle can be.
     241                 *@returns True if the rectangle needed to be resized, false otherwise.
     242                 */
    77243                bool constrain_to( const rectangle& r )
    78244                {
     
    83249                }
    84250
     251                /**
     252                 *Fixes an invalid rectangle.
     253                 */
    85254                void repair()
    86255                {
     
    89258                }
    90259
     260                /**
     261                 *Expands the rectangle to just include the given point.
     262                 *
     263                 *@param p The point to include in the rectangle.
     264                 */
    91265                void include_point( position p )
    92266                {
  • trunk/nv/singleton.hh

    r3 r110  
    1818namespace nv
    1919{
    20 
     20        /**
     21         *singleton
     22         *@brief Represents an accessible static object that will only have one instance.
     23         */
    2124    template <class T>
    2225    class singleton
    2326    {
    2427    private:
    25         static T *singleton_;
     28        static T *singleton_; ///< Pointer to the instance of this object type.
    2629
    2730    protected:
     31
     32                /**
     33                 *Creates the single instance if one doesn't already exist.
     34                 */
    2835        singleton()
    2936        {
     
    3239        }
    3340
     41                /**
     42                 *Destroys the instance.
     43                 */
    3444        ~singleton()
    3545        {
     
    3949
    4050    public:
     51                /**
     52                 *Checks to see if the instance exists.
     53                 *
     54                 *@returns True if this singleton has an instance assigned, false otherwise.
     55                 */
    4156        static bool is_valid()
    4257        {
    4358            return singleton_ != 0;
    4459        }
     60
     61                /**
     62                 *Returns the pointer to the instance.
     63                 *
     64                 *@returns The pointer to the instance.
     65                 */
    4566        static T *pointer()
    4667        {
     
    4869            return singleton_;
    4970        }
     71                /**
     72                 *Returns the object referenced by this singleton.
     73                 */
    5074        static T &reference()
    5175        {
     
    5882    T* singleton<T>::singleton_ = 0;
    5983
     84
     85        /**
     86         *auto_singleton
     87         *@brief Represents a singleton that automatically creates an instance if one doesn't already exist.
     88         */
    6089    template <class T>
    6190    class auto_singleton : public singleton<T>
    6291    {
    6392    public:
     93                /**
     94                 *Returns the pointer to the instance.  Makes an instance if one doesn't already exist.
     95                 */
    6496        static T *pointer()
    6597        {
     
    70102            return singleton<T>::pointer();
    71103        }
     104
     105                /**
     106                 *Returns the object referenced by this singleton.  Makes an instance if one doesn't already exist.
     107                 */
    72108        static T &reference()
    73109        {
  • trunk/nv/uid.hh

    r59 r110  
    2222        {
    2323        public:
     24               
     25                /**
     26                 *Creates a new instance of the unique indentifer store.
     27                 */
    2428                uid_store();
     29
     30                /**
     31                 *Gets the object with the specified ID.
     32                 *
     33                 *@param auid The ID to fetch.
     34                 *@returns The stored object for that ID.
     35                 */
    2536                object* get( uid auid ) const;
     37
     38                /**
     39                 *Removes the object with the specified ID.
     40                 *
     41                 *@param auid The ID to remove.
     42                 *@returns True if the removal was successful, false if the ID didn't exist.
     43                 */
    2644                bool remove( uid auid );
     45
     46                /**
     47                 *Adds an object to the store assigned to the indicated ID.
     48                 *
     49                 *@param o The object to add to the store.
     50                 *@param auid The ID to assign to the object.
     51                 */
    2752                void insert( object* o, uid auid );
     53
     54                /**
     55                 *Adds an object to the store and assigns it a new ID.
     56                 *
     57                 *@param o The object to add to the store.
     58                 *@returns The ID the object was store under.
     59                 */
    2860                uid insert( object* o );
     61
     62                /**
     63                 *Gets the next available ID.
     64                 *
     65                 *@returns The next ID in the store.
     66                 */
    2967                uid request_uid();
     68
     69                /**
     70                 *Destroys the unique identifier store.
     71                 */
    3072                ~uid_store();
     73
     74                /**
     75                 *Retrieves an object and casts it to the specified type.
     76                 *
     77                 *@tparam T The type to cast to.
     78                 *@param auid The ID the object is stored under.
     79                 *@returns An object of the indicated type that was stored at the indicated ID.
     80                 */
    3181                template< typename T >
    3282                T* get_as( uid auid ) const
     
    3686        private:
    3787                typedef std::unordered_map< uid, object* > map;
    38                 map m_map;
    39                 uid m_current;
     88                map m_map; ///< The hash map everything is stored in.
     89                uid m_current; ///< The last UID assigned.
    4090        };
    4191}
Note: See TracChangeset for help on using the changeset viewer.