UI porting

dev-ui
Michał Konopacki 2012-08-20 14:05:36 +02:00
parent 574c07e388
commit 8666d35f7c
4 changed files with 383 additions and 335 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * it under the terms of the GNU General Public License as published by
@ -14,69 +15,99 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// edit.h
/**
* \file ui/edit.h
* \brief CEdit class
*/
#pragma once #pragma once
#include "common/struct.h" //#include "common/struct.h"
#include "ui/control.h" #include "ui/control.h"
namespace Gfx{
class CEngine;
};
class CD3DEngine; namespace Ui {
class CScroll; class CScroll;
//! maximum number of characters in CBOT edit
const int EDITSTUDIOMAX = 20000;
//! maximum total number of lines
const int EDITLINEMAX = 1000;
//! maximum total number of lines with images
const int EDITIMAGEMAX = 50;
//! maximum number of links
const int EDITLINKMAX = 100;
//! max number of levels preserves
const int EDITHISTORYMAX = 50;
const int EDITSTUDIOMAX = 20000; // maximum number of characters in CBOT edit //! max number of successive undo
const int EDITLINEMAX = 1000; // maximum total number of lines const int EDITUNDOMAX = 20;
const int EDITIMAGEMAX = 50; // maximum total number of lines with images
const int EDITLINKMAX = 100; // maximum number of links
const int EDITHISTORYMAX = 50; // max number of levels preserves
const int EDITUNDOMAX = 20; // max number of successive undo
struct EditUndo struct EditUndo
{ {
char* text; // original text //! original text
int len; // length of the text char* text;
int cursor1; // offset cursor //! length of the text
int cursor2; // offset cursor int len;
int lineFirst; // the first line displayed. //! offset cursor
int cursor1;
//! offset cursor
int cursor2;
//! the first line displayed.
int lineFirst;
}; };
enum OperUndo enum OperUndo
{ {
OPERUNDO_SPEC = 0, // special operation //! special operation
OPERUNDO_INSERT = 1, // inserting characters OPERUNDO_SPEC = 0,
OPERUNDO_DELETE = 2, // deleting characters //! inserting characters
OPERUNDO_INSERT = 1,
//! deleting characters
OPERUNDO_DELETE = 2,
}; };
struct ImageLine struct ImageLine
{ {
char name[40]; // name of the image (without diagram \) //! name of the image (without diagram \)
float offset; // vertical offset (v texture) char name[40];
float height; // height of the part (dv texture) //! vertical offset (v texture)
float width; // width float offset;
//! height of the part (dv texture)
float height;
//! width
float width;
}; };
struct HyperLink struct HyperLink
{ {
char name[40]; // text file name (without help \) //! text file name (without help \)
char marker[20]; // name of the marker char name[40];
//! name of the marker
char marker[20];
}; };
struct HyperMarker struct HyperMarker
{ {
char name[20]; // name of the marker //! name of the marker
int pos; // position in the text char name[20];
//! position in the text
int pos;
}; };
struct HyperHistory struct HyperHistory
{ {
char filename[50]; // full file name text //! full file name text
int firstLine; // rank of the first displayed line char filename[50];
//! rank of the first displayed line
int firstLine;
}; };
@ -85,10 +116,11 @@ struct HyperHistory
class CEdit : public CControl class CEdit : public CControl
{ {
public: public:
CEdit(CInstanceManager* iMan); // CEdit(CInstanceManager* iMan);
CEdit ();
virtual ~CEdit(); virtual ~CEdit();
bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
void SetPos(Math::Point pos); void SetPos(Math::Point pos);
void SetDim(Math::Point dim); void SetDim(Math::Point dim);
@ -98,45 +130,45 @@ public:
void SetText(char *text, bool bNew=true); void SetText(char *text, bool bNew=true);
void GetText(char *buffer, int max); void GetText(char *buffer, int max);
char* RetText(); char* GetText();
int RetTextLength(); int GetTextLength();
bool ReadText(char *filename, int addSize=0); bool ReadText(char *filename, int addSize=0);
bool WriteText(char *filename); bool WriteText(char *filename);
void SetMaxChar(int max); void SetMaxChar(int max);
int RetMaxChar(); int GetMaxChar();
void SetEditCap(bool bMode); void SetEditCap(bool bMode);
bool RetEditCap(); bool GetEditCap();
void SetHiliteCap(bool bEnable); void SetHiliteCap(bool bEnable);
bool RetHiliteCap(); bool GetHiliteCap();
void SetInsideScroll(bool bInside); void SetInsideScroll(bool bInside);
bool RetInsideScroll(); bool GetInsideScroll();
void SetSoluceMode(bool bSoluce); void SetSoluceMode(bool bSoluce);
bool RetSoluceMode(); bool GetSoluceMode();
void SetGenericMode(bool bGeneric); void SetGenericMode(bool bGeneric);
bool RetGenericMode(); bool GetGenericMode();
void SetAutoIndent(bool bMode); void SetAutoIndent(bool bMode);
bool RetAutoIndent(); bool GetAutoIndent();
void SetCursor(int cursor1, int cursor2); void SetCursor(int cursor1, int cursor2);
void GetCursor(int &cursor1, int &cursor2); void GetCursor(int &cursor1, int &cursor2);
void SetFirstLine(int rank); void SetFirstLine(int rank);
int RetFirstLine(); int GetFirstLine();
void ShowSelect(); void ShowSelect();
void SetDisplaySpec(bool bDisplay); void SetDisplaySpec(bool bDisplay);
bool RetDisplaySpec(); bool GetDisplaySpec();
void SetMultiFont(bool bMulti); void SetMultiFont(bool bMulti);
bool RetMultiFont(); bool GetMultiFont();
bool Cut(); bool Cut();
bool Copy(); bool Copy();
@ -145,8 +177,8 @@ public:
void HyperFlush(); void HyperFlush();
void HyperHome(char *filename); void HyperHome(char *filename);
bool HyperTest(EventMsg event); bool HyperTest(EventType event);
bool HyperGo(EventMsg event); bool HyperGo(EventType event);
void SetFontSize(float size); void SetFontSize(float size);
@ -189,7 +221,7 @@ protected:
bool Shift(bool bLeft); bool Shift(bool bLeft);
bool MinMaj(bool bMaj); bool MinMaj(bool bMaj);
void Justif(); void Justif();
int RetCursorLine(int cursor); int GetCursorLine(int cursor);
void UndoFlush(); void UndoFlush();
void UndoMemorize(OperUndo oper); void UndoMemorize(OperUndo oper);
@ -246,3 +278,4 @@ protected:
}; };
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * it under the terms of the GNU General Public License as published by
@ -17,13 +18,13 @@
// editvalue.cpp // editvalue.cpp
#include <windows.h> //#include <windows.h>
#include <stdio.h> //#include <stdio.h>
#include <d3d.h> //#include <d3d.h>
#include "common/struct.h" //#include "common/struct.h"
#include "old/d3dengine.h" //#include "old/d3dengine.h"
#include "old/math3d.h" //#include "old/math3d.h"
#include "common/event.h" #include "common/event.h"
#include "common/misc.h" #include "common/misc.h"
#include "common/iman.h" #include "common/iman.h"
@ -33,10 +34,11 @@
namespace Ui {
// Object's constructor. // Object's constructor.
CEditValue::CEditValue(CInstanceManager* iMan) : CControl(iMan) //CEditValue::CEditValue(CInstanceManager* iMan) : CControl(iMan)
CEditValue::CEditValue() : CControl ()
{ {
m_edit = 0; m_edit = 0;
m_buttonUp = 0; m_buttonUp = 0;
@ -60,28 +62,28 @@ CEditValue::~CEditValue()
// Creates a new button. // Creates a new button.
bool CEditValue::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) bool CEditValue::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType)
{ {
CEdit* pe; Ui::CEdit* pe;
CButton* pc; Ui::CButton* pc;
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
CControl::Create(pos, dim, icon, eventMsg); CControl::Create(pos, dim, icon, eventType);
GlintDelete(); GlintDelete();
m_edit = new CEdit(m_iMan); m_edit = new Ui::CEdit();
pe = (CEdit*)m_edit; pe = static_cast<Ui::CEdit*>(m_edit);
pe->Create(pos, dim, 0, EVENT_NULL); pe->Create(pos, dim, 0, EVENT_NULL);
pe->SetMaxChar(4); pe->SetMaxChar(4);
m_buttonUp = new CButton(m_iMan); m_buttonUp = new Ui::CButton();
pc = (CButton*)m_buttonUp; pc = static_cast<Ui::CButton*>(m_buttonUp);
pc->Create(pos, dim, 49, EVENT_NULL); // ^ pc->Create(pos, dim, 49, EVENT_NULL); // ^
pc->SetRepeat(true); pc->SetRepeat(true);
m_buttonDown = new CButton(m_iMan); m_buttonDown = new Ui::CButton();
pc = (CButton*)m_buttonDown; pc = static_cast<Ui::CButton*>(m_buttonDown);
pc->Create(pos, dim, 50, EVENT_NULL); // v pc->Create(pos, dim, 50, EVENT_NULL); // v
pc->SetRepeat(true); pc->SetRepeat(true);
@ -151,11 +153,11 @@ bool CEditValue::EventProcess(const Event &event)
if ( m_edit != 0 ) if ( m_edit != 0 )
{ {
if ( m_edit->RetFocus() && if ( m_edit->GetFocus() &&
event.event == EVENT_KEYDOWN && event.type == EVENT_KEY_DOWN &&
event.param == VK_RETURN ) event.param == KEY(RETURN) )
{ {
value = RetValue(); value = GetValue();
if ( value > m_maxValue ) value = m_maxValue; if ( value > m_maxValue ) value = m_maxValue;
if ( value < m_minValue ) value = m_minValue; if ( value < m_minValue ) value = m_minValue;
SetValue(value, true); SetValue(value, true);
@ -163,19 +165,18 @@ bool CEditValue::EventProcess(const Event &event)
} }
if ( !m_edit->EventProcess(event) ) return false; if ( !m_edit->EventProcess(event) ) return false;
if ( event.event == m_edit->RetEventMsg() ) if ( event.type == m_edit->GetEventType() )
{ {
Event newEvent; Event newEvent(m_eventType);
m_event->MakeEvent(newEvent, m_eventMsg);
m_event->AddEvent(newEvent); m_event->AddEvent(newEvent);
} }
} }
if ( m_buttonUp != 0 ) if ( m_buttonUp != 0 )
{ {
if ( event.event == m_buttonUp->RetEventMsg() ) if ( event.type == m_buttonUp->GetEventType() )
{ {
value = RetValue()+m_stepValue; value = GetValue()+m_stepValue;
if ( value > m_maxValue ) value = m_maxValue; if ( value > m_maxValue ) value = m_maxValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -185,9 +186,9 @@ bool CEditValue::EventProcess(const Event &event)
if ( m_buttonDown != 0 ) if ( m_buttonDown != 0 )
{ {
if ( event.event == m_buttonDown->RetEventMsg() ) if ( event.type == m_buttonDown->GetEventType() )
{ {
value = RetValue()-m_stepValue; value = GetValue()-m_stepValue;
if ( value < m_minValue ) value = m_minValue; if ( value < m_minValue ) value = m_minValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -195,20 +196,20 @@ bool CEditValue::EventProcess(const Event &event)
if ( !m_buttonDown->EventProcess(event) ) return false; if ( !m_buttonDown->EventProcess(event) ) return false;
} }
if ( event.event == EVENT_KEYDOWN && if ( event.type == EVENT_KEY_DOWN &&
event.param == VK_WHEELUP && event.mouseButton.button == 4 &&
Detect(event.pos) ) Detect(event.pos) )
{ {
value = RetValue()+m_stepValue; value = GetValue()+m_stepValue;
if ( value > m_maxValue ) value = m_maxValue; if ( value > m_maxValue ) value = m_maxValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
} }
if ( event.event == EVENT_KEYDOWN && if ( event.type == EVENT_KEY_DOWN &&
event.param == VK_WHEELDOWN && event.mouseButton.button == 5 &&
Detect(event.pos) ) Detect(event.pos) )
{ {
value = RetValue()-m_stepValue; value = GetValue()-m_stepValue;
if ( value < m_minValue ) value = m_minValue; if ( value < m_minValue ) value = m_minValue;
SetValue(value, true); SetValue(value, true);
HiliteValue(event); HiliteValue(event);
@ -226,7 +227,7 @@ void CEditValue::HiliteValue(const Event &event)
if ( m_edit == 0 ) return; if ( m_edit == 0 ) return;
pos = m_edit->RetTextLength(); pos = m_edit->GetTextLength();
if ( m_type == EVT_100 && pos > 0 ) if ( m_type == EVT_100 && pos > 0 )
{ {
pos --; // not only selects the "%" pos --; // not only selects the "%"
@ -236,8 +237,9 @@ void CEditValue::HiliteValue(const Event &event)
m_edit->SetFocus(true); m_edit->SetFocus(true);
Event newEvent = event; Event newEvent = event;
newEvent.event = EVENT_FOCUS; newEvent.type = EVENT_ACTIVE;
newEvent.param = m_edit->RetEventMsg(); newEvent.active.gain = true; // TODO not much pretty sure about it
newEvent.param = m_edit->GetEventType();
m_event->AddEvent(newEvent); // defocus the other objects m_event->AddEvent(newEvent); // defocus the other objects
} }
@ -275,7 +277,7 @@ void CEditValue::SetType(EditValueType type)
m_type = type; m_type = type;
} }
EditValueType CEditValue::RetType() EditValueType CEditValue::GetType()
{ {
return m_type; return m_type;
} }
@ -310,15 +312,14 @@ void CEditValue::SetValue(float value, bool bSendMessage)
if ( bSendMessage ) if ( bSendMessage )
{ {
Event newEvent; Event newEvent(m_eventType);
m_event->MakeEvent(newEvent, m_eventMsg);
m_event->AddEvent(newEvent); m_event->AddEvent(newEvent);
} }
} }
// Return the edited value. // Return the edited value.
float CEditValue::RetValue() float CEditValue::GetValue()
{ {
char text[100]; char text[100];
float value; float value;
@ -345,7 +346,7 @@ void CEditValue::SetStepValue(float value)
m_stepValue = value; m_stepValue = value;
} }
float CEditValue::RetStepValue() float CEditValue::GetStepValue()
{ {
return m_stepValue; return m_stepValue;
} }
@ -358,7 +359,7 @@ void CEditValue::SetMinValue(float value)
m_minValue = value; m_minValue = value;
} }
float CEditValue::RetMinValue() float CEditValue::GetMinValue()
{ {
return m_minValue; return m_minValue;
} }
@ -371,8 +372,9 @@ void CEditValue::SetMaxValue(float value)
m_maxValue = value; m_maxValue = value;
} }
float CEditValue::RetMaxValue() float CEditValue::GetMaxValue()
{ {
return m_maxValue; return m_maxValue;
} }
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * it under the terms of the GNU General Public License as published by
@ -22,6 +23,12 @@
#include "ui/control.h" #include "ui/control.h"
namespace Gfx{
class CEngine;
}
namespace Ui {
enum EditValueType enum EditValueType
{ {
EVT_INT = 1, // integer EVT_INT = 1, // integer
@ -29,8 +36,6 @@ enum EditValueType
EVT_100 = 3, // percent (0 .. 1) EVT_100 = 3, // percent (0 .. 1)
}; };
class CD3DEngine;
class CEdit; class CEdit;
class CButton; class CButton;
@ -39,10 +44,11 @@ class CButton;
class CEditValue : public CControl class CEditValue : public CControl
{ {
public: public:
CEditValue(CInstanceManager* iMan); // CEditValue(CInstanceManager* iMan);
CEditValue();
virtual ~CEditValue(); virtual ~CEditValue();
bool Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg); bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
void SetPos(Math::Point pos); void SetPos(Math::Point pos);
void SetDim(Math::Point dim); void SetDim(Math::Point dim);
@ -51,28 +57,28 @@ public:
void Draw(); void Draw();
void SetType(EditValueType type); void SetType(EditValueType type);
EditValueType RetType(); EditValueType GetType();
void SetValue(float value, bool bSendMessage=false); void SetValue(float value, bool bSendMessage=false);
float RetValue(); float GetValue();
void SetStepValue(float value); void SetStepValue(float value);
float RetStepValue(); float GetStepValue();
void SetMinValue(float value); void SetMinValue(float value);
float RetMinValue(); float GetMinValue();
void SetMaxValue(float value); void SetMaxValue(float value);
float RetMaxValue(); float GetMaxValue();
protected: protected:
void MoveAdjust(); void MoveAdjust();
void HiliteValue(const Event &event); void HiliteValue(const Event &event);
protected: protected:
CEdit* m_edit; Ui::CEdit* m_edit;
CButton* m_buttonUp; Ui::CButton* m_buttonUp;
CButton* m_buttonDown; Ui::CButton* m_buttonDown;
EditValueType m_type; EditValueType m_type;
float m_stepValue; float m_stepValue;
@ -81,3 +87,4 @@ protected:
}; };
}