1 /***************************************************************************
2  *   Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com>          *
3  *                                                                         *
4  *   Part of the Free Heroes2 Engine:                                      *
5  *   http://sourceforge.net/projects/fheroes2                              *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21  ***************************************************************************/
22 
23 #ifndef H2INTERFACE_ICONS_H
24 #define H2INTERFACE_ICONS_H
25 
26 #include "interface_border.h"
27 #include "interface_list.h"
28 
29 enum icons_t
30 {
31     ICON_HEROES = 0x01,
32     ICON_CASTLES = 0x02,
33     ICON_ANY = ICON_HEROES | ICON_CASTLES
34 };
35 
36 namespace Interface
37 {
38     using HEROES = Heroes *;
39     using CASTLE = Castle *;
40 
41     class IconsBar
42     {
43     public:
IconsBar(u32 count,const fheroes2::Image & sf)44         IconsBar( u32 count, const fheroes2::Image & sf )
45             : marker( sf )
46             , iconsCount( count )
47             , show( true )
48         {}
49 
SetShow(bool f)50         void SetShow( bool f )
51         {
52             show = f;
53         }
54 
IsShow(void)55         bool IsShow( void ) const
56         {
57             return show;
58         }
59 
60         void RedrawBackground( const fheroes2::Point & ) const;
61 
SetIconsCount(u32 c)62         void SetIconsCount( u32 c )
63         {
64             iconsCount = c;
65         }
66 
67         static u32 GetItemWidth( void );
68         static u32 GetItemHeight( void );
69         static bool IsVisible( void );
70 
71     protected:
72         const fheroes2::Image & marker;
73         u32 iconsCount;
74         bool show;
75     };
76 
77     void RedrawHeroesIcon( const Heroes &, s32, s32 );
78     void RedrawCastleIcon( const Castle &, s32, s32 );
79 
80     class HeroesIcons : public Interface::ListBox<HEROES>, public IconsBar
81     {
82     public:
HeroesIcons(u32 count,const fheroes2::Image & sf)83         HeroesIcons( u32 count, const fheroes2::Image & sf )
84             : IconsBar( count, sf )
85         {}
86 
87         void SetPos( s32, s32 );
88         void SetShow( bool );
89 
90     protected:
91         void ActionCurrentUp( void ) override;
92         void ActionCurrentDn( void ) override;
93         void ActionListDoubleClick( HEROES & ) override;
94         void ActionListSingleClick( HEROES & ) override;
95         void ActionListPressRight( HEROES & ) override;
96         void RedrawItem( const HEROES &, s32 ox, s32 oy, bool current ) override;
97         void RedrawBackground( const fheroes2::Point & ) override;
98 
99     private:
100         fheroes2::Point _topLeftCorner;
101     };
102 
103     class CastleIcons : public Interface::ListBox<CASTLE>, public IconsBar
104     {
105     public:
CastleIcons(u32 count,const fheroes2::Image & sf)106         CastleIcons( u32 count, const fheroes2::Image & sf )
107             : IconsBar( count, sf )
108         {}
109 
110         void SetPos( s32, s32 );
111         void SetShow( bool );
112 
113     protected:
114         void ActionCurrentUp( void ) override;
115         void ActionCurrentDn( void ) override;
116         void ActionListDoubleClick( CASTLE & ) override;
117         void ActionListSingleClick( CASTLE & ) override;
118         void ActionListPressRight( CASTLE & ) override;
119         void RedrawItem( const CASTLE &, s32 ox, s32 oy, bool current ) override;
120         void RedrawBackground( const fheroes2::Point & ) override;
121 
122     private:
123         fheroes2::Point _topLeftCorner;
124     };
125 
126     class Basic;
127 
128     class IconsPanel : public BorderWindow
129     {
130     public:
131         explicit IconsPanel( Basic & );
132 
133         void SetPos( s32, s32 ) override;
134         void SavePosition( void ) override;
135         void SetRedraw( void ) const;
136         void SetRedraw( icons_t ) const;
137 
138         void Redraw( void );
139         void QueueEventProcessing( void );
140 
141         void Select( Heroes * const );
142         void Select( Castle * const );
143 
144         bool IsSelected( icons_t ) const;
145         void ResetIcons( icons_t = ICON_ANY );
146         void HideIcons( icons_t = ICON_ANY );
147         void ShowIcons( icons_t = ICON_ANY );
148         void RedrawIcons( icons_t = ICON_ANY );
149         void SetCurrentVisible( void );
150 
151     private:
152         Basic & interface;
153 
154         fheroes2::Image sfMarker;
155 
156         CastleIcons castleIcons;
157         HeroesIcons heroesIcons;
158     };
159 }
160 
161 #endif
162