using namespace irr::core;
-const char **touchgui_button_imagenames = (const char*[]) {
+const char **touchgui_button_imagenames = (const char *[]) {
"jump_btn.png",
- "down.png"
+ "down.png",
+ "zoom.png"
};
const char **touchgui_joystick_imagenames = (const char *[]) {
case crunch_id:
key = "sneak";
break;
+ case zoom_id:
+ key = "zoom";
+ break;
case fly_id:
key = "freemove";
break;
case debug_id:
key = "toggle_debug";
break;
+ case toggle_chat_id:
+ key = "toggle_chat";
+ break;
+ case minimap_id:
+ key = "minimap";
+ break;
case chat_id:
key = "chat";
break;
TouchScreenGUI *g_touchscreengui;
-static void load_button_texture(button_info* btn, const char* path,
- rect<s32> button_rect, ISimpleTextureSource* tsrc, video::IVideoDriver *driver)
+static void load_button_texture(button_info *btn, const char *path,
+ rect<s32> button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver)
{
unsigned int tid;
video::ITexture *texture = guiScalingImageButton(driver,
}
AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device,
- IEventReceiver* receiver) :
+ IEventReceiver *receiver) :
m_driver(device->getVideoDriver()),
m_guienv(device->getGUIEnvironment()),
m_receiver(receiver)
{
}
-void AutoHideButtonBar::init(ISimpleTextureSource* tsrc,
- const char* starter_img, int button_id, v2s32 UpperLeft,
+void AutoHideButtonBar::init(ISimpleTextureSource *tsrc,
+ const char *starter_img, int button_id, v2s32 UpperLeft,
v2s32 LowerRight, autohide_button_bar_dir dir, float timeout)
{
m_texturesource = tsrc;
}
void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
- const wchar_t* caption, const char* btn_image)
+ const wchar_t *caption, const char *btn_image)
{
if (!m_initialized) {
y_end);
}
- button_info* btn = new button_info();
+ button_info *btn = new button_info();
btn->guibutton = m_guienv->addButton(current_button, 0, button_id, caption, 0);
btn->guibutton->grab();
btn->guibutton->setVisible(false);
m_buttons.push_back(btn);
}
+void AutoHideButtonBar::addToggleButton(touch_gui_button_id button_id,
+ const wchar_t *caption, const char *btn_image_1,
+ const char *btn_image_2)
+{
+ addButton(button_id, caption, btn_image_1);
+ button_info *btn = m_buttons.back();
+ btn->togglable = 1;
+ btn->textures.push_back(btn_image_1);
+ btn->textures.push_back(btn_image_2);
+}
+
bool AutoHideButtonBar::isButton(const SEvent &event)
{
- IGUIElement* rootguielement = m_guienv->getRootGUIElement();
+ IGUIElement *rootguielement = m_guienv->getRootGUIElement();
if (rootguielement == NULL) {
return false;
if (m_active) {
// check for all buttons in vector
- std::vector<button_info*>::iterator iter = m_buttons.begin();
+ std::vector<button_info *>::iterator iter = m_buttons.begin();
while (iter != m_buttons.end()) {
if ((*iter)->guibutton == element) {
- SEvent* translated = new SEvent();
+ SEvent *translated = new SEvent();
memset(translated, 0, sizeof(SEvent));
translated->EventType = irr::EET_KEY_INPUT_EVENT;
translated->KeyInput.Key = (*iter)->keycode;
m_timeout = 0;
+ if ((*iter)->togglable == 1) {
+ (*iter)->togglable = 2;
+ load_button_texture(*iter, (*iter)->textures[1],
+ (*iter)->guibutton->getRelativePosition(),
+ m_texturesource, m_driver);
+ } else if ((*iter)->togglable == 2) {
+ (*iter)->togglable = 1;
+ load_button_texture(*iter, (*iter)->textures[0],
+ (*iter)->guibutton->getRelativePosition(),
+ m_texturesource, m_driver);
+ }
+
return true;
}
++iter;
return true;
}
- std::vector<button_info*>::iterator iter = m_buttons.begin();
+ std::vector<button_info *>::iterator iter = m_buttons.begin();
while (iter != m_buttons.end()) {
std::vector<int>::iterator id = std::find((*iter)->ids.begin(),
}
m_active = false;
- std::vector<button_info*>::iterator iter = m_buttons.begin();
+ std::vector<button_info *>::iterator iter = m_buttons.begin();
while (iter != m_buttons.end()) {
(*iter)->guibutton->setVisible(false);
m_starter.guibutton->setVisible(false);
m_starter.guibutton->setEnabled(false);
- std::vector<button_info*>::iterator iter = m_buttons.begin();
+ std::vector<button_info *>::iterator iter = m_buttons.begin();
while (iter != m_buttons.end()) {
(*iter)->guibutton->setVisible(false);
m_visible = true;
if (m_active) {
- std::vector<button_info*>::iterator iter = m_buttons.begin();
+ std::vector<button_info *>::iterator iter = m_buttons.begin();
while (iter != m_buttons.end()) {
(*iter)->guibutton->setVisible(true);
}
}
-TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver):
+TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver):
m_device(device),
m_guienv(device->getGUIEnvironment()),
m_receiver(receiver),
std::wstring caption, bool immediate_release, float repeat_delay)
{
- button_info* btn = &m_buttons[id];
+ button_info *btn = &m_buttons[id];
btn->guibutton = m_guienv->addButton(button_rect, 0, id, caption.c_str());
btn->guibutton->grab();
btn->repeatcounter = -1;
btn->immediate_release = immediate_release;
btn->ids.clear();
- load_button_texture(btn,touchgui_button_imagenames[id],button_rect,
+ load_button_texture(btn, touchgui_button_imagenames[id], button_rect,
m_texturesource, m_device->getVideoDriver());
}
return control_pad_size / 3;
}
-void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
+void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
{
assert(tsrc);
// init jump button
initButton(jump_id,
- rect<s32>(m_screensize.X-(1.75*button_size),
- m_screensize.Y - (0.5*button_size),
- m_screensize.X-(0.25*button_size),
- m_screensize.Y),
- L"x",false);
+ rect<s32>(m_screensize.X - (1.75 * button_size),
+ m_screensize.Y - button_size,
+ m_screensize.X - (0.25 * button_size),
+ m_screensize.Y - (0.5 * button_size)),
+ L"x", false);
// init crunch button
initButton(crunch_id,
- rect<s32>(m_screensize.X-(3.25*button_size),
- m_screensize.Y - (0.5*button_size),
- m_screensize.X-(1.75*button_size),
- m_screensize.Y),
- L"H",false);
+ rect<s32>(m_screensize.X - (3.25 * button_size),
+ m_screensize.Y - button_size,
+ m_screensize.X - (1.75 * button_size),
+ m_screensize.Y - (0.5 * button_size)),
+ L"H", false);
+
+ // init zoom button
+ initButton(zoom_id,
+ rect<s32>(m_screensize.X - (1.25 * button_size),
+ m_screensize.Y - (3 * button_size),
+ m_screensize.X - (0.25 * button_size),
+ m_screensize.Y - (2 * button_size)),
+ L"z", false);
m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id,
v2s32(m_screensize.X - (button_size / 2),
+ (button_size * 0.5)), AHBB_Dir_Right_Left,
3.0);
- m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png");
- m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png");
- m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png");
- m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png");
- m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png");
- m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png");
+ m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png");
+ m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png");
+ m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png");
+ m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png");
+ m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png");
+ m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png");
+ m_settingsbar.addButton(minimap_id, L"minimap", "minimap_btn.png");
+
+ // Chat is shown by default, so chat_hide_btn.png is shown first.
+ m_settingsbar.addToggleButton(toggle_chat_id, L"togglechat",
+ "chat_hide_btn.png", "chat_show_btn.png");
m_rarecontrolsbar.init(m_texturesource, "rare_controls.png",
rare_controls_starter_id,
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
{
- IGUIElement* rootguielement = m_guienv->getRootGUIElement();
+ IGUIElement *rootguielement = m_guienv->getRootGUIElement();
if (rootguielement != NULL) {
gui::IGUIElement *element =
- rootguielement->getElementFromPoint(core::position2d<s32>(x,y));
+ rootguielement->getElementFromPoint(core::position2d<s32>(x, y));
if (element) {
for (unsigned int i=0; i < after_last_element_id; i++) {
touch_gui_button_id TouchScreenGUI::getButtonID(int eventID)
{
for (unsigned int i=0; i < after_last_element_id; i++) {
- button_info* btn = &m_buttons[i];
+ button_info *btn = &m_buttons[i];
std::vector<int>::iterator id =
- std::find(btn->ids.begin(),btn->ids.end(), eventID);
+ std::find(btn->ids.begin(), btn->ids.end(), eventID);
if (id != btn->ids.end())
return (touch_gui_button_id) i;
bool TouchScreenGUI::isHUDButton(const SEvent &event)
{
// check if hud item is pressed
- for (std::map<int,rect<s32> >::iterator iter = m_hud_rects.begin();
+ for (std::map<int, rect<s32> >::iterator iter = m_hud_rects.begin();
iter != m_hud_rects.end(); ++iter) {
if (iter->second.isPointInside(
v2s32(event.TouchInput.X,
event.TouchInput.Y)
)) {
if ( iter->first < 8) {
- SEvent* translated = new SEvent();
- memset(translated,0,sizeof(SEvent));
+ SEvent *translated = new SEvent();
+ memset(translated, 0, sizeof(SEvent));
translated->EventType = irr::EET_KEY_INPUT_EVENT;
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
translated->KeyInput.Control = false;
bool TouchScreenGUI::isReleaseHUDButton(int eventID)
{
- std::map<int,irr::EKEY_CODE>::iterator iter = m_hud_ids.find(eventID);
+ std::map<int, irr::EKEY_CODE>::iterator iter = m_hud_ids.find(eventID);
if (iter != m_hud_ids.end()) {
- SEvent* translated = new SEvent();
- memset(translated,0,sizeof(SEvent));
+ SEvent *translated = new SEvent();
+ memset(translated, 0, sizeof(SEvent));
translated->EventType = irr::EET_KEY_INPUT_EVENT;
translated->KeyInput.Key = iter->second;
translated->KeyInput.PressedDown = false;
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
int eventID, bool action)
{
- button_info* btn = &m_buttons[button];
- SEvent* translated = new SEvent();
- memset(translated,0,sizeof(SEvent));
+ button_info *btn = &m_buttons[button];
+ SEvent *translated = new SEvent();
+ memset(translated, 0, sizeof(SEvent));
translated->EventType = irr::EET_KEY_INPUT_EVENT;
translated->KeyInput.Key = btn->keycode;
translated->KeyInput.Control = false;
// add this event
if (action) {
- assert(std::find(btn->ids.begin(),btn->ids.end(), eventID) == btn->ids.end());
+ assert(std::find(btn->ids.begin(), btn->ids.end(), eventID) == btn->ids.end());
btn->ids.push_back(eventID);
if ((!action) || (btn->immediate_release)) {
std::vector<int>::iterator pos =
- std::find(btn->ids.begin(),btn->ids.end(), eventID);
+ std::find(btn->ids.begin(), btn->ids.end(), eventID);
// has to be in touch list
assert(pos != btn->ids.end());
btn->ids.erase(pos);
// if this pointer issued a mouse event issue symmetric release here
if (m_move_sent_as_mouse_event) {
- SEvent* translated = new SEvent;
- memset(translated,0,sizeof(SEvent));
+ SEvent *translated = new SEvent;
+ memset(translated, 0, sizeof(SEvent));
translated->EventType = EET_MOUSE_INPUT_EVENT;
translated->MouseInput.X = m_move_downlocation.X;
translated->MouseInput.Y = m_move_downlocation.Y;
}
// remove old button
- handleButtonEvent((touch_gui_button_id) i,*iter,false);
+ handleButtonEvent((touch_gui_button_id) i, *iter, false);
if (current_button_id == after_last_element_id) {
return;
}
- handleButtonEvent((touch_gui_button_id) current_button_id,*iter,true);
+ handleButtonEvent((touch_gui_button_id) current_button_id, *iter, true);
return;
}
return;
}
- button_info* btn = &m_buttons[current_button_id];
- if (std::find(btn->ids.begin(),btn->ids.end(), event.TouchInput.ID)
+ button_info *btn = &m_buttons[current_button_id];
+ if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID)
== btn->ids.end())
{
handleButtonEvent((touch_gui_button_id) current_button_id,
if (distance > (20 + m_touchscreen_threshold))
return false;
- SEvent* translated = new SEvent();
+ SEvent *translated = new SEvent();
memset(translated, 0, sizeof(SEvent));
translated->EventType = EET_MOUSE_INPUT_EVENT;
translated->MouseInput.X = m_key_events[0].x;
TouchScreenGUI::~TouchScreenGUI()
{
for (unsigned int i = 0; i < after_last_element_id; i++) {
- button_info* btn = &m_buttons[i];
+ button_info *btn = &m_buttons[i];
if (btn->guibutton) {
btn->guibutton->drop();
btn->guibutton = NULL;
{
// simulate keyboard repeats
for (unsigned int i = 0; i < after_last_element_id; i++) {
- button_info* btn = &m_buttons[i];
+ button_info *btn = &m_buttons[i];
if (btn->ids.size() > 0) {
btn->repeatcounter += dtime;
{
m_visible = visible;
for (unsigned int i = 0; i < after_last_element_id; i++) {
- button_info* btn = &m_buttons[i];
+ button_info *btn = &m_buttons[i];
if (btn->guibutton) {
btn->guibutton->setVisible(visible);
}