Fix some memory leaks and code style issues
Maximum line length is 95 characters. Some members' name are changed. Struct initialisations use brace syntax; eliminating the usage of the memset function. Iterations use for-each-loop instead of while-loop+iterator. char * -> std::string button_info * -> std::shared_ptr<button_info>
This commit is contained in:
		
							parent
							
								
									8e09077de8
								
							
						
					
					
						commit
						3a47559e86
					
				@ -104,7 +104,7 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
 | 
				
			|||||||
	if (isMenuActive()) {
 | 
						if (isMenuActive()) {
 | 
				
			||||||
#ifdef HAVE_TOUCHSCREENGUI
 | 
					#ifdef HAVE_TOUCHSCREENGUI
 | 
				
			||||||
		if (m_touchscreengui) {
 | 
							if (m_touchscreengui) {
 | 
				
			||||||
			m_touchscreengui->Toggle(false);
 | 
								m_touchscreengui->setVisible(false);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		return g_menumgr.preprocessEvent(event);
 | 
							return g_menumgr.preprocessEvent(event);
 | 
				
			||||||
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -60,15 +60,6 @@ typedef enum
 | 
				
			|||||||
	joystick_center_id
 | 
						joystick_center_id
 | 
				
			||||||
} touch_gui_button_id;
 | 
					} touch_gui_button_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef enum
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	j_forward = 0,
 | 
					 | 
				
			||||||
	j_backward,
 | 
					 | 
				
			||||||
	j_left,
 | 
					 | 
				
			||||||
	j_right,
 | 
					 | 
				
			||||||
	j_aux1
 | 
					 | 
				
			||||||
} touch_gui_joystick_move_id;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef enum
 | 
					typedef enum
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	AHBB_Dir_Top_Bottom,
 | 
						AHBB_Dir_Top_Bottom,
 | 
				
			||||||
@ -82,24 +73,24 @@ typedef enum
 | 
				
			|||||||
#define SETTINGS_BAR_Y_OFFSET 5
 | 
					#define SETTINGS_BAR_Y_OFFSET 5
 | 
				
			||||||
#define RARE_CONTROLS_BAR_Y_OFFSET 5
 | 
					#define RARE_CONTROLS_BAR_Y_OFFSET 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Very slow button repeat frequency
 | 
					extern const std::string button_image_names[];
 | 
				
			||||||
#define SLOW_BUTTON_REPEAT 1.0f
 | 
					extern const std::string joystick_image_names[];
 | 
				
			||||||
 | 
					 | 
				
			||||||
extern const char *button_imagenames[];
 | 
					 | 
				
			||||||
extern const char *joystick_imagenames[];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct button_info
 | 
					struct button_info
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	float repeatcounter;
 | 
						float repeat_counter;
 | 
				
			||||||
	float repeatdelay;
 | 
						float repeat_delay;
 | 
				
			||||||
	irr::EKEY_CODE keycode;
 | 
						EKEY_CODE keycode;
 | 
				
			||||||
	std::vector<size_t> ids;
 | 
						std::vector<size_t> ids;
 | 
				
			||||||
	IGUIButton *guibutton = nullptr;
 | 
						IGUIButton *gui_button = nullptr;
 | 
				
			||||||
	bool immediate_release;
 | 
						bool immediate_release;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 0: false, 1: (true) first texture, 2: (true) second texture
 | 
						enum {
 | 
				
			||||||
	int togglable = 0;
 | 
							NOT_TOGGLEABLE,
 | 
				
			||||||
	std::vector<const char *> textures;
 | 
							FIRST_TEXTURE,
 | 
				
			||||||
 | 
							SECOND_TEXTURE
 | 
				
			||||||
 | 
						} toggleable = NOT_TOGGLEABLE;
 | 
				
			||||||
 | 
						std::vector<const std::string> textures;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AutoHideButtonBar
 | 
					class AutoHideButtonBar
 | 
				
			||||||
@ -107,7 +98,7 @@ class AutoHideButtonBar
 | 
				
			|||||||
public:
 | 
					public:
 | 
				
			||||||
	AutoHideButtonBar(IrrlichtDevice *device, IEventReceiver *receiver);
 | 
						AutoHideButtonBar(IrrlichtDevice *device, IEventReceiver *receiver);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void init(ISimpleTextureSource *tsrc, const char *starter_img, int button_id,
 | 
						void init(ISimpleTextureSource *tsrc, const std::string &starter_img, int button_id,
 | 
				
			||||||
			const v2s32 &UpperLeft, const v2s32 &LowerRight,
 | 
								const v2s32 &UpperLeft, const v2s32 &LowerRight,
 | 
				
			||||||
			autohide_button_bar_dir dir, float timeout);
 | 
								autohide_button_bar_dir dir, float timeout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -115,13 +106,13 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// add button to be shown
 | 
						// add button to be shown
 | 
				
			||||||
	void addButton(touch_gui_button_id id, const wchar_t *caption,
 | 
						void addButton(touch_gui_button_id id, const wchar_t *caption,
 | 
				
			||||||
			const char *btn_image);
 | 
								const std::string &btn_image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// add toggle button to be shown
 | 
						// add toggle button to be shown
 | 
				
			||||||
	void addToggleButton(touch_gui_button_id id, const wchar_t *caption,
 | 
						void addToggleButton(touch_gui_button_id id, const wchar_t *caption,
 | 
				
			||||||
			const char *btn_image_1, const char *btn_image_2);
 | 
								const std::string &btn_image_1, const std::string &btn_image_2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// detect settings bar button events
 | 
						// detect button bar button events
 | 
				
			||||||
	bool isButton(const SEvent &event);
 | 
						bool isButton(const SEvent &event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// step handler
 | 
						// step handler
 | 
				
			||||||
@ -130,13 +121,13 @@ public:
 | 
				
			|||||||
	// return whether the button bar is active
 | 
						// return whether the button bar is active
 | 
				
			||||||
	bool active() { return m_active; }
 | 
						bool active() { return m_active; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// deactivate button bar
 | 
						// deactivate the button bar
 | 
				
			||||||
	void deactivate();
 | 
						void deactivate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// hide the whole buttonbar
 | 
						// hide the whole button bar
 | 
				
			||||||
	void hide();
 | 
						void hide();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// unhide the buttonbar
 | 
						// unhide the button bar
 | 
				
			||||||
	void show();
 | 
						void show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
@ -145,17 +136,16 @@ private:
 | 
				
			|||||||
	IGUIEnvironment *m_guienv;
 | 
						IGUIEnvironment *m_guienv;
 | 
				
			||||||
	IEventReceiver *m_receiver;
 | 
						IEventReceiver *m_receiver;
 | 
				
			||||||
	button_info m_starter;
 | 
						button_info m_starter;
 | 
				
			||||||
	std::vector<button_info *> m_buttons;
 | 
						std::vector<std::shared_ptr<button_info>> m_buttons;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v2s32 m_upper_left;
 | 
						v2s32 m_upper_left;
 | 
				
			||||||
	v2s32 m_lower_right;
 | 
						v2s32 m_lower_right;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// show settings bar
 | 
						// show button bar
 | 
				
			||||||
	bool m_active = false;
 | 
						bool m_active = false;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	bool m_visible = true;
 | 
						bool m_visible = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// settings bar timeout
 | 
						// button bar timeout
 | 
				
			||||||
	float m_timeout = 0.0f;
 | 
						float m_timeout = 0.0f;
 | 
				
			||||||
	float m_timeout_value = 3.0f;
 | 
						float m_timeout_value = 3.0f;
 | 
				
			||||||
	bool m_initialized = false;
 | 
						bool m_initialized = false;
 | 
				
			||||||
@ -181,7 +171,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	double getPitch() { return m_camera_pitch; }
 | 
						double getPitch() { return m_camera_pitch; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * Returns a line which describes what the player is pointing at.
 | 
						 * Returns a line which describes what the player is pointing at.
 | 
				
			||||||
	 * The starting point and looking direction are significant,
 | 
						 * The starting point and looking direction are significant,
 | 
				
			||||||
	 * the line should be scaled to match its length to the actual distance
 | 
						 * the line should be scaled to match its length to the actual distance
 | 
				
			||||||
@ -198,8 +188,8 @@ public:
 | 
				
			|||||||
	void resetHud();
 | 
						void resetHud();
 | 
				
			||||||
	void registerHudItem(int index, const rect<s32> &rect);
 | 
						void registerHudItem(int index, const rect<s32> &rect);
 | 
				
			||||||
	inline void setUseCrosshair(bool use_crosshair) { m_draw_crosshair = use_crosshair; }
 | 
						inline void setUseCrosshair(bool use_crosshair) { m_draw_crosshair = use_crosshair; }
 | 
				
			||||||
	void Toggle(bool visible);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void setVisible(bool visible);
 | 
				
			||||||
	void hide();
 | 
						void hide();
 | 
				
			||||||
	void show();
 | 
						void show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -213,16 +203,15 @@ private:
 | 
				
			|||||||
	s32 button_size;
 | 
						s32 button_size;
 | 
				
			||||||
	double m_touchscreen_threshold;
 | 
						double m_touchscreen_threshold;
 | 
				
			||||||
	std::map<int, rect<s32>> m_hud_rects;
 | 
						std::map<int, rect<s32>> m_hud_rects;
 | 
				
			||||||
	std::map<size_t, irr::EKEY_CODE> m_hud_ids;
 | 
						std::map<size_t, EKEY_CODE> m_hud_ids;
 | 
				
			||||||
	bool m_visible; // is the gui visible
 | 
						bool m_visible; // is the whole touch screen gui visible
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// value in degree
 | 
						// value in degree
 | 
				
			||||||
	double m_camera_yaw_change = 0.0;
 | 
						double m_camera_yaw_change = 0.0;
 | 
				
			||||||
	double m_camera_pitch = 0.0;
 | 
						double m_camera_pitch = 0.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * A line starting at the camera and pointing towards the
 | 
						 * A line starting at the camera and pointing towards the selected object.
 | 
				
			||||||
	 * selected object.
 | 
					 | 
				
			||||||
	 * The line ends on the camera's far plane.
 | 
						 * The line ends on the camera's far plane.
 | 
				
			||||||
	 * The coordinates do not contain the camera offset.
 | 
						 * The coordinates do not contain the camera offset.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@ -244,9 +233,9 @@ private:
 | 
				
			|||||||
	bool m_fixed_joystick = false;
 | 
						bool m_fixed_joystick = false;
 | 
				
			||||||
	bool m_joystick_triggers_aux1 = false;
 | 
						bool m_joystick_triggers_aux1 = false;
 | 
				
			||||||
	bool m_draw_crosshair = false;
 | 
						bool m_draw_crosshair = false;
 | 
				
			||||||
	button_info *m_joystick_btn_off = nullptr;
 | 
						std::shared_ptr<button_info> m_joystick_btn_off = nullptr;
 | 
				
			||||||
	button_info *m_joystick_btn_bg = nullptr;
 | 
						std::shared_ptr<button_info> m_joystick_btn_bg = nullptr;
 | 
				
			||||||
	button_info *m_joystick_btn_center = nullptr;
 | 
						std::shared_ptr<button_info> m_joystick_btn_center = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	button_info m_buttons[after_last_element_id];
 | 
						button_info m_buttons[after_last_element_id];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -265,7 +254,7 @@ private:
 | 
				
			|||||||
			float repeat_delay = BUTTON_REPEAT_DELAY);
 | 
								float repeat_delay = BUTTON_REPEAT_DELAY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// initialize a joystick button
 | 
						// initialize a joystick button
 | 
				
			||||||
	button_info *initJoystickButton(touch_gui_button_id id,
 | 
						std::shared_ptr<button_info> initJoystickButton(touch_gui_button_id id,
 | 
				
			||||||
			const rect<s32> &button_rect, int texture_id,
 | 
								const rect<s32> &button_rect, int texture_id,
 | 
				
			||||||
			bool visible = true);
 | 
								bool visible = true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -295,13 +284,13 @@ private:
 | 
				
			|||||||
	void applyJoystickStatus();
 | 
						void applyJoystickStatus();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// array for saving last known position of a pointer
 | 
						// array for saving last known position of a pointer
 | 
				
			||||||
	std::map<size_t, v2s32> m_pointerpos;
 | 
						std::map<size_t, v2s32> m_pointer_pos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// settings bar
 | 
						// settings bar
 | 
				
			||||||
	AutoHideButtonBar m_settingsbar;
 | 
						AutoHideButtonBar m_settings_bar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// rare controls bar
 | 
						// rare controls bar
 | 
				
			||||||
	AutoHideButtonBar m_rarecontrolsbar;
 | 
						AutoHideButtonBar m_rare_controls_bar;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern TouchScreenGUI *g_touchscreengui;
 | 
					extern TouchScreenGUI *g_touchscreengui;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user