UI porting
parent
574c07e388
commit
8666d35f7c
470
src/ui/edit.cpp
470
src/ui/edit.cpp
File diff suppressed because it is too large
Load Diff
123
src/ui/edit.h
123
src/ui/edit.h
|
@ -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
|
||||
|
@ -14,69 +15,99 @@
|
|||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
// edit.h
|
||||
|
||||
/**
|
||||
* \file ui/edit.h
|
||||
* \brief CEdit class
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "common/struct.h"
|
||||
//#include "common/struct.h"
|
||||
#include "ui/control.h"
|
||||
|
||||
namespace Gfx{
|
||||
class CEngine;
|
||||
};
|
||||
|
||||
class CD3DEngine;
|
||||
namespace Ui {
|
||||
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
|
||||
const int EDITLINEMAX = 1000; // maximum total number of lines
|
||||
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
|
||||
//! max number of successive undo
|
||||
const int EDITUNDOMAX = 20;
|
||||
|
||||
struct EditUndo
|
||||
{
|
||||
char* text; // original text
|
||||
int len; // length of the text
|
||||
int cursor1; // offset cursor
|
||||
int cursor2; // offset cursor
|
||||
int lineFirst; // the first line displayed.
|
||||
//! original text
|
||||
char* text;
|
||||
//! length of the text
|
||||
int len;
|
||||
//! offset cursor
|
||||
int cursor1;
|
||||
//! offset cursor
|
||||
int cursor2;
|
||||
//! the first line displayed.
|
||||
int lineFirst;
|
||||
|
||||
};
|
||||
|
||||
enum OperUndo
|
||||
{
|
||||
OPERUNDO_SPEC = 0, // special operation
|
||||
OPERUNDO_INSERT = 1, // inserting characters
|
||||
OPERUNDO_DELETE = 2, // deleting characters
|
||||
//! special operation
|
||||
OPERUNDO_SPEC = 0,
|
||||
//! inserting characters
|
||||
OPERUNDO_INSERT = 1,
|
||||
//! deleting characters
|
||||
OPERUNDO_DELETE = 2,
|
||||
};
|
||||
|
||||
struct ImageLine
|
||||
{
|
||||
char name[40]; // name of the image (without diagram \)
|
||||
float offset; // vertical offset (v texture)
|
||||
float height; // height of the part (dv texture)
|
||||
float width; // width
|
||||
//! name of the image (without diagram \)
|
||||
char name[40];
|
||||
//! vertical offset (v texture)
|
||||
float offset;
|
||||
//! height of the part (dv texture)
|
||||
float height;
|
||||
//! width
|
||||
float width;
|
||||
};
|
||||
|
||||
struct HyperLink
|
||||
{
|
||||
char name[40]; // text file name (without help \)
|
||||
char marker[20]; // name of the marker
|
||||
//! text file name (without help \)
|
||||
char name[40];
|
||||
//! name of the marker
|
||||
char marker[20];
|
||||
};
|
||||
|
||||
struct HyperMarker
|
||||
{
|
||||
char name[20]; // name of the marker
|
||||
int pos; // position in the text
|
||||
//! name of the marker
|
||||
char name[20];
|
||||
//! position in the text
|
||||
int pos;
|
||||
};
|
||||
|
||||
struct HyperHistory
|
||||
{
|
||||
char filename[50]; // full file name text
|
||||
int firstLine; // rank of the first displayed line
|
||||
//! full file name text
|
||||
char filename[50];
|
||||
//! rank of the first displayed line
|
||||
int firstLine;
|
||||
};
|
||||
|
||||
|
||||
|
@ -85,10 +116,11 @@ struct HyperHistory
|
|||
class CEdit : public CControl
|
||||
{
|
||||
public:
|
||||
CEdit(CInstanceManager* iMan);
|
||||
// CEdit(CInstanceManager* iMan);
|
||||
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 SetDim(Math::Point dim);
|
||||
|
@ -98,45 +130,45 @@ public:
|
|||
|
||||
void SetText(char *text, bool bNew=true);
|
||||
void GetText(char *buffer, int max);
|
||||
char* RetText();
|
||||
int RetTextLength();
|
||||
char* GetText();
|
||||
int GetTextLength();
|
||||
|
||||
bool ReadText(char *filename, int addSize=0);
|
||||
bool WriteText(char *filename);
|
||||
|
||||
void SetMaxChar(int max);
|
||||
int RetMaxChar();
|
||||
int GetMaxChar();
|
||||
|
||||
void SetEditCap(bool bMode);
|
||||
bool RetEditCap();
|
||||
bool GetEditCap();
|
||||
|
||||
void SetHiliteCap(bool bEnable);
|
||||
bool RetHiliteCap();
|
||||
bool GetHiliteCap();
|
||||
|
||||
void SetInsideScroll(bool bInside);
|
||||
bool RetInsideScroll();
|
||||
bool GetInsideScroll();
|
||||
|
||||
void SetSoluceMode(bool bSoluce);
|
||||
bool RetSoluceMode();
|
||||
bool GetSoluceMode();
|
||||
|
||||
void SetGenericMode(bool bGeneric);
|
||||
bool RetGenericMode();
|
||||
bool GetGenericMode();
|
||||
|
||||
void SetAutoIndent(bool bMode);
|
||||
bool RetAutoIndent();
|
||||
bool GetAutoIndent();
|
||||
|
||||
void SetCursor(int cursor1, int cursor2);
|
||||
void GetCursor(int &cursor1, int &cursor2);
|
||||
|
||||
void SetFirstLine(int rank);
|
||||
int RetFirstLine();
|
||||
int GetFirstLine();
|
||||
void ShowSelect();
|
||||
|
||||
void SetDisplaySpec(bool bDisplay);
|
||||
bool RetDisplaySpec();
|
||||
bool GetDisplaySpec();
|
||||
|
||||
void SetMultiFont(bool bMulti);
|
||||
bool RetMultiFont();
|
||||
bool GetMultiFont();
|
||||
|
||||
bool Cut();
|
||||
bool Copy();
|
||||
|
@ -145,8 +177,8 @@ public:
|
|||
|
||||
void HyperFlush();
|
||||
void HyperHome(char *filename);
|
||||
bool HyperTest(EventMsg event);
|
||||
bool HyperGo(EventMsg event);
|
||||
bool HyperTest(EventType event);
|
||||
bool HyperGo(EventType event);
|
||||
|
||||
void SetFontSize(float size);
|
||||
|
||||
|
@ -189,7 +221,7 @@ protected:
|
|||
bool Shift(bool bLeft);
|
||||
bool MinMaj(bool bMaj);
|
||||
void Justif();
|
||||
int RetCursorLine(int cursor);
|
||||
int GetCursorLine(int cursor);
|
||||
|
||||
void UndoFlush();
|
||||
void UndoMemorize(OperUndo oper);
|
||||
|
@ -246,3 +278,4 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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,13 +18,13 @@
|
|||
// editvalue.cpp
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <d3d.h>
|
||||
//#include <windows.h>
|
||||
//#include <stdio.h>
|
||||
//#include <d3d.h>
|
||||
|
||||
#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 "common/event.h"
|
||||
#include "common/misc.h"
|
||||
#include "common/iman.h"
|
||||
|
@ -33,10 +34,11 @@
|
|||
|
||||
|
||||
|
||||
|
||||
namespace Ui {
|
||||
// Object's constructor.
|
||||
|
||||
CEditValue::CEditValue(CInstanceManager* iMan) : CControl(iMan)
|
||||
//CEditValue::CEditValue(CInstanceManager* iMan) : CControl(iMan)
|
||||
CEditValue::CEditValue() : CControl ()
|
||||
{
|
||||
m_edit = 0;
|
||||
m_buttonUp = 0;
|
||||
|
@ -60,28 +62,28 @@ CEditValue::~CEditValue()
|
|||
|
||||
// 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;
|
||||
CButton* pc;
|
||||
Ui::CEdit* pe;
|
||||
Ui::CButton* pc;
|
||||
|
||||
if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg();
|
||||
CControl::Create(pos, dim, icon, eventMsg);
|
||||
if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType();
|
||||
CControl::Create(pos, dim, icon, eventType);
|
||||
|
||||
GlintDelete();
|
||||
|
||||
m_edit = new CEdit(m_iMan);
|
||||
pe = (CEdit*)m_edit;
|
||||
m_edit = new Ui::CEdit();
|
||||
pe = static_cast<Ui::CEdit*>(m_edit);
|
||||
pe->Create(pos, dim, 0, EVENT_NULL);
|
||||
pe->SetMaxChar(4);
|
||||
|
||||
m_buttonUp = new CButton(m_iMan);
|
||||
pc = (CButton*)m_buttonUp;
|
||||
m_buttonUp = new Ui::CButton();
|
||||
pc = static_cast<Ui::CButton*>(m_buttonUp);
|
||||
pc->Create(pos, dim, 49, EVENT_NULL); // ^
|
||||
pc->SetRepeat(true);
|
||||
|
||||
m_buttonDown = new CButton(m_iMan);
|
||||
pc = (CButton*)m_buttonDown;
|
||||
m_buttonDown = new Ui::CButton();
|
||||
pc = static_cast<Ui::CButton*>(m_buttonDown);
|
||||
pc->Create(pos, dim, 50, EVENT_NULL); // v
|
||||
pc->SetRepeat(true);
|
||||
|
||||
|
@ -151,11 +153,11 @@ bool CEditValue::EventProcess(const Event &event)
|
|||
|
||||
if ( m_edit != 0 )
|
||||
{
|
||||
if ( m_edit->RetFocus() &&
|
||||
event.event == EVENT_KEYDOWN &&
|
||||
event.param == VK_RETURN )
|
||||
if ( m_edit->GetFocus() &&
|
||||
event.type == EVENT_KEY_DOWN &&
|
||||
event.param == KEY(RETURN) )
|
||||
{
|
||||
value = RetValue();
|
||||
value = GetValue();
|
||||
if ( value > m_maxValue ) value = m_maxValue;
|
||||
if ( value < m_minValue ) value = m_minValue;
|
||||
SetValue(value, true);
|
||||
|
@ -163,19 +165,18 @@ bool CEditValue::EventProcess(const Event &event)
|
|||
}
|
||||
if ( !m_edit->EventProcess(event) ) return false;
|
||||
|
||||
if ( event.event == m_edit->RetEventMsg() )
|
||||
if ( event.type == m_edit->GetEventType() )
|
||||
{
|
||||
Event newEvent;
|
||||
m_event->MakeEvent(newEvent, m_eventMsg);
|
||||
Event newEvent(m_eventType);
|
||||
m_event->AddEvent(newEvent);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
SetValue(value, true);
|
||||
HiliteValue(event);
|
||||
|
@ -185,9 +186,9 @@ bool CEditValue::EventProcess(const Event &event)
|
|||
|
||||
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;
|
||||
SetValue(value, true);
|
||||
HiliteValue(event);
|
||||
|
@ -195,20 +196,20 @@ bool CEditValue::EventProcess(const Event &event)
|
|||
if ( !m_buttonDown->EventProcess(event) ) return false;
|
||||
}
|
||||
|
||||
if ( event.event == EVENT_KEYDOWN &&
|
||||
event.param == VK_WHEELUP &&
|
||||
if ( event.type == EVENT_KEY_DOWN &&
|
||||
event.mouseButton.button == 4 &&
|
||||
Detect(event.pos) )
|
||||
{
|
||||
value = RetValue()+m_stepValue;
|
||||
value = GetValue()+m_stepValue;
|
||||
if ( value > m_maxValue ) value = m_maxValue;
|
||||
SetValue(value, true);
|
||||
HiliteValue(event);
|
||||
}
|
||||
if ( event.event == EVENT_KEYDOWN &&
|
||||
event.param == VK_WHEELDOWN &&
|
||||
if ( event.type == EVENT_KEY_DOWN &&
|
||||
event.mouseButton.button == 5 &&
|
||||
Detect(event.pos) )
|
||||
{
|
||||
value = RetValue()-m_stepValue;
|
||||
value = GetValue()-m_stepValue;
|
||||
if ( value < m_minValue ) value = m_minValue;
|
||||
SetValue(value, true);
|
||||
HiliteValue(event);
|
||||
|
@ -226,7 +227,7 @@ void CEditValue::HiliteValue(const Event &event)
|
|||
|
||||
if ( m_edit == 0 ) return;
|
||||
|
||||
pos = m_edit->RetTextLength();
|
||||
pos = m_edit->GetTextLength();
|
||||
if ( m_type == EVT_100 && pos > 0 )
|
||||
{
|
||||
pos --; // not only selects the "%"
|
||||
|
@ -236,8 +237,9 @@ void CEditValue::HiliteValue(const Event &event)
|
|||
m_edit->SetFocus(true);
|
||||
|
||||
Event newEvent = event;
|
||||
newEvent.event = EVENT_FOCUS;
|
||||
newEvent.param = m_edit->RetEventMsg();
|
||||
newEvent.type = EVENT_ACTIVE;
|
||||
newEvent.active.gain = true; // TODO not much pretty sure about it
|
||||
newEvent.param = m_edit->GetEventType();
|
||||
m_event->AddEvent(newEvent); // defocus the other objects
|
||||
}
|
||||
|
||||
|
@ -275,7 +277,7 @@ void CEditValue::SetType(EditValueType type)
|
|||
m_type = type;
|
||||
}
|
||||
|
||||
EditValueType CEditValue::RetType()
|
||||
EditValueType CEditValue::GetType()
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
@ -310,15 +312,14 @@ void CEditValue::SetValue(float value, bool bSendMessage)
|
|||
|
||||
if ( bSendMessage )
|
||||
{
|
||||
Event newEvent;
|
||||
m_event->MakeEvent(newEvent, m_eventMsg);
|
||||
Event newEvent(m_eventType);
|
||||
m_event->AddEvent(newEvent);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the edited value.
|
||||
|
||||
float CEditValue::RetValue()
|
||||
float CEditValue::GetValue()
|
||||
{
|
||||
char text[100];
|
||||
float value;
|
||||
|
@ -345,7 +346,7 @@ void CEditValue::SetStepValue(float value)
|
|||
m_stepValue = value;
|
||||
}
|
||||
|
||||
float CEditValue::RetStepValue()
|
||||
float CEditValue::GetStepValue()
|
||||
{
|
||||
return m_stepValue;
|
||||
}
|
||||
|
@ -358,7 +359,7 @@ void CEditValue::SetMinValue(float value)
|
|||
m_minValue = value;
|
||||
}
|
||||
|
||||
float CEditValue::RetMinValue()
|
||||
float CEditValue::GetMinValue()
|
||||
{
|
||||
return m_minValue;
|
||||
}
|
||||
|
@ -371,8 +372,9 @@ void CEditValue::SetMaxValue(float value)
|
|||
m_maxValue = value;
|
||||
}
|
||||
|
||||
float CEditValue::RetMaxValue()
|
||||
float CEditValue::GetMaxValue()
|
||||
{
|
||||
return m_maxValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -22,6 +23,12 @@
|
|||
#include "ui/control.h"
|
||||
|
||||
|
||||
namespace Gfx{
|
||||
class CEngine;
|
||||
}
|
||||
|
||||
namespace Ui {
|
||||
|
||||
enum EditValueType
|
||||
{
|
||||
EVT_INT = 1, // integer
|
||||
|
@ -29,8 +36,6 @@ enum EditValueType
|
|||
EVT_100 = 3, // percent (0 .. 1)
|
||||
};
|
||||
|
||||
|
||||
class CD3DEngine;
|
||||
class CEdit;
|
||||
class CButton;
|
||||
|
||||
|
@ -39,10 +44,11 @@ class CButton;
|
|||
class CEditValue : public CControl
|
||||
{
|
||||
public:
|
||||
CEditValue(CInstanceManager* iMan);
|
||||
// CEditValue(CInstanceManager* iMan);
|
||||
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 SetDim(Math::Point dim);
|
||||
|
@ -51,28 +57,28 @@ public:
|
|||
void Draw();
|
||||
|
||||
void SetType(EditValueType type);
|
||||
EditValueType RetType();
|
||||
EditValueType GetType();
|
||||
|
||||
void SetValue(float value, bool bSendMessage=false);
|
||||
float RetValue();
|
||||
float GetValue();
|
||||
|
||||
void SetStepValue(float value);
|
||||
float RetStepValue();
|
||||
float GetStepValue();
|
||||
|
||||
void SetMinValue(float value);
|
||||
float RetMinValue();
|
||||
float GetMinValue();
|
||||
|
||||
void SetMaxValue(float value);
|
||||
float RetMaxValue();
|
||||
float GetMaxValue();
|
||||
|
||||
protected:
|
||||
void MoveAdjust();
|
||||
void HiliteValue(const Event &event);
|
||||
|
||||
protected:
|
||||
CEdit* m_edit;
|
||||
CButton* m_buttonUp;
|
||||
CButton* m_buttonDown;
|
||||
Ui::CEdit* m_edit;
|
||||
Ui::CButton* m_buttonUp;
|
||||
Ui::CButton* m_buttonDown;
|
||||
|
||||
EditValueType m_type;
|
||||
float m_stepValue;
|
||||
|
@ -81,3 +87,4 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue