Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
TouchControls Class Reference

#include <touchcontrols.h>

+ Collaboration diagram for TouchControls:

Public Member Functions

 TouchControls (IrrlichtDevice *device, ISimpleTextureSource *tsrc)
 
 ~TouchControls ()
 
 DISABLE_CLASS_COPY (TouchControls)
 
void translateEvent (const SEvent &event)
 
void applyContextControls (const TouchInteractionMode &mode)
 
double getYawChange ()
 
double getPitchChange ()
 
line3d< f32 > getShootline ()
 Returns a line which describes what the player is pointing at.
 
float getJoystickDirection ()
 
float getJoystickSpeed ()
 
void step (float dtime)
 
void setUseCrosshair (bool use_crosshair)
 
void setVisible (bool visible)
 
void hide ()
 
void show ()
 
void resetHotbarRects ()
 
void registerHotbarRect (u16 index, const recti &rect)
 
std::optional< u16 > getHotbarSelection ()
 
bool isStatusTextOverriden ()
 
IGUIStaticText * getStatusText ()
 

Private Member Functions

void toggleOverflowMenu ()
 
void updateVisibility ()
 
void releaseAll ()
 
void addButton (std::vector< button_info > &buttons, touch_gui_button_id id, const std::string &image, const recti &rect, bool visible=true)
 
void addToggleButton (std::vector< button_info > &buttons, touch_gui_button_id id, const std::string &image_1, const std::string &image_2, const recti &rect, bool visible=true)
 
IGUIImage * makeButtonDirect (touch_gui_button_id id, const recti &rect, bool visible)
 
bool isHotbarButton (const SEvent &event)
 
void handleReleaseEvent (size_t pointer_id)
 
void applyJoystickStatus ()
 
v2s32 getPointerPos ()
 
void emitMouseEvent (EMOUSE_INPUT_EVENT type)
 

Private Attributes

IrrlichtDevice * m_device = nullptr
 
IGUIEnvironment * m_guienv = nullptr
 
IEventReceiver * m_receiver = nullptr
 
ISimpleTextureSourcem_texturesource = nullptr
 
v2u32 m_screensize
 
s32 m_button_size
 
double m_touchscreen_threshold
 
u16 m_long_tap_delay
 
bool m_visible = true
 
std::unordered_map< u16, recti > m_hotbar_rects
 
std::optional< u16 > m_hotbar_selection = std::nullopt
 
double m_camera_yaw_change = 0.0
 
double m_camera_pitch_change = 0.0
 
line3d< f32 > m_shootline
 A line starting at the camera and pointing towards the selected object.
 
bool m_has_move_id = false
 
size_t m_move_id
 
bool m_move_has_really_moved = false
 
u64 m_move_downtime = 0
 
v2s32 m_move_pos
 
bool m_had_move_id = false
 
bool m_move_prevent_short_tap = false
 
bool m_has_joystick_id = false
 
size_t m_joystick_id
 
bool m_joystick_has_really_moved = false
 
float m_joystick_direction = 0.0f
 
float m_joystick_speed = 0.0f
 
bool m_joystick_status_aux1 = false
 
bool m_fixed_joystick = false
 
bool m_joystick_triggers_aux1 = false
 
bool m_draw_crosshair = false
 
std::shared_ptr< IGUIImage > m_joystick_btn_off
 
std::shared_ptr< IGUIImage > m_joystick_btn_bg
 
std::shared_ptr< IGUIImage > m_joystick_btn_center
 
std::vector< button_infom_buttons
 
std::shared_ptr< IGUIImage > m_overflow_btn
 
bool m_overflow_open = false
 
std::shared_ptr< IGUIStaticText > m_overflow_bg
 
std::vector< button_infom_overflow_buttons
 
std::vector< std::shared_ptr< IGUIStaticText > > m_overflow_button_titles
 
std::vector< recti > m_overflow_button_rects
 
std::shared_ptr< IGUIStaticText > m_status_text
 
std::unordered_map< size_t, v2s32m_pointer_downpos
 
std::unordered_map< size_t, v2s32m_pointer_pos
 
TouchInteractionMode m_last_mode = TouchInteractionMode_END
 
TapState m_tap_state = TapState::None
 
bool m_dig_pressed = false
 
u64 m_dig_pressed_until = 0
 
bool m_place_pressed = false
 
u64 m_place_pressed_until = 0
 

Constructor & Destructor Documentation

◆ TouchControls()

◆ ~TouchControls()

TouchControls::~TouchControls ( )

References releaseAll().

+ Here is the call graph for this function:

Member Function Documentation

◆ addButton()

void TouchControls::addButton ( std::vector< button_info > & buttons,
touch_gui_button_id id,
const std::string & image,
const recti & rect,
bool visible = true )
private

References grab_gui_element(), button_info::gui_button, id_to_keycode(), button_info::keycode, load_button_texture(), m_device, m_guienv, and m_texturesource.

Referenced by TouchControls(), and addToggleButton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addToggleButton()

void TouchControls::addToggleButton ( std::vector< button_info > & buttons,
touch_gui_button_id id,
const std::string & image_1,
const std::string & image_2,
const recti & rect,
bool visible = true )
private

References addButton(), button_info::FIRST_TEXTURE, button_info::toggle_textures, and button_info::toggleable.

Referenced by TouchControls().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyContextControls()

void TouchControls::applyContextControls ( const TouchInteractionMode & mode)

References emitMouseEvent(), porting::getTimeMs(), LongTap, m_dig_pressed, m_dig_pressed_until, m_last_mode, m_place_pressed, m_place_pressed_until, m_tap_state, None, sanity_check, SHORT_DIG_LONG_PLACE, ShortTap, SIMULATED_CLICK_DURATION_MS, and TouchInteractionMode_USER.

Referenced by Game::processPlayerInteraction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyJoystickStatus()

void TouchControls::applyJoystickStatus ( )
private

References aux1_id, id_to_keycode(), m_joystick_status_aux1, m_joystick_triggers_aux1, and m_receiver.

Referenced by handleReleaseEvent(), and step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DISABLE_CLASS_COPY()

TouchControls::DISABLE_CLASS_COPY ( TouchControls )

◆ emitMouseEvent()

void TouchControls::emitMouseEvent ( EMOUSE_INPUT_EVENT type)
private

References getPointerPos(), and m_receiver.

Referenced by applyContextControls(), and releaseAll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHotbarSelection()

std::optional< u16 > TouchControls::getHotbarSelection ( )

References m_hotbar_selection.

Referenced by Game::processItemSelection().

+ Here is the caller graph for this function:

◆ getJoystickDirection()

float TouchControls::getJoystickDirection ( )
inline

References m_joystick_direction.

Referenced by RealInputHandler::getJoystickDirection().

+ Here is the caller graph for this function:

◆ getJoystickSpeed()

float TouchControls::getJoystickSpeed ( )
inline

References m_joystick_speed.

Referenced by RealInputHandler::getJoystickDirection(), and RealInputHandler::getJoystickSpeed().

+ Here is the caller graph for this function:

◆ getPitchChange()

double TouchControls::getPitchChange ( )
inline

References m_camera_pitch_change.

Referenced by Game::updateCameraOrientation().

+ Here is the caller graph for this function:

◆ getPointerPos()

v2s32 TouchControls::getPointerPos ( )
private

References m_draw_crosshair, m_move_pos, and m_screensize.

Referenced by emitMouseEvent(), and step().

+ Here is the caller graph for this function:

◆ getShootline()

line3d< f32 > TouchControls::getShootline ( )
inline

Returns a line which describes what the player is pointing at.

The starting point and looking direction are significant, the line should be scaled to match its length to the actual distance the player can reach. The line starts at the camera and ends on the camera's far plane. The coordinates do not contain the camera offset.

References m_shootline.

Referenced by Game::processPlayerInteraction().

+ Here is the caller graph for this function:

◆ getStatusText()

IGUIStaticText * TouchControls::getStatusText ( )
inline

References m_status_text.

Referenced by GameUI::update().

+ Here is the caller graph for this function:

◆ getYawChange()

double TouchControls::getYawChange ( )
inline

References m_camera_yaw_change.

Referenced by Game::updateCameraOrientation().

+ Here is the caller graph for this function:

◆ handleReleaseEvent()

void TouchControls::handleReleaseEvent ( size_t pointer_id)
private

References applyJoystickStatus(), buttons_handleRelease(), infostream, LongTap, m_buttons, m_device, m_has_joystick_id, m_has_move_id, m_joystick_direction, m_joystick_id, m_joystick_speed, m_joystick_status_aux1, m_move_has_really_moved, m_move_id, m_move_prevent_short_tap, m_overflow_buttons, m_pointer_downpos, m_pointer_pos, m_receiver, m_tap_state, m_texturesource, None, ShortTap, and updateVisibility().

Referenced by releaseAll(), and translateEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hide()

void TouchControls::hide ( )

References setVisible().

Referenced by Game::processUserInput(), and Game::shutdown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isHotbarButton()

bool TouchControls::isHotbarButton ( const SEvent & event)
private

References m_hotbar_rects, and m_hotbar_selection.

Referenced by translateEvent().

+ Here is the caller graph for this function:

◆ isStatusTextOverriden()

bool TouchControls::isStatusTextOverriden ( )
inline

References m_overflow_open.

Referenced by GameUI::update().

+ Here is the caller graph for this function:

◆ makeButtonDirect()

IGUIImage * TouchControls::makeButtonDirect ( touch_gui_button_id id,
const recti & rect,
bool visible )
private

References button_image_names, load_button_texture(), m_device, m_guienv, and m_texturesource.

Referenced by TouchControls().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerHotbarRect()

void TouchControls::registerHotbarRect ( u16 index,
const recti & rect )

References m_hotbar_rects.

Referenced by Hud::drawItems().

+ Here is the caller graph for this function:

◆ releaseAll()

void TouchControls::releaseAll ( )
private

References emitMouseEvent(), handleReleaseEvent(), m_dig_pressed, m_place_pressed, and m_pointer_pos.

Referenced by ~TouchControls(), and setVisible().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetHotbarRects()

void TouchControls::resetHotbarRects ( )

References m_hotbar_rects.

Referenced by Hud::drawHotbar().

+ Here is the caller graph for this function:

◆ setUseCrosshair()

void TouchControls::setUseCrosshair ( bool use_crosshair)
inline

References m_draw_crosshair.

Referenced by Game::initGui(), and Game::updateCamera().

+ Here is the caller graph for this function:

◆ setVisible()

void TouchControls::setVisible ( bool visible)

References m_overflow_open, m_visible, releaseAll(), and updateVisibility().

Referenced by hide(), MyEventReceiver::OnEvent(), and show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ show()

void TouchControls::show ( )

References setVisible().

Referenced by Game::processUserInput(), and GUIModalMenu::quitMenu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ step()

void TouchControls::step ( float dtime)

References applyJoystickStatus(), buttons_step(), porting::getDeltaMs(), getPointerPos(), porting::getTimeMs(), LongTap, m_buttons, m_device, m_draw_crosshair, m_had_move_id, m_has_move_id, m_long_tap_delay, m_move_downtime, m_move_has_really_moved, m_overflow_buttons, m_receiver, m_shootline, m_tap_state, m_texturesource, and None.

Referenced by Game::processUserInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toggleOverflowMenu()

void TouchControls::toggleOverflowMenu ( )
private

References m_overflow_open, and updateVisibility().

Referenced by translateEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translateEvent()

◆ updateVisibility()

void TouchControls::updateVisibility ( )
private

References m_buttons, m_has_joystick_id, m_joystick_btn_bg, m_joystick_btn_center, m_joystick_btn_off, m_overflow_bg, m_overflow_btn, m_overflow_button_titles, m_overflow_buttons, m_overflow_open, and m_visible.

Referenced by handleReleaseEvent(), setVisible(), toggleOverflowMenu(), and translateEvent().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_button_size

s32 TouchControls::m_button_size
private

Referenced by TouchControls(), and translateEvent().

◆ m_buttons

std::vector<button_info> TouchControls::m_buttons
private

◆ m_camera_pitch_change

double TouchControls::m_camera_pitch_change = 0.0
private

Referenced by getPitchChange(), and translateEvent().

◆ m_camera_yaw_change

double TouchControls::m_camera_yaw_change = 0.0
private

Referenced by getYawChange(), and translateEvent().

◆ m_device

IrrlichtDevice* TouchControls::m_device = nullptr
private

◆ m_dig_pressed

bool TouchControls::m_dig_pressed = false
private

Referenced by applyContextControls(), and releaseAll().

◆ m_dig_pressed_until

u64 TouchControls::m_dig_pressed_until = 0
private

Referenced by applyContextControls().

◆ m_draw_crosshair

bool TouchControls::m_draw_crosshair = false
private

◆ m_fixed_joystick

bool TouchControls::m_fixed_joystick = false
private

Referenced by TouchControls(), and translateEvent().

◆ m_guienv

IGUIEnvironment* TouchControls::m_guienv = nullptr
private

◆ m_had_move_id

bool TouchControls::m_had_move_id = false
private

Referenced by step(), and translateEvent().

◆ m_has_joystick_id

bool TouchControls::m_has_joystick_id = false
private

◆ m_has_move_id

bool TouchControls::m_has_move_id = false
private

◆ m_hotbar_rects

std::unordered_map<u16, recti> TouchControls::m_hotbar_rects
private

◆ m_hotbar_selection

std::optional<u16> TouchControls::m_hotbar_selection = std::nullopt
private

◆ m_joystick_btn_bg

std::shared_ptr<IGUIImage> TouchControls::m_joystick_btn_bg
private

◆ m_joystick_btn_center

std::shared_ptr<IGUIImage> TouchControls::m_joystick_btn_center
private

◆ m_joystick_btn_off

std::shared_ptr<IGUIImage> TouchControls::m_joystick_btn_off
private

Referenced by TouchControls(), and updateVisibility().

◆ m_joystick_direction

float TouchControls::m_joystick_direction = 0.0f
private

◆ m_joystick_has_really_moved

bool TouchControls::m_joystick_has_really_moved = false
private

Referenced by translateEvent().

◆ m_joystick_id

size_t TouchControls::m_joystick_id
private

◆ m_joystick_speed

float TouchControls::m_joystick_speed = 0.0f
private

◆ m_joystick_status_aux1

bool TouchControls::m_joystick_status_aux1 = false
private

◆ m_joystick_triggers_aux1

bool TouchControls::m_joystick_triggers_aux1 = false
private

◆ m_last_mode

TouchInteractionMode TouchControls::m_last_mode = TouchInteractionMode_END
private

Referenced by applyContextControls().

◆ m_long_tap_delay

u16 TouchControls::m_long_tap_delay
private

Referenced by TouchControls(), and step().

◆ m_move_downtime

u64 TouchControls::m_move_downtime = 0
private

Referenced by step(), and translateEvent().

◆ m_move_has_really_moved

bool TouchControls::m_move_has_really_moved = false
private

◆ m_move_id

size_t TouchControls::m_move_id
private

◆ m_move_pos

v2s32 TouchControls::m_move_pos
private

Referenced by getPointerPos(), and translateEvent().

◆ m_move_prevent_short_tap

bool TouchControls::m_move_prevent_short_tap = false
private

◆ m_overflow_bg

std::shared_ptr<IGUIStaticText> TouchControls::m_overflow_bg
private

Referenced by TouchControls(), and updateVisibility().

◆ m_overflow_btn

std::shared_ptr<IGUIImage> TouchControls::m_overflow_btn
private

◆ m_overflow_button_rects

std::vector<recti> TouchControls::m_overflow_button_rects
private

Referenced by TouchControls(), and translateEvent().

◆ m_overflow_button_titles

std::vector<std::shared_ptr<IGUIStaticText> > TouchControls::m_overflow_button_titles
private

Referenced by TouchControls(), and updateVisibility().

◆ m_overflow_buttons

std::vector<button_info> TouchControls::m_overflow_buttons
private

◆ m_overflow_open

bool TouchControls::m_overflow_open = false
private

◆ m_place_pressed

bool TouchControls::m_place_pressed = false
private

Referenced by applyContextControls(), and releaseAll().

◆ m_place_pressed_until

u64 TouchControls::m_place_pressed_until = 0
private

Referenced by applyContextControls().

◆ m_pointer_downpos

std::unordered_map<size_t, v2s32> TouchControls::m_pointer_downpos
private

◆ m_pointer_pos

std::unordered_map<size_t, v2s32> TouchControls::m_pointer_pos
private

◆ m_receiver

IEventReceiver* TouchControls::m_receiver = nullptr
private

◆ m_screensize

v2u32 TouchControls::m_screensize
private

◆ m_shootline

line3d<f32> TouchControls::m_shootline
private

A line starting at the camera and pointing towards the selected object.

The line ends on the camera's far plane. The coordinates do not contain the camera offset.

Referenced by getShootline(), and step().

◆ m_status_text

std::shared_ptr<IGUIStaticText> TouchControls::m_status_text
private

Referenced by TouchControls(), and getStatusText().

◆ m_tap_state

TapState TouchControls::m_tap_state = TapState::None
private

◆ m_texturesource

ISimpleTextureSource* TouchControls::m_texturesource = nullptr
private

◆ m_touchscreen_threshold

double TouchControls::m_touchscreen_threshold
private

Referenced by TouchControls(), and translateEvent().

◆ m_visible

bool TouchControls::m_visible = true
private

The documentation for this class was generated from the following files: