From 479a67a731be5a5e8035ea7acce0344c7c605814 Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Mon, 10 Sep 2012 23:29:38 +0200 Subject: Merge with changes from Zaba999 fork. --- src/ui/slider.cpp | 85 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 38 deletions(-) (limited to 'src/ui/slider.cpp') diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index be8af18..27bcfbb 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -1,5 +1,6 @@ // * This file is part of the COLOBOT source code // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012, Polish Portal of Colobot (PPC) // * // * This program is free software: you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by @@ -17,21 +18,24 @@ // slider.cpp -#include +//#include #include -#include +//#include -#include "common/struct.h" -#include "old/d3dengine.h" -#include "old/math3d.h" +//#include "common/struct.h" +//#include "old/d3dengine.h" +//#include "old/math3d.h" +#include "graphics/engine/engine.h" #include "common/event.h" #include "common/misc.h" #include "common/iman.h" -#include "old/text.h" +//#include "old/text.h" +#include "graphics/engine/text.h" #include "ui/button.h" #include "ui/slider.h" +namespace Ui { const float CURSOR_WIDTH = (10.0f/640.0f); const float HOLE_WIDTH = (5.0f/480.0f); @@ -41,7 +45,7 @@ const float HOLE_WIDTH = (5.0f/480.0f); // Object's constructor. -CSlider::CSlider(CInstanceManager* iMan) : CControl(iMan) +CSlider::CSlider() : CControl() { m_buttonLeft = 0; m_buttonRight = 0; @@ -71,10 +75,10 @@ CSlider::~CSlider() // Creates a new button. -bool CSlider::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +bool CSlider::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) { - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - CControl::Create(pos, dim, icon, eventMsg); + if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); + CControl::Create(pos, dim, icon, eventType); MoveAdjust(); return true; @@ -115,20 +119,20 @@ void CSlider::MoveAdjust() #if 1 if ( m_buttonLeft == 0 ) { - m_buttonLeft = new CButton(m_iMan); + m_buttonLeft = new CButton(); m_buttonLeft->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?55:49, EVENT_NULL); // SetRepeat(true); if ( m_state & STATE_SHADOW ) m_buttonLeft->SetState(STATE_SHADOW); - m_eventUp = m_buttonLeft->RetEventMsg(); + m_eventUp = m_buttonLeft->GetEventType(); } if ( m_buttonRight == 0 ) { - m_buttonRight = new CButton(m_iMan); + m_buttonRight = new CButton(); m_buttonRight->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?48:50, EVENT_NULL); // >/v m_buttonRight->SetRepeat(true); if ( m_state & STATE_SHADOW ) m_buttonRight->SetState(STATE_SHADOW); - m_eventDown = m_buttonRight->RetEventMsg(); + m_eventDown = m_buttonRight->GetEventType(); } m_marginButton = m_bHoriz?(m_dim.y*0.75f):(m_dim.x/0.75f); @@ -261,7 +265,7 @@ bool CSlider::EventProcess(const Event &event) if ( !m_buttonRight->EventProcess(event) ) return false; } - if ( event.event == m_eventUp && m_step > 0.0f ) + if ( event.type == m_eventUp && m_step > 0.0f ) { m_visibleValue -= m_bHoriz?m_step:-m_step; if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f; @@ -269,11 +273,11 @@ bool CSlider::EventProcess(const Event &event) AdjustGlint(); Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); } - if ( event.event == m_eventDown && m_step > 0.0f ) + if ( event.type == m_eventDown && m_step > 0.0f ) { m_visibleValue += m_bHoriz?m_step:-m_step; if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f; @@ -281,12 +285,13 @@ bool CSlider::EventProcess(const Event &event) AdjustGlint(); Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); } - if ( event.event == EVENT_LBUTTONDOWN && - (m_state & STATE_VISIBLE) && + if ( event.type == EVENT_MOUSE_BUTTON_DOWN && + (event.mouseButton.button == 1 ) && + (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { if ( CControl::Detect(event.pos) ) @@ -311,7 +316,7 @@ bool CSlider::EventProcess(const Event &event) AdjustGlint(); Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); m_bCapture = true; @@ -320,7 +325,7 @@ bool CSlider::EventProcess(const Event &event) } } - if ( event.event == EVENT_MOUSEMOVE && m_bCapture ) + if ( event.type == EVENT_MOUSE_MOVE && m_bCapture ) { if ( m_bHoriz ) { @@ -345,32 +350,35 @@ bool CSlider::EventProcess(const Event &event) AdjustGlint(); Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); } } - if ( event.event == EVENT_LBUTTONUP && m_bCapture ) + if ( ( event.type == EVENT_MOUSE_BUTTON_UP ) && + ( event.mouseButton.button == 1 ) && + m_bCapture ) { m_bCapture = false; } - if ( event.event == EVENT_KEYDOWN && - event.param == VK_WHEELUP && + if ( event.type == EVENT_KEY_DOWN && + event.mouseButton.button == 4 && Detect(event.pos) && m_buttonLeft != 0 ) { Event newEvent = event; - newEvent.event = m_buttonLeft->RetEventMsg(); + newEvent.type = m_buttonLeft->GetEventType(); m_event->AddEvent(newEvent); } - if ( event.event == EVENT_KEYDOWN && - event.param == VK_WHEELDOWN && + + if ( event.type == EVENT_KEY_DOWN && + event.mouseButton.button == 5 && Detect(event.pos) && m_buttonRight != 0 ) { Event newEvent = event; - newEvent.event = m_buttonRight->RetEventMsg(); + newEvent.type = m_buttonRight->GetEventType(); m_event->AddEvent(newEvent); } @@ -466,10 +474,10 @@ void CSlider::Draw() if ( m_bHoriz ) { sprintf(text, "%d", (int)(m_min+m_visibleValue*(m_max-m_min))); - h = m_engine->RetText()->RetHeight(m_fontSize, m_fontType); + h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); pos.x = m_pos.x+m_dim.x+(10.0f/640.0f); pos.y = m_pos.y+(m_dim.y-h)/2.0f; - m_engine->RetText()->DrawText(text, pos, m_dim.x, 1, m_fontSize, m_fontStretch, m_fontType, 0); + m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); } else { @@ -482,7 +490,7 @@ void CSlider::Draw() dim.x = 50.0f/640.0f; dim.y = 16.0f/480.0f; sprintf(text, "%d", (int)(m_min+(m_visibleValue*(m_max-m_min)))); - m_engine->RetText()->DrawText(text, pos, dim.x, 1, m_fontSize, m_fontStretch, m_fontType, 0); + m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); } } } @@ -497,7 +505,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) if ( icon == 0 ) { m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // yellow rectangle uv1.y = 32.0f/256.0f; uv2.x = 32.0f/256.0f; @@ -509,7 +517,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) else if ( icon == 1 ) { m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // gray rectangle uv1.y = 32.0f/256.0f; uv2.x = 160.0f/256.0f; @@ -521,7 +529,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) else { m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 224.0f/256.0f; // cursor uv1.y = 32.0f/256.0f; uv2.x = 256.0f/256.0f; @@ -561,7 +569,7 @@ void CSlider::SetVisibleValue(float value) AdjustGlint(); } -float CSlider::RetVisibleValue() +float CSlider::GetVisibleValue() { return m_min+m_visibleValue*(m_max-m_min); } @@ -572,9 +580,10 @@ void CSlider::SetArrowStep(float step) m_step = step/(m_max-m_min); } -float CSlider::RetArrowStep() +float CSlider::GetArrowStep() { return m_step*(m_max-m_min); } +} -- cgit v1.2.3-1-g7c22 From 6a0d150539897ec65ccc161305db48de10ea35ba Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 16 Sep 2012 10:38:08 +0200 Subject: Interface works - removed mock of CInterface and fixed event passing to CRobotMain - changed texture names from tga and bmp to png - UI now works but interaction is still broken --- src/ui/slider.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ui/slider.cpp') diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 2bf0cc8..4394cc2 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -498,7 +498,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) if ( icon == 0 ) { - m_engine->SetTexture("button2.tga"); + m_engine->SetTexture("button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // yellow rectangle uv1.y = 32.0f/256.0f; @@ -510,7 +510,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("button2.tga"); + m_engine->SetTexture("button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // gray rectangle uv1.y = 32.0f/256.0f; @@ -522,7 +522,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else { - m_engine->SetTexture("button2.tga"); + m_engine->SetTexture("button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 224.0f/256.0f; // cursor uv1.y = 32.0f/256.0f; -- cgit v1.2.3-1-g7c22 From da5d4edeb3a41462ec987cb4994a6897823f3f76 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 18 Sep 2012 17:52:36 +0200 Subject: Fixed invalid text alignment --- src/ui/slider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/slider.cpp') diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 4394cc2..869fa42 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -471,7 +471,7 @@ void CSlider::Draw() h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); pos.x = m_pos.x+m_dim.x+(10.0f/640.0f); pos.y = m_pos.y+(m_dim.y-h)/2.0f; - m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); + m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, 0); } else { @@ -484,7 +484,7 @@ void CSlider::Draw() dim.x = 50.0f/640.0f; dim.y = 16.0f/480.0f; sprintf(text, "%d", (int)(m_min+(m_visibleValue*(m_max-m_min)))); - m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); + m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_LEFT, 0); } } } -- cgit v1.2.3-1-g7c22 From 36ae984ac77c5545d3d11dde7e37913a8eff0b0d Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Tue, 18 Sep 2012 22:33:28 +0200 Subject: Warnings cleaned, left only those connected to commented out code. --- src/ui/slider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/slider.cpp') diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 4394cc2..e32bb96 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -467,7 +467,7 @@ void CSlider::Draw() if ( m_bHoriz ) { - sprintf(text, "%d", (int)(m_min+m_visibleValue*(m_max-m_min))); + sprintf(text, "%d", static_cast(m_min+m_visibleValue*(m_max-m_min))); h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); pos.x = m_pos.x+m_dim.x+(10.0f/640.0f); pos.y = m_pos.y+(m_dim.y-h)/2.0f; @@ -483,7 +483,7 @@ void CSlider::Draw() pos.y += (h-CURSOR_WIDTH)*m_visibleValue; dim.x = 50.0f/640.0f; dim.y = 16.0f/480.0f; - sprintf(text, "%d", (int)(m_min+(m_visibleValue*(m_max-m_min)))); + sprintf(text, "%d", static_cast(m_min+(m_visibleValue*(m_max-m_min)))); m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); } } -- cgit v1.2.3-1-g7c22 From 1a79137e904eb07c17df2596e6b8aa9310ff22bd Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 19 Sep 2012 21:45:41 +0200 Subject: Mouse wheel fixes --- src/ui/slider.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/ui/slider.cpp') diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 185ee35..175a6fe 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -356,20 +356,20 @@ bool CSlider::EventProcess(const Event &event) m_bCapture = false; } - if ( event.type == EVENT_KEY_DOWN && - event.mouseButton.button == 4 && - Detect(event.pos) && - m_buttonLeft != 0 ) + if (event.type == EVENT_MOUSE_WHEEL && + event.mouseWheel.dir == WHEEL_UP && + Detect(event.mouseWheel.pos) && + m_buttonLeft != 0) { Event newEvent = event; newEvent.type = m_buttonLeft->GetEventType(); m_event->AddEvent(newEvent); } - if ( event.type == EVENT_KEY_DOWN && - event.mouseButton.button == 5 && - Detect(event.pos) && - m_buttonRight != 0 ) + if (event.type == EVENT_MOUSE_WHEEL && + event.mouseButton.button == WHEEL_DOWN && + Detect(event.mouseWheel.pos) && + m_buttonRight != 0) { Event newEvent = event; newEvent.type = m_buttonRight->GetEventType(); -- cgit v1.2.3-1-g7c22 From 57d33d79ea570773d84ad81d4a61f50e079979ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Konopacki?= Date: Wed, 19 Sep 2012 22:17:28 +0200 Subject: Changes in Ui, solves part of #47 --- src/ui/slider.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/ui/slider.cpp') diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 175a6fe..70dd2cc 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -288,20 +288,20 @@ bool CSlider::EventProcess(const Event &event) (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { - if ( CControl::Detect(event.pos) ) + if ( CControl::Detect(event.mouseButton.pos) ) { if ( m_bHoriz ) { pos.x = m_pos.x+m_marginButton; dim.x = m_dim.x-m_marginButton*2.0f; - value = (event.pos.x-pos.x-CURSOR_WIDTH/2.0f); + value = (event.mouseButton.pos.x-pos.x-CURSOR_WIDTH/2.0f); value /= (dim.x-CURSOR_WIDTH); } else { pos.y = m_pos.y+m_marginButton; dim.y = m_dim.y-m_marginButton*2.0f; - value = (event.pos.y-pos.y-CURSOR_WIDTH/2.0f); + value = (event.mouseButton.pos.y-pos.y-CURSOR_WIDTH/2.0f); value /= (dim.y-CURSOR_WIDTH); } if ( value < 0.0f ) value = 0.0f; @@ -314,7 +314,7 @@ bool CSlider::EventProcess(const Event &event) m_event->AddEvent(newEvent); m_bCapture = true; - m_pressPos = event.pos; + m_pressPos = event.mouseButton.pos; m_pressValue = m_visibleValue; } } @@ -325,14 +325,14 @@ bool CSlider::EventProcess(const Event &event) { pos.x = m_pos.x+m_marginButton; dim.x = m_dim.x-m_marginButton*2.0f; - value = (event.pos.x-pos.x-CURSOR_WIDTH/2.0f); + value = (event.mouseMove.pos.x-pos.x-CURSOR_WIDTH/2.0f); value /= (dim.x-CURSOR_WIDTH); } else { pos.y = m_pos.y+m_marginButton; dim.y = m_dim.y-m_marginButton*2.0f; - value = (event.pos.y-pos.y-CURSOR_WIDTH/2.0f); + value = (event.mouseMove.pos.y-pos.y-CURSOR_WIDTH/2.0f); value /= (dim.y-CURSOR_WIDTH); } if ( value < 0.0f ) value = 0.0f; -- cgit v1.2.3-1-g7c22