Code Search for Developers
 
 
  

StaticGraphic.h from FreeOrion at Krugle


Show StaticGraphic.h syntax highlighted

// -*- C++ -*-
/* GG is a GUI for SDL and OpenGL.
   Copyright (C) 2003 T. Zachary Laine

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   as published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.
   
   This library 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
   Lesser General Public License for more details.
    
   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA

   If you do not wish to comply with the terms of the LGPL please
   contact the author as other terms are available for a fee.
    
   Zach Laine
   whatwasthataddress@hotmail.com */

/** \file StaticGraphic.h
    Contains the StaticGraphic class, a fixed image control. */

#ifndef _GG_StaticGraphic_h_
#define _GG_StaticGraphic_h_

#include <GG/Control.h>
#include <GG/Texture.h>


namespace GG {

/** Styles for StaticGraphic controls. */
GG_FLAG_TYPE(GraphicStyle);
extern GG_API const GraphicStyle GRAPHIC_NONE;        ///< Default style selected.
extern GG_API const GraphicStyle GRAPHIC_VCENTER;     ///< Centers graphic vertically.
extern GG_API const GraphicStyle GRAPHIC_TOP;         ///< Top-justifies graphic.
extern GG_API const GraphicStyle GRAPHIC_BOTTOM;      ///< Justifies the graphic to the bottom of the rectangle.
extern GG_API const GraphicStyle GRAPHIC_CENTER;      ///< Centers graphic horizontally in the rectangle.
extern GG_API const GraphicStyle GRAPHIC_LEFT;        ///< Aligns graphic to the left.
extern GG_API const GraphicStyle GRAPHIC_RIGHT;       ///< Aligns graphic to the right.
extern GG_API const GraphicStyle GRAPHIC_FITGRAPHIC;  ///< Scales graphic to fit within the StaticGraphic's window dimensions.
extern GG_API const GraphicStyle GRAPHIC_SHRINKFIT;   ///< Like GRAPHIC_FITGRAPHIC, but this one only scales the image if it otherwise would not fit in the window.
extern GG_API const GraphicStyle GRAPHIC_PROPSCALE;   ///< If GRAPHIC_FITGRAPHIC or GRAPHIC_SHRINKFIT is used, this ensures scaling is done proportionally.


/** This is a simple, non-interactive window that displays a GG::SubTexture.  Though the SubTexture displayed in a
    StaticGraphic is fixed, its size is not; the image can be scaled (proportionately or not) to fit in the
    StaticGraphic's window area. \see StaticGraphicStyle*/
class GG_API StaticGraphic : public Control
{
public:
    /** \name Structors */ //@{
    /** creates a StaticGraphic from a pre-existing Texture.
        \warning Calling code <b>must not</b> delete \a texture; \a texture becomes the property of a shared_ptr inside 
        a SubTexture. */
    StaticGraphic(int x, int y, int w, int h, const boost::shared_ptr<Texture>& texture, Flags<GraphicStyle> style = GRAPHIC_NONE, Flags<WndFlag> flags = Flags<WndFlag>()); ///< creates a StaticGraphic from a pre-existing Texture.
    StaticGraphic(int x, int y, int w, int h, const SubTexture& subtexture, Flags<GraphicStyle> style = GRAPHIC_NONE, Flags<WndFlag> flags = Flags<WndFlag>()); ///< creates a StaticGraphic from a pre-existing SubTexture.
    //@}

    /** \name Accessors */ //@{
    /** returns the style of the StaticGraphic \see StaticGraphicStyle */
    Flags<GraphicStyle> Style() const;
    //@}

    /** \name Mutators */ //@{
    virtual void Render();

    /** sets the style flags, and perfroms sanity checking \see StaticGraphicStyle */
    void SetStyle(Flags<GraphicStyle> style);

    virtual void DefineAttributes(WndEditor* editor);
    //@}

protected:
    /** \name Structors */ //@{
    StaticGraphic(); ///< default ctor
    //@}

private:
    void     Init(const SubTexture& subtexture); ///< initializes a StaticGraphic from a SubTexture
    void     ValidateStyle();   ///< ensures that the style flags are consistent

    SubTexture          m_graphic;
    Flags<GraphicStyle> m_style;        ///< position of texture wrt the window area

    friend class boost::serialization::access;
    template <class Archive>
    void serialize(Archive& ar, const unsigned int version);
};

} // namespace GG

// template implementations
template <class Archive>
void GG::StaticGraphic::serialize(Archive& ar, const unsigned int version)
{
    ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
        & BOOST_SERIALIZATION_NVP(m_graphic)
        & BOOST_SERIALIZATION_NVP(m_style);

    if (Archive::is_loading::value)
        ValidateStyle();
}

#endif // _GG_StaticGraphic_h_




See more files for this project here

FreeOrion

FreeOrion brings nation building to a galactic scale with its full-featured grand campaign and in-game racial histories, in addition to the classic 4X model of galactic conquest and tactical combat.

Project homepage: http://sourceforge.net/projects/freeorion
Programming language(s): C,C++
License: other

  Ogre/
    OgreGUI.h
  SDL/
    SDLGUI.h
  dialogs/
    ColorDlg.h
    FileDlg.h
    ThreeButtonDlg.h
  AlignmentFlags.h
  Base.h
  BrowseInfoWnd.h
  Button.h
  Clr.h
  Control.h
  Cursor.h
  DrawUtil.h
  DropDownList.h
  DynamicGraphic.h
  Edit.h
  Enum.h
  EventPump.h
  Exception.h
  Flags.h
  Font.h
  GUI.h
  Layout.h
  ListBox.h
  Menu.h
  MultiEdit.h
  PluginInterface.h
  PtRect.h
  Scroll.h
  Signal0.h
  Signal1.h
  Signal2.h
  Signal3.h
  Signal4.h
  Signal5.h
  Signal6.h
  Signal7.h
  Signal8.h
  SignalTemplate.h
  SignalsAndSlots.h
  Slider.h
  Spin.h
  StaticGraphic.h
  StyleFactory.h
  TabWnd.h
  TextControl.h
  Texture.h
  Timer.h
  Wnd.h
  WndEditor.h
  WndEvent.h
  ZList.h
  gen_signals.py
  glext.h