00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include <SDL.h>
00024
#include "guitypedefs.h"
00025
#include "guicolors.h"
00026
#ifdef _WIN32
00027
#pragma warning(push)
00028
00029
#include <yvals.h>
00030
00031
#pragma warning(disable: 4251)
00032
#pragma warning(disable: 4786) // identifier was truncated to 'number' characters in the debug information
00033
00034
00035
00036
00037
00038
#include <sge.h>
00039
00040
#pragma warning(pop)
00041
#else
00042
#include <sge.h>
00043
#endif
00044
00045
#include "TTFont.h"
00046
#include "Surface.h"
00047
#include "Hotspot.h"
00048
#include "MenuItem.h"
00049
#include "Menu.h"
00050
00051
00052
namespace gui
00053 {
00054
00055
00056 Menu::Menu(
Surface *s,
SurfaceHelper *pclHelper)
00057 :
Surface(s,pclHelper)
00058 ,m_w(0)
00059 ,m_h(0)
00060 ,m_pclSubMenu(NULL)
00061 {
00062 SetFrameWidth(
DIALOG_DEFAULT_FW);
00063 }
00064
00065
00066 Menu::~Menu()
00067 {
00068 }
00069
00070
00071 void Menu::AddMenuItem(
MenuItem *pclItem)
00072 {
00073
m_w = pclItem ->
GetW() >
m_w ? pclItem ->
GetW() :
m_w;
00074 pclItem -> SetY(
m_h);
00075
m_h += pclItem ->
GetH();
00076
00077
00078 AddChild(pclItem);
00079 }
00080
00081
00082 void Menu::CreateMenu()
00083 {
00084 surfacevector_t::iterator it;
00085
int fw =
GetFrameWidth();
00086
00087
for (it = m_ChildList.begin(); it != m_ChildList.end(); it++)
00088 {
00089
MenuItem *pclItem = static_cast<MenuItem *>(*it);
00090 pclItem -> SetW(
m_w);
00091 pclItem -> CreateMenuItem();
00092 }
00093
00094 SetW(
m_w + fw * 2);
00095 SetH(
m_h + fw * 2);
00096
00097
RecreateSurfaces();
00098
00099
00100
00101 SetBgColor(
DIALOG_DEFAULT_BG_R,
DIALOG_DEFAULT_BG_G,
DIALOG_DEFAULT_BG_B);
00102 SetFrameColor(
DIALOG_DEFAULT_FC_R,
DIALOG_DEFAULT_FC_G,
DIALOG_DEFAULT_FC_B);
00103 }
00104
00105
00106 void Menu::Draw()
00107 {
00108 SDL_Rect *area =
GetClientRectPtr();
00109 Uint32 color =
GetBgColor();
00110
00111 SDL_FillRect(m_screen, area, color);
00112 }
00113
00114
00115 void Menu::OnRightClick(coord_t x,coord_t y)
00116 {
00117
Surface *head =
this;
00118
00119
while (head ->
GetBond())
00120 {
00121 head = head ->
GetBond();
00122 }
00123 head ->
CloseAll();
00124 head ->
RemoveAllBonds();
00125 }
00126
00127
00128 void Menu::ActivateSubMenu(
Menu *pclMenu,coord_t x,coord_t y)
00129 {
00130
if (
m_pclSubMenu &&
m_pclSubMenu ->
IsVisible())
00131 {
00132 SDL_Rect a =
m_pclSubMenu ->
GetAbsoluteRect();
00133 InvalidateRectEv(a);
00134
m_pclSubMenu -> SetVisible(
false);
00135 Unbond(
m_pclSubMenu);
00136 }
00137
m_pclSubMenu = pclMenu;
00138
m_pclSubMenu -> SetX(x);
00139
m_pclSubMenu -> SetY(y);
00140
GetParent() ->
CalculateAbsolute();
00141
m_pclSubMenu -> SetVisible(
true);
00142
m_pclSubMenu -> SetDirty(
true);
00143
m_pclSubMenu ->
InvalidateEv();
00144 Bond(
m_pclSubMenu);
00145 }
00146
00147
00148 Menu *Menu::GetSubMenu(
int id)
00149 {
00150
return NULL;
00151 }
00152
00153
00154 }