From 10b2c562fb7635f9850f1441f08ba8b1a71e31e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Konopacki?= Date: Wed, 15 Aug 2012 01:48:49 +0200 Subject: First approach to port 2D UI Interface - changes in src/ui ; be CAREFUL, not every file is changed in a proper way -> bugs - necessary changes in object/robotmain.h and common/misc.h/.cpp in order to compile --- src/ui/compass.cpp | 55 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'src/ui/compass.cpp') diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index 7ea6e9d..d4a15a8 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.cpp @@ -15,14 +15,16 @@ // * along with this program. If not, see http://www.gnu.org/licenses/. -#include +//#include #include -#include +//#include -#include "common/struct.h" +//#include "common/struct.h" #include "math/geometry.h" -#include "old/d3dengine.h" -#include "old/math3d.h" +//#include "old/d3dengine.h" +#include "graphics/engine/engine.h" +#include "graphics/core/device.h" +//#include "old/math3d.h" #include "common/event.h" #include "common/misc.h" #include "common/iman.h" @@ -47,11 +49,11 @@ CCompass::~CCompass() // Creates a new button. -bool CCompass::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +bool CCompass::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) { - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); + if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); - CControl::Create(pos, dim, icon, eventMsg); + CControl::Create(pos, dim, icon, eventType); return true; } @@ -62,12 +64,13 @@ bool CCompass::EventProcess(const Event &event) { CControl::EventProcess(event); - if ( event.event == EVENT_LBUTTONDOWN ) + if ( event.type == EVENT_MOUSE_BUTTON_DOWN && + event.mouseButton.button == 1) { if ( CControl::Detect(event.pos) ) { Event newEvent = event; - newEvent.event = m_eventMsg; + newEvent.type = m_eventType; m_event->AddEvent(newEvent); return false; } @@ -81,18 +84,18 @@ bool CCompass::EventProcess(const Event &event) void CCompass::Draw() { - LPDIRECT3DDEVICE7 device; - D3DVERTEX2 vertex[4]; // 2 triangles - Math::Point p1, p2, p3, c, uv1, uv2; - Math::Vector n; - float dp; + Gfx::CDevice* device; + Gfx::Vertex vertex[4]; // 2 triangles + Math::Point p1, p2, p3, c, uv1, uv2; + Math::Vector n; + float dp; if ( (m_state & STATE_VISIBLE) == 0 ) return; - device = m_engine->RetD3DDevice(); + device = m_engine->GetDevice(); m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); p1.x = m_pos.x; p1.y = m_pos.y; @@ -115,12 +118,12 @@ void CCompass::Draw() n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, uv1.x,uv2.y); - vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, uv1.x,uv1.y); - vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, uv2.x,uv2.y); - vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, uv2.x,uv1.y); + vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point( uv1.x,uv2.y)); + vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point( uv1.x,uv1.y)); + vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point( uv2.x,uv2.y)); + vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point( uv2.x,uv1.y)); - device->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); if ( m_state & STATE_ENABLE ) @@ -150,11 +153,11 @@ void CCompass::Draw() uv2.x -= dp; uv2.y -= dp; - vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, uv1.x,uv1.y); - vertex[1] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, uv1.x,uv2.y); - vertex[2] = D3DVERTEX2(Math::Vector(p3.x, p3.y, 0.0f), n, uv2.x,uv2.y); + vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point( uv1.x,uv1.y)); + vertex[1] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point( uv1.x,uv2.y)); + vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point( uv2.x,uv2.y)); - device->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX2, vertex, 3, NULL); + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, vertex, 3); m_engine->AddStatisticTriangle(1); } } -- cgit v1.2.3-1-g7c22 From 574c07e388dfd902b6565bc4a5ac9b915c73074e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Konopacki?= Date: Sat, 18 Aug 2012 22:56:42 +0200 Subject: Further improvements in UI porting --- src/ui/compass.cpp | 63 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'src/ui/compass.cpp') diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index d4a15a8..95e75b3 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.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 @@ -16,7 +17,7 @@ //#include -#include +//#include //#include //#include "common/struct.h" @@ -32,10 +33,11 @@ - +namespace Ui { // Object's constructor. -CCompass::CCompass(CInstanceManager* iMan) : CControl(iMan) +//CCompass::CCompass(CInstanceManager* iMan) : CControl(iMan) +CCompass::CCompass() : CControl() { m_dir = 0.0f; } @@ -102,15 +104,15 @@ void CCompass::Draw() p2.x = m_pos.x + m_dim.x; p2.y = m_pos.y + m_dim.y; - c.x = (p1.x+p2.x)/2.0f; - c.y = (p1.y+p2.y)/2.0f; // center + c.x = (p1.x + p2.x) / 2.0f; + c.y = (p1.y + p2.y) / 2.0f; // center - uv1.x = 64.0f/256.0f; - uv1.y = 32.0f/256.0f; - uv2.x = 96.0f/256.0f; - uv2.y = 64.0f/256.0f; + uv1.x = 64.0f / 256.0f; + uv1.y = 32.0f / 256.0f; + uv2.x = 96.0f / 256.0f; + uv2.y = 64.0f / 256.0f; - dp = 0.5f/256.0f; + dp = 0.5f / 256.0f; uv1.x += dp; uv1.y += dp; uv2.x -= dp; @@ -118,10 +120,10 @@ void CCompass::Draw() n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point( uv1.x,uv2.y)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point( uv1.x,uv1.y)); - vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point( uv2.x,uv2.y)); - vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point( uv2.x,uv1.y)); + vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y)); + vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y)); + vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y)); + vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y)); device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -129,33 +131,33 @@ void CCompass::Draw() if ( m_state & STATE_ENABLE ) { p1.x = c.x; - p1.y = c.y+m_dim.x*0.40f; + p1.y = c.y + m_dim.x * 0.40f; p1 = Math::RotatePoint(c, m_dir, p1); - p1.x = c.x+(p1.x-c.x)*(m_dim.x/m_dim.y); + p1.x = c.x + (p1.x - c.x) * (m_dim.x / m_dim.y); - p2.x = c.x+m_dim.x*0.20f; - p2.y = c.y-m_dim.x*0.40f; + p2.x = c.x + m_dim.x * 0.20f; + p2.y = c.y - m_dim.x * 0.40f; p2 = Math::RotatePoint(c, m_dir, p2); - p2.x = c.x+(p2.x-c.x)*(m_dim.x/m_dim.y); + p2.x = c.x + (p2.x - c.x) * (m_dim.x / m_dim.y); - p3.x = c.x-m_dim.x*0.20f; - p3.y = c.y-m_dim.x*0.40f; + p3.x = c.x - m_dim.x * 0.20f; + p3.y = c.y - m_dim.x * 0.40f; p3 = Math::RotatePoint(c, m_dir, p3); - p3.x = c.x+(p3.x-c.x)*(m_dim.x/m_dim.y); + p3.x = c.x + (p3.x - c.x) * (m_dim.x / m_dim.y); - uv1.x = 96.0f/256.0f; - uv1.y = 32.0f/256.0f; - uv2.x = 104.0f/256.0f; - uv2.y = 64.0f/256.0f; + uv1.x = 96.0f / 256.0f; + uv1.y = 32.0f / 256.0f; + uv2.x = 104.0f / 256.0f; + uv2.y = 64.0f / 256.0f; uv1.x += dp; uv1.y += dp; uv2.x -= dp; uv2.y -= dp; - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point( uv1.x,uv1.y)); - vertex[1] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point( uv1.x,uv2.y)); - vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point( uv2.x,uv2.y)); + vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv1.y)); + vertex[1] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv2.y)); + vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y)); device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, vertex, 3); m_engine->AddStatisticTriangle(1); @@ -170,9 +172,10 @@ void CCompass::SetDirection(float dir) m_dir = dir; } -float CCompass::RetDirection() +float CCompass::GetDirection() { return m_dir; } +} -- cgit v1.2.3-1-g7c22 From 01cc0fbc49696a19a56dfdd8359d4bb77e868925 Mon Sep 17 00:00:00 2001 From: erihel Date: Tue, 11 Sep 2012 12:49:41 +0200 Subject: * latest changes * all files except studio, map and maindialog should compile * did some code cleanup --- src/ui/compass.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/ui/compass.cpp') diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index 95e75b3..1969710 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.cpp @@ -15,23 +15,16 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. +#include "compass.h" -//#include -//#include -//#include - -//#include "common/struct.h" -#include "math/geometry.h" -//#include "old/d3dengine.h" -#include "graphics/engine/engine.h" -#include "graphics/core/device.h" -//#include "old/math3d.h" #include "common/event.h" -#include "common/misc.h" #include "common/iman.h" -#include "ui/compass.h" +#include "common/misc.h" +#include "graphics/core/device.h" +#include "graphics/engine/engine.h" +#include "math/geometry.h" namespace Ui { // Object's constructor. -- 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/compass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/compass.cpp') diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index 102b697..f7be764 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.cpp @@ -89,7 +89,7 @@ void CCompass::Draw() device = m_engine->GetDevice(); - m_engine->SetTexture("button2.tga"); + m_engine->SetTexture("button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); p1.x = m_pos.x; -- 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/compass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/compass.cpp') diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp index f7be764..c7d0068 100644 --- a/src/ui/compass.cpp +++ b/src/ui/compass.cpp @@ -62,7 +62,7 @@ bool CCompass::EventProcess(const Event &event) if ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.mouseButton.button == 1) { - if ( CControl::Detect(event.pos) ) + if ( CControl::Detect(event.mouseButton.pos) ) { Event newEvent = event; newEvent.type = m_eventType; -- cgit v1.2.3-1-g7c22