From 8765d58b02c9afd00186bae4a0045dff32f7d102 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 17:47:54 +0200 Subject: Fixed code formatting * moved braces to new lines * fixed some function/variable names * fixed whitespace issues --- src/ui/list.cpp | 164 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 112 insertions(+), 52 deletions(-) (limited to 'src/ui/list.cpp') diff --git a/src/ui/list.cpp b/src/ui/list.cpp index 7593582..f6c3ed9 100644 --- a/src/ui/list.cpp +++ b/src/ui/list.cpp @@ -33,13 +33,15 @@ CList::CList() : CControl() m_button[i] = nullptr; m_scroll = nullptr; - for (int i = 0; i < LISTMAXTOTAL; i++) { + for (int i = 0; i < LISTMAXTOTAL; i++) + { m_text[i][0] = 0; m_check[i] = false; m_enable[i] = true; } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) + { m_tabs[i] = 0.0f; m_justifs[i] = Gfx::TEXT_ALIGN_LEFT; } @@ -57,7 +59,8 @@ CList::CList() : CControl() CList::~CList() { - for (int i = 0; i < LISTMAXDISPLAY; i++) { + for (int i = 0; i < LISTMAXDISPLAY; i++) + { if (m_button[i] != nullptr) delete m_button[i]; } @@ -103,8 +106,10 @@ bool CList::MoveAdjust() Math::Point ipos, idim, ppos, ddim; float marging, h; - for (int i = 0; i < LISTMAXDISPLAY; i++) { - if (m_button[i] != nullptr) { + for (int i = 0; i < LISTMAXDISPLAY; i++) + { + if (m_button[i] != nullptr) + { delete m_button[i]; m_button[i] = nullptr; } @@ -142,7 +147,8 @@ bool CList::MoveAdjust() ppos.y = ipos.y + idim.y - h; ddim.x = idim.x - SCROLL_WIDTH; ddim.y = h; - for (int i = 0; i < m_displayLine; i++) { + for (int i = 0; i < m_displayLine; i++) + { m_button[i] = new CButton(); m_button[i]->Create(ppos, ddim, -1, EVENT_NULL); m_button[i]->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); @@ -154,7 +160,8 @@ bool CList::MoveAdjust() m_eventButton[i] = m_button[i]->GetEventType(); } - if ( m_scroll != nullptr ) { + if ( m_scroll != nullptr ) + { ppos.x = ipos.x + idim.x - SCROLL_WIDTH; ppos.y = ipos.y; ddim.x = SCROLL_WIDTH; @@ -206,8 +213,10 @@ void CList::SetDim(Math::Point dim) bool CList::SetState(int state, bool bState) { - if (state & STATE_ENABLE) { - for (int i = 0; i < m_displayLine; i++) { + if (state & STATE_ENABLE) + { + for (int i = 0; i < m_displayLine; i++) + { if (m_button[i] != nullptr) m_button[i]->SetState(state, bState); } @@ -221,8 +230,10 @@ bool CList::SetState(int state, bool bState) bool CList::SetState(int state) { - if (state & STATE_ENABLE) { - for (int i = 0; i < m_displayLine; i++) { + if (state & STATE_ENABLE) + { + for (int i = 0; i < m_displayLine; i++) + { if (m_button[i] != nullptr) m_button[i]->SetState(state); } @@ -236,8 +247,10 @@ bool CList::SetState(int state) bool CList::ClearState(int state) { - if (state & STATE_ENABLE) { - for (int i = 0; i < m_displayLine; i++) { + if (state & STATE_ENABLE) + { + for (int i = 0; i < m_displayLine; i++) + { if (m_button[i] != nullptr) m_button[i]->ClearState(state); } @@ -254,15 +267,20 @@ bool CList::ClearState(int state) bool CList::EventProcess(const Event &event) { int i; - if (m_bBlink && event.type == EVENT_FRAME) { + if (m_bBlink && event.type == EVENT_FRAME) + { i = m_selectLine-m_firstLine; - if (i >= 0 && i < 4 && m_button[i] != nullptr) { + if (i >= 0 && i < 4 && m_button[i] != nullptr) + { m_blinkTime += event.rTime; - if (Math::Mod(m_blinkTime, 0.7f) < 0.3f) { + if (Math::Mod(m_blinkTime, 0.7f) < 0.3f) + { m_button[i]->ClearState(STATE_ENABLE); m_button[i]->ClearState(STATE_CHECK); - } else { + } + else + { m_button[i]->SetState(STATE_ENABLE); m_button[i]->SetState(STATE_CHECK); } @@ -274,7 +292,8 @@ bool CList::EventProcess(const Event &event) if ((m_state & STATE_ENABLE) == 0) return true; - if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_UP && Detect(event.mousePos)) { + if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_UP && Detect(event.mousePos)) + { if (m_firstLine > 0) m_firstLine--; UpdateScroll(); @@ -282,7 +301,8 @@ bool CList::EventProcess(const Event &event) return true; } - if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_DOWN && Detect(event.mousePos)) { + if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_DOWN && Detect(event.mousePos)) + { if (m_firstLine < m_totalLine - m_displayLine) m_firstLine++; UpdateScroll(); @@ -292,9 +312,11 @@ bool CList::EventProcess(const Event &event) CControl::EventProcess(event); - if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos)) { + if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos)) + { m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); - for (i = 0; i < m_displayLine; i++) { + for (i = 0; i < m_displayLine; i++) + { if (i + m_firstLine >= m_totalLine) break; if (m_button[i] != nullptr) @@ -302,16 +324,20 @@ bool CList::EventProcess(const Event &event) } } - if (m_bSelectCap) { - for (i = 0; i < m_displayLine; i++) { + if (m_bSelectCap) + { + for (i = 0; i < m_displayLine; i++) + { if (i + m_firstLine >= m_totalLine) break; - if (m_button[i] != nullptr) { + if (m_button[i] != nullptr) + { if (!m_button[i]->EventProcess(event)) return false; - if (event.type == m_eventButton[i]) { + if (event.type == m_eventButton[i]) + { SetSelect(m_firstLine + i); Event newEvent = event; @@ -322,11 +348,13 @@ bool CList::EventProcess(const Event &event) } } - if (m_scroll != nullptr) { + if (m_scroll != nullptr) + { if (!m_scroll->EventProcess(event)) return false; - if (event.type == m_eventScroll) { + if (event.type == m_eventScroll) + { MoveScroll(); UpdateButton(); } @@ -354,10 +382,12 @@ void CList::Draw() dp = 0.5f / 256.0f; - if (m_icon != -1) { + if (m_icon != -1) + { dim = m_dim; - if (m_icon == 0) { + if (m_icon == 0) + { m_engine->SetTexture("button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -365,7 +395,9 @@ void CList::Draw() uv1.y = 64.0f / 256.0f; // u-v texture uv2.x = 160.0f / 256.0f; uv2.y = 96.0f / 256.0f; - } else { + } + else + { m_engine->SetTexture("button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -374,7 +406,8 @@ void CList::Draw() uv2.x = 156.0f / 256.0f; uv2.y = 92.0f / 256.0f; - if (m_button[0] != nullptr) { + if (m_button[0] != nullptr) + { dim = m_button[0]->GetDim(); dim.y *= m_displayLine; // background sounds spot behind } @@ -390,9 +423,11 @@ void CList::Draw() DrawIcon(m_pos, dim, uv1, uv2, corner, 8.0f / 256.0f); } - if ( m_totalLine < m_displayLine ) { // no buttons to the bottom? + if ( m_totalLine < m_displayLine ) // no buttons to the bottom? + { i = m_totalLine; - if ( m_button[i] != 0 ) { + if ( m_button[i] != 0 ) + { pos = m_button[i]->GetPos(); dim = m_button[i]->GetDim(); pos.y += dim.y * 1.1f; @@ -413,11 +448,13 @@ void CList::Draw() } } - for (i = 0; i < m_displayLine; i++) { + for (i = 0; i < m_displayLine; i++) + { if ( i + m_firstLine >= m_totalLine ) break; - if ( m_button[i] != nullptr ) { + if ( m_button[i] != nullptr ) + { if ( !m_bBlink && i + m_firstLine < m_totalLine ) m_button[i]->SetState(STATE_ENABLE, m_enable[i+m_firstLine] && (m_state & STATE_ENABLE) ); @@ -426,22 +463,27 @@ void CList::Draw() // draws text in the box pos = m_button[i]->GetPos(); dim = m_button[i]->GetDim(); - if ( m_tabs[0] == 0.0f ) { + if ( m_tabs[0] == 0.0f ) + { ppos.x = pos.x + dim.y * 0.5f; ppos.y = pos.y + dim.y * 0.5f; ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; ddim.x = dim.x-dim.y; DrawCase(m_text[i + m_firstLine], ppos, ddim.x, Gfx::TEXT_ALIGN_LEFT); - } else { + } + else + { ppos.x = pos.x + dim.y * 0.5f; ppos.y = pos.y + dim.y * 0.5f; ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; pb = m_text[i + m_firstLine]; - for (int j = 0; j < 10; j++) { + for (int j = 0; j < 10; j++) + { pe = strchr(pb, '\t'); if ( pe == 0 ) strcpy(text, pb); - else { + else + { strncpy(text, pb, pe - pb); text[pe - pb] = 0; } @@ -454,7 +496,8 @@ void CList::Draw() } } - if ( (m_state & STATE_EXTEND) && i < m_totalLine) { + if ( (m_state & STATE_EXTEND) && i < m_totalLine) + { pos = m_button[i]->GetPos(); dim = m_button[i]->GetDim(); pos.x += dim.x - dim.y * 0.75f; @@ -464,7 +507,8 @@ void CList::Draw() dim.x -= 4.0f / 640.0f; dim.y -= 4.0f / 480.0f; - if ( m_check[i + m_firstLine] ) { + if ( m_check[i + m_firstLine] ) + { m_engine->SetTexture("button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; @@ -487,15 +531,20 @@ void CList::Draw() uv2.x -= dp; uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); // draws v - } else { + } + else + { m_engine->SetTexture("button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw - if ( i + m_firstLine == m_selectLine ) { + if ( i + m_firstLine == m_selectLine ) + { uv1.x =224.0f / 256.0f; // < uv1.y =192.0f / 256.0f; uv2.x =256.0f / 256.0f; uv2.y =224.0f / 256.0f; - } else { + } + else + { uv1.x = 96.0f / 256.0f; // x uv1.y = 32.0f / 256.0f; uv2.x =128.0f / 256.0f; @@ -560,7 +609,8 @@ void CList::SetSelect(int i) { if ( m_bSelectCap ) m_selectLine = i; - else { + else + { m_firstLine = i; UpdateScroll(); } @@ -603,8 +653,10 @@ void CList::SetBlink(bool bEnable) i = m_selectLine-m_firstLine; - if (i >= 0 && i < 4 && m_button[i] != nullptr) { - if ( !bEnable ) { + if (i >= 0 && i < 4 && m_button[i] != nullptr) + { + if ( !bEnable ) + { m_button[i]->SetState(STATE_CHECK); m_button[i]->ClearState(STATE_ENABLE); } @@ -744,17 +796,21 @@ void CList::UpdateButton() state = CControl::GetState(); j = m_firstLine; - for (i = 0; i < m_displayLine; i++) { + for (i = 0; i < m_displayLine; i++) + { if (m_button[i] == nullptr) continue; m_button[i]->SetState(STATE_CHECK, (j == m_selectLine)); - if ( j < m_totalLine ) { + if ( j < m_totalLine ) + { //? m_button[i]->SetName(m_text[j]); m_button[i]->SetName(" "); // blank button m_button[i]->SetState(STATE_ENABLE, (state & STATE_ENABLE)); - } else { + } + else + { m_button[i]->SetName(" "); // blank button m_button[i]->ClearState(STATE_ENABLE); } @@ -771,11 +827,14 @@ void CList::UpdateScroll() if (m_scroll == nullptr) return; - if (m_totalLine <= m_displayLine) { + if (m_totalLine <= m_displayLine) + { ratio = 1.0f; value = 0.0f; step = 0.0f; - } else { + } + else + { ratio = static_cast(m_displayLine) / m_totalLine; if ( ratio > 1.0f ) ratio = 1.0f; @@ -817,3 +876,4 @@ void CList::MoveScroll() } // namespace Ui + -- cgit v1.2.3-1-g7c22