1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        MenuObject.h
3 // Purpose:     The class to store a DVD Menu Object
4 // Author:      Alex Thuering
5 // Created:	04.11.2006
6 // RCS-ID:      $Id: MenuObject.h,v 1.34 2016/01/29 16:43:00 ntalex Exp $
7 // Copyright:   (c) Alex Thuering
8 // Licence:     GPL
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef MENU_OBJECT_H
12 #define MENU_OBJECT_H
13 
14 #include <src/SubStream.h>
15 #include "DVDAction.h"
16 #include "MenuObjectDef.h"
17 #include <wx/image.h>
18 #include <wx/dynarray.h>
19 #include <wxSVG/SVGLength.h>
20 #include <vector>
21 using namespace std;
22 
23 class wxSvgXmlNode;
24 class wxSVGDocument;
25 class wxSVGElement;
26 class wxSVGUseElement;
27 class wxSVGSVGElement;
28 class wxSVGImageElement;
29 class wxSVGRect;
30 class wxSVGMatrix;
31 class wxSVGTransformList;
32 class wxSVGAnimateElement;
33 class Menu;
34 class DVD;
35 
36 
37 enum NavigationButton {
38   nbLEFT = 0,
39   nbRIGHT,
40   nbUP,
41   nbDOWN
42 };
43 
44 class MenuObject: public MenuObjectDef {
45 public:
46 	/** Constructor */
47 	MenuObject(Menu* menu, bool vmg, wxString fileName = wxT(""), int x = 0, int y = 0, wxString param = wxT(""));
48 	/** Destructor */
49 	virtual ~MenuObject();
50 
51 	/** Returns id of menu object */
52 	virtual wxString GetId(bool translate = false);
53 	/** Returns true id this menu object is a button */
IsButton()54 	inline bool IsButton() { return m_button; }
55 	/** Returns button action */
GetAction()56 	inline DVDAction& GetAction() { return m_action; }
57 
58 	/** Returns true, if it's an auto-execute button. */
IsAutoExecute()59 	inline bool IsAutoExecute() { return m_autoExecute; }
60 	/** Sets, if it's an auto-execute button. */
SetAutoExecute(bool autoExecute)61 	inline void SetAutoExecute(bool autoExecute) { m_autoExecute = autoExecute; }
62 
GetFileName()63     inline wxString GetFileName() { return m_fileName; }
GetTitle()64     inline wxString GetTitle() { return m_title; }
65 
66     int GetX() const;
67     void SetX(int value);
68     int GetY() const;
69     void SetY(int value);
70     int GetWidth() const;
71     void SetWidth(int value);
72     int GetHeight() const;
73     void SetHeight(int value);
74     void SetRect(wxRect rect);
75     double GetAngle() const;
76     void SetAngle(double value);
77     wxRect GetBBox() const;
78     wxRect GetResultBBox() const;
79     wxRect GetFrameBBox(SubStreamMode mode, bool ignorePadding = false);
80 
IsDefaultSize()81 	inline bool IsDefaultSize() { return m_defaultSize; }
82 	inline void SetDefaultSize(bool value = true) { m_defaultSize = value; }
IsKeepAspectRatio()83 	inline bool IsKeepAspectRatio() { return m_keepAspectRatio; }
84 	inline void SetKeepAspectRatio(bool value = true) { m_keepAspectRatio = value; }
85     void FixSize(int& width, int& height);
86     void UpdateSize();
87     void UpdateMatrix(wxSVGMatrix& matrix) const;
88 
89     int GetChangebaleColourCount(bool drawButtonsOnBackground);
GetTextOffset()90     const wxSVGLength& GetTextOffset() const { return m_textOffset; }
91 
92     /** Returns animation elements */
93 	vector<wxSVGAnimateElement*> GetAnimations();
94 	/** Sets animation elements */
95 	void SetAnimations(vector<wxSVGAnimateElement*>& animations);
96 
97 	/** Returns true, if video frame must be displayed (if button has image parameter and "jump to title" action) */
IsDisplayVideoFrame()98 	inline bool IsDisplayVideoFrame() { return m_displayVideoFrame; }
99 	/** Sets, if video frame must be displayed */
SetDisplayVideoFrame(bool displayVideoFrame)100 	inline void SetDisplayVideoFrame(bool displayVideoFrame) { m_displayVideoFrame = displayVideoFrame; }
101 	/** Returns true, if custom video frame is selected */
IsCustomVideoFrame()102 	inline bool IsCustomVideoFrame() { return m_customVideoFrame; }
103 	/** Sets, if custom video frame is selected */
SetCustomVideoFrame(bool customVideoFrame)104 	inline void SetCustomVideoFrame(bool customVideoFrame) { m_customVideoFrame = customVideoFrame; }
105 	/** Returns VOB-ID of displayed frame */
GetDisplayVobId()106 	inline int GetDisplayVobId() { return m_displayVobId; }
107 	/** Sets VOB-ID of displayed frame */
SetDisplayVobId(int displayVobId)108 	inline void SetDisplayVobId(int displayVobId) { m_displayVobId = displayVobId; }
109 
110     void ToFront();
111     void Forward();
112     void Backward();
113     void ToBack();
114     bool IsFirst();
115     bool IsLast();
116 
GetFocusDest(NavigationButton navButton)117 	wxString GetFocusDest(NavigationButton navButton) { return m_direction[navButton]; }
SetFocusDest(NavigationButton navButton,wxString value)118 	void SetFocusDest(NavigationButton navButton, wxString value) { m_direction[navButton] = value; }
119 	wxString GetDefaultFocusDest(NavigationButton navButton);
120 
121 	/** Returns image (thumbnail) */
122 	wxImage GetImage(int maxWidth, int maxHeight);
123 
124 	virtual wxSvgXmlNode* GetXML(DVDFileType type, DVD* dvd, SubStreamMode mode = ssmNORMAL, bool withSVG = false);
125 	virtual bool PutXML(wxSvgXmlNode* node);
126 
127 protected:
128 	Menu* m_menu; // can be null
129 	wxString m_id;
130 	bool m_button;
131 	bool m_autoExecute;
132 	DVDAction m_action;
133 	wxString m_fileName;
134 
135 	wxString m_direction[4]; // left, right, up, down button names
136 
137 	bool m_displayVideoFrame; // sets if video frame must be displayed
138 	bool m_customVideoFrame; // shows if custom video frame is selected
139 	int m_displayVobId; // VOB-ID of displayed frame
140 
141 	bool m_keepAspectRatio;
142 	wxSVGImageElement* m_aspectRatioElem;
143 
144 	wxSVGUseElement* m_use;
145 	wxSVGSVGElement* m_buttonSVG;
146 	wxSVGSVGElement* AddButtonSVG(wxString id, wxSVGElement* content);
147 	void AddUseElement(wxString id, int x, int y, int width, int height, const wxSVGTransformList* transforms = NULL);
148 	virtual wxSVGSVGElement* GetButtonSVG() const;
149 
150 	void SetScale(double scaleX, double scaleY);
151 
152 	bool Init(wxString filename, int x = 0, int y = 0, wxString param = wxT(""));
153 	bool LoadSVG(wxSVGDocument& svg, wxSvgXmlNode* node);
154 	wxString GenerateId(wxString prefix);
155 	unsigned int CalcSize(MenuObjectSize& size, bool width);
156 	bool IsAlignRight(MenuObjectSize& size);
157 	void UpdateTransform();
158 };
159 
160 #endif // MENU_OBJECT_H
161