diff options
Diffstat (limited to 'src/button.cxx')
-rw-r--r-- | src/button.cxx | 89 |
1 files changed, 55 insertions, 34 deletions
diff --git a/src/button.cxx b/src/button.cxx index 7a09128..fe934ed 100644 --- a/src/button.cxx +++ b/src/button.cxx @@ -1,7 +1,7 @@ /* * This file is part of the planetblupi source code * Copyright (C) 1997, Daniel Roux & EPSITEC SA - * Copyright (C) 2017-2018, Mathieu Schroeter + * Copyright (C) 2017-2019, Mathieu Schroeter * http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games * * This program is free software: you can redistribute it and/or modify @@ -55,7 +55,8 @@ CButton::~CButton () {} bool CButton::Create ( CPixmap * pPixmap, CSound * pSound, Point pos, Sint32 type, Sint32 * pMenu, - Sint32 nbMenu, const char ** pToolTips, Sint32 region, Uint32 message) + Sint32 nbMenu, const char ** pToolTips, Sint32 region, Uint32 message, + bool isRightReading) { Point iconDim; Sint32 i, icon; @@ -92,6 +93,16 @@ CButton::Create ( { icon = pMenu[i]; + if (isRightReading) + { + if (icon == 51) // right arrow + icon = 50; + else if (icon == 50) // left arrow + icon = 51; + else if (icon == 40) // stop + icon = 109; + } + if (region == 1) // palmiers ? { if (icon == 0) @@ -144,28 +155,27 @@ void CButton::Draw () { Sint32 i; - Point pos; + Point pos = this->m_pos; Rect rect; if (m_bHide) // bouton caché ? { - rect.left = m_pos.x; - rect.right = m_pos.x + m_dim.x; - rect.top = m_pos.y; - rect.bottom = m_pos.y + m_dim.y; - m_pPixmap->DrawPart (-1, CHBACK, m_pos, rect); // dessine le fond + rect.left = pos.x; + rect.right = pos.x + m_dim.x; + rect.top = pos.y; + rect.bottom = pos.y + m_dim.y; + m_pPixmap->DrawPart (-1, CHBACK, pos, rect); // dessine le fond return; } if (m_bEnable) // bouton actif ? - m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_mouseState, m_pos); + m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_mouseState, pos); else - m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, 4, m_pos); + m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, 4, pos); if (m_nbMenu == 0) return; - pos = m_pos; if (m_nbMenu > 0) { m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_iconMenu[m_selMenu] + 6, pos); @@ -174,13 +184,12 @@ CButton::Draw () if (m_nbMenu == 1 || !m_bEnable || !m_bMouseDown) return; - pos = m_pos; - pos.x += m_dim.x + 2; + pos.x += IsRightReading () ? -m_dim.x - 2 : m_dim.x + 2; for (i = 0; i < m_nbMenu; i++) { m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, i == m_selMenu ? 1 : 0, pos); m_pPixmap->DrawIcon (-1, CHBUTTON + m_type, m_iconMenu[i] + 6, pos); - pos.x += m_dim.x - 1; + pos.x += IsRightReading () ? -m_dim.x - 1 : m_dim.x - 1; } } @@ -292,24 +301,43 @@ CButton::MouseOnButton (Point pos) return Detect (pos); } +bool +CButton::IsInMenu (const Point & pos) +{ + Sint32 width = m_dim.x; + + if (m_nbMenu > 1 && m_bMouseDown) // submenu expanded ? + width += 2 + (m_dim.x + (IsRightReading () ? 1 : -1)) * m_nbMenu; + + if (IsRightReading () && m_nbMenu > 1 && m_bMouseDown) + { + if (pos.x > m_pos.x + m_dim.x || pos.x < m_pos.x - width + m_dim.x) + return false; + } + else + { + if (pos.x < m_pos.x || pos.x > m_pos.x + width) + return false; + } + + if (pos.y < m_pos.y || pos.y > m_pos.y + m_dim.y) + return false; + + return true; +} + // Retourne le tooltips pour un bouton, en fonction // de la position de la souris. const char * CButton::GetToolTips (Point pos) { - Sint32 width = m_dim.x; Sint32 rank; if (m_bHide || !m_bEnable) return nullptr; - if (m_nbMenu > 1 && m_bMouseDown) // sous-menu déroulé ? - width += 2 + (m_dim.x - 1) * m_nbMenu; - - if ( - pos.x < m_pos.x || pos.x > m_pos.x + width || pos.y < m_pos.y || - pos.y > m_pos.y + m_dim.y) + if (!this->IsInMenu (pos)) return nullptr; rank = (pos.x - (m_pos.x + 2 + 1)) / (m_dim.x - 1); @@ -334,20 +362,10 @@ CButton::GetToolTips (Point pos) bool CButton::Detect (Point pos) { - Sint32 width = m_dim.x; - if (m_bHide || !m_bEnable) return false; - if (m_nbMenu > 1 && m_bMouseDown) // sous-menu déroulé ? - width += 2 + (m_dim.x - 1) * m_nbMenu; - - if ( - pos.x < m_pos.x || pos.x > m_pos.x + width || pos.y < m_pos.y || - pos.y > m_pos.y + m_dim.y) - return false; - - return true; + return this->IsInMenu (pos); } // Bouton de la souris pressé. @@ -397,9 +415,12 @@ CButton::MouseMove (Point pos) if ( m_nbMenu > 1 && m_bMouseDown && - pos.x > m_pos.x + m_dim.x + 2) // dans sous-menu ? + (IsRightReading () ? pos.x < m_pos.x + : pos.x > m_pos.x + m_dim.x + 2)) // in sub-menu ? { - m_selMenu = (pos.x - (m_pos.x + m_dim.x + 2)) / (m_dim.x - 1); + m_selMenu = IsRightReading () + ? (m_pos.x - 2 - pos.x) / (m_dim.x + 1) + : (pos.x - (m_pos.x + m_dim.x + 2)) / (m_dim.x - 1); if (m_selMenu >= m_nbMenu) m_selMenu = m_nbMenu - 1; } |