From 8666d35f7c3129c101029eae1cd0a5124f35b7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Konopacki?= Date: Mon, 20 Aug 2012 14:05:36 +0200 Subject: UI porting --- src/ui/edit.cpp | 470 ++++++++++++++++++++++++++------------------------- src/ui/edit.h | 123 +++++++++----- src/ui/editvalue.cpp | 94 ++++++----- src/ui/editvalue.h | 31 ++-- 4 files changed, 383 insertions(+), 335 deletions(-) (limited to 'src/ui') diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index 58a8b7d..86f0011 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.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 @@ -20,34 +21,41 @@ #include #include #include -#include -#include +//#include +//#include -#include "common/struct.h" -#include "old/d3dengine.h" +//#include "common/struct.h" +//#include "old/d3dengine.h" +#include "graphics/engine/engine.h" #include "common/language.h" -#include "old/math3d.h" +//#include "old/math3d.h" #include "common/event.h" #include "common/misc.h" #include "common/iman.h" #include "common/restext.h" #include "ui/scroll.h" -#include "old/text.h" +//#include "old/text.h" +#include "graphics/engine/text.h" +//#include "graphics/engine/color.h" #include "ui/edit.h" +namespace Ui { const float MARGX = (5.0f/640.0f); const float MARGY = (5.0f/480.0f); const float MARGYS = (4.0f/480.0f); const float MARGY1 = (1.0f/480.0f); -const float DELAY_DBCLICK = 0.3f; // time limit for double-click -const float DELAY_SCROLL = 0.1f; // time limit for scroll -const float BIG_FONT = 1.6f; // expansion for \b; +//! time limit for double-click +const float DELAY_DBCLICK = 0.3f; +//! time limit for scroll +const float DELAY_SCROLL = 0.1f; +//! expansion for \b; +const float BIG_FONT = 1.6f; -// Indicates whether a character is a space. +//! Indicates whether a character is a space. bool IsSpace(int character) { @@ -56,20 +64,20 @@ bool IsSpace(int character) character == '\n' ); } -// Indicates whether a character is part of a word. +//! Indicates whether a character is part of a word. bool IsWord(int character) { char c; - c = tolower(RetNoAccent(character)); + c = tolower(GetNoAccent(character)); return ( (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' ); } -// Indicates whether a character is a word separator. +//! Indicates whether a character is a word separator. bool IsSep(int character) { @@ -79,19 +87,20 @@ bool IsSep(int character) -// Object's constructor. +//! Object's constructor. -CEdit::CEdit(CInstanceManager* iMan) : CControl(iMan) +//CEdit::CEdit(CInstanceManager* iMan) : CControl(iMan) +CEdit::CEdit () : CControl () { Math::Point pos; int i; m_maxChar = 100; - m_text = (char*)malloc(sizeof(char)*(m_maxChar+1)); + m_text = new char* [sizeof(char)*(m_maxChar+1)]; // TODO m_format = 0; m_len = 0; - m_fontType = FONT_COURIER; + m_fontType = Gfx::FONT_COURIER; m_scroll = 0; m_bEdit = true; m_bHilite = true; @@ -137,13 +146,13 @@ CEdit::~CEdit() // Creates a new editable line. -bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg) +bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) { CScroll* pc; Math::Point start, end; - if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg(); - CControl::Create(pos, dim, icon, eventMsg); + if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); + CControl::Create(pos, dim, icon, eventType); m_len = 0; m_lineFirst = 0; @@ -162,8 +171,8 @@ bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventMsg eventMsg { m_bMulti = true; MoveAdjust(); // readjusts multi-line mode - m_scroll = new CScroll(m_iMan); - pc = (CScroll*)m_scroll; + m_scroll = new Ui::CScroll(); + pc = static_cast(m_scroll); pc->Create(pos, dim, -1, EVENT_NULL); MoveAdjust(); } @@ -189,25 +198,25 @@ void CEdit::MoveAdjust() Math::Point pos, dim; float height; - m_lineDescent = m_engine->RetText()->RetDescent(m_fontSize, m_fontType); - m_lineAscent = m_engine->RetText()->RetAscent(m_fontSize, m_fontType); - m_lineHeight = m_engine->RetText()->RetHeight(m_fontSize, m_fontType); + m_lineDescent = m_engine->GetText()->GetDescent(m_fontType, m_fontSize); + m_lineAscent = m_engine->GetText()->GetAscent(m_fontType, m_fontSize); + m_lineHeight = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); height = m_dim.y-(m_bMulti?MARGY*2.0f:MARGY1); - m_lineVisible = (int)(height/m_lineHeight); + m_lineVisible = static_cast((height/m_lineHeight)); if ( m_scroll != 0 ) { if ( m_bInsideScroll ) { - pos.x = m_pos.x+m_dim.x-MARGX-SCROLL_WIDTH; - pos.y = m_pos.y+MARGYS; + pos.x = m_pos.x + m_dim.x - MARGX-SCROLL_WIDTH; + pos.y = m_pos.y + MARGYS; dim.x = SCROLL_WIDTH; - dim.y = m_dim.y-MARGYS*2.0f; + dim.y = m_dim.y - MARGYS*2.0f; } else { - pos.x = m_pos.x+m_dim.x-SCROLL_WIDTH; + pos.x = m_pos.x + m_dim.x - SCROLL_WIDTH; pos.y = m_pos.y; dim.x = SCROLL_WIDTH; dim.y = m_dim.y; @@ -238,15 +247,15 @@ bool CEdit::EventProcess(const Event &event) if ( (m_state & STATE_VISIBLE) == 0 ) return true; - if ( event.event == EVENT_KEYDOWN && - event.param == VK_WHEELUP && + if ( event.type == EVENT_KEY_DOWN && + event.mouseButton.button == 5 && Detect(event.pos) ) { Scroll(m_lineFirst-3, true); return true; } - if ( event.event == EVENT_KEYDOWN && - event.param == VK_WHEELDOWN && + if ( event.type == EVENT_KEY_DOWN && + event.mouseButton.button == 4 && // TODO Detect(event.pos) ) { Scroll(m_lineFirst+3, true); @@ -255,30 +264,30 @@ bool CEdit::EventProcess(const Event &event) CControl::EventProcess(event); - if ( event.event == EVENT_FRAME ) + if ( event.type == EVENT_FRAME ) { m_time += event.rTime; m_timeBlink += event.rTime; } - if ( event.event == EVENT_MOUSEMOVE ) + if ( event.type == EVENT_MOUSE_MOVE ) { if ( Detect(event.pos) && event.pos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) ) { if ( m_bEdit ) { - m_engine->SetMouseType(D3DMOUSEEDIT); + m_engine->SetMouseType(Gfx::ENG_MOUSE_EDIT); } else { if ( IsLinkPos(event.pos) ) { - m_engine->SetMouseType(D3DMOUSEHAND); + m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND); } else { - m_engine->SetMouseType(D3DMOUSENORM); + m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); } } } @@ -288,32 +297,32 @@ bool CEdit::EventProcess(const Event &event) { m_scroll->EventProcess(event); - if ( event.event == m_scroll->RetEventMsg() ) + if ( event.type == m_scroll->GetEventType() ) { Scroll(); return true; } } - if ( event.event == EVENT_KEYDOWN && m_bFocus ) + if ( event.type == EVENT_KEY_DOWN && m_bFocus ) { bShift = (event.keyState&KS_SHIFT); bControl = (event.keyState&KS_CONTROL); if ( (event.param == 'X' && !bShift && bControl) || - (event.param == VK_DELETE && bShift && !bControl) ) + (event.param == KEY(DELETE) && bShift && !bControl) ) { Cut(); return true; } if ( (event.param == 'C' && !bShift && bControl) || - (event.param == VK_INSERT && !bShift && bControl) ) + (event.param == KEY(INSERT) && !bShift && bControl) ) { Copy(); return true; } if ( (event.param == 'V' && !bShift && bControl) || - (event.param == VK_INSERT && bShift && !bControl) ) + (event.param == KEY(INSERT) && bShift && !bControl) ) { Paste(); return true; @@ -327,14 +336,14 @@ bool CEdit::EventProcess(const Event &event) if ( event.param == 'O' && !bShift && bControl ) { - Event newEvent; - m_event->MakeEvent(newEvent, EVENT_STUDIO_OPEN); + Event newEvent(EVENT_STUDIO_OPEN); +// m_event->NewEvent(newEvent, EVENT_STUDIO_OPEN); m_event->AddEvent(newEvent); } if ( event.param == 'S' && !bShift && bControl ) { - Event newEvent; - m_event->MakeEvent(newEvent, EVENT_STUDIO_SAVE); + Event newEvent( EVENT_STUDIO_SAVE ); +// m_event->MakeEvent(newEvent, EVENT_STUDIO_SAVE); m_event->AddEvent(newEvent); } @@ -353,44 +362,44 @@ bool CEdit::EventProcess(const Event &event) if ( MinMaj(true) ) return true; } - if ( event.param == VK_TAB && !bShift && !bControl && !m_bAutoIndent ) + if ( event.param == KEY(TAB) && !bShift && !bControl && !m_bAutoIndent ) { if ( Shift(false) ) return true; } - if ( event.param == VK_TAB && bShift && !bControl && !m_bAutoIndent ) + if ( event.param == KEY(TAB) && bShift && !bControl && !m_bAutoIndent ) { if ( Shift(true) ) return true; } if ( m_bEdit ) { - if ( event.param == VK_LEFT ) + if ( event.param == KEY(LEFT) ) { MoveChar(-1, bControl, bShift); return true; } - if ( event.param == VK_RIGHT ) + if ( event.param == KEY(RIGHT) ) { MoveChar(1, bControl, bShift); return true; } - if ( event.param == VK_UP ) + if ( event.param == KEY(UP) ) { MoveLine(-1, bControl, bShift); return true; } - if ( event.param == VK_DOWN ) + if ( event.param == KEY(DOWN) ) { MoveLine(1, bControl, bShift); return true; } - if ( event.param == VK_PRIOR ) // PageUp ? + if ( event.param == KEY(PAGEUP) ) // PageUp ? { MoveLine(-(m_lineVisible-1), bControl, bShift); return true; } - if ( event.param == VK_NEXT ) // PageDown ? + if ( event.param == KEY(PAGEDOWN) ) // PageDown ? { MoveLine(m_lineVisible-1, bControl, bShift); return true; @@ -398,62 +407,62 @@ bool CEdit::EventProcess(const Event &event) } else { - if ( event.param == VK_LEFT || - event.param == VK_UP ) + if ( event.param == KEY(LEFT) || + event.param == KEY(UP) ) { Scroll(m_lineFirst-1, true); return true; } - if ( event.param == VK_RIGHT || - event.param == VK_DOWN ) + if ( event.param == KEY(RIGHT) || + event.param == KEY(DOWN) ) { Scroll(m_lineFirst+1, true); return true; } - if ( event.param == VK_PRIOR ) // PageUp ? + if ( event.param == KEY(PAGEUP) ) // PageUp ? { Scroll(m_lineFirst-(m_lineVisible-1), true); return true; } - if ( event.param == VK_NEXT ) // PageDown ? + if ( event.param == KEY(PAGEDOWN) ) // PageDown ? { Scroll(m_lineFirst+(m_lineVisible-1), true); return true; } } - if ( event.param == VK_HOME ) + if ( event.param == KEY(HOME) ) { MoveHome(bControl, bShift); return true; } - if ( event.param == VK_END ) + if ( event.param == KEY(END) ) { MoveEnd(bControl, bShift); return true; } - if ( event.param == VK_BACK ) // backspace ( <- ) ? + if ( event.param == KEY(BACKSPACE) ) // backspace ( <- ) ? { Delete(-1); SendModifEvent(); return true; } - if ( event.param == VK_DELETE ) + if ( event.param == KEY(DELETE) ) { Delete(1); SendModifEvent(); return true; } - if ( event.param == VK_RETURN ) + if ( event.param == KEY(RETURN) ) { Insert('\n'); SendModifEvent(); return true; } - if ( event.param == VK_TAB ) + if ( event.param == KEY(TAB) ) { Insert('\t'); SendModifEvent(); @@ -461,7 +470,7 @@ bool CEdit::EventProcess(const Event &event) } } - if ( event.event == EVENT_CHAR && m_bFocus ) + if ( event.type == EVENT_ACTIVE && m_bFocus ) { if ( event.param >= ' ' && event.param <= 255 ) { @@ -471,9 +480,9 @@ bool CEdit::EventProcess(const Event &event) } } - if ( event.event == EVENT_FOCUS ) + if ( event.type == EVENT_ACTIVE ) { - if ( event.param == m_eventMsg ) + if ( event.param == m_eventType ) { m_bFocus = true; } @@ -483,7 +492,8 @@ bool CEdit::EventProcess(const Event &event) } } - if ( event.event == EVENT_LBUTTONDOWN ) + if ( event.type == EVENT_MOUSE_BUTTON_DOWN && + event.mouseButton.button == 1) { m_mouseFirstPos = event.pos; m_mouseLastPos = event.pos; @@ -502,18 +512,19 @@ bool CEdit::EventProcess(const Event &event) } } - if ( event.event == EVENT_MOUSEMOVE && m_bCapture ) + if ( event.type == EVENT_MOUSE_MOVE && m_bCapture ) { m_mouseLastPos = event.pos; MouseMove(event.pos); } - if ( event.event == EVENT_FRAME && m_bCapture ) + if ( event.type == EVENT_FRAME && m_bCapture ) { MouseMove(m_mouseLastPos); } - if ( event.event == EVENT_LBUTTONUP ) + if ( event.type == EVENT_MOUSE_BUTTON_UP && + event.mouseButton.button == 1) { if ( Detect(event.pos) ) { @@ -541,9 +552,9 @@ bool CEdit::EventProcess(const Event &event) void CEdit::SendModifEvent() { - Event newEvent; + Event newEvent (m_eventType); - m_event->MakeEvent(newEvent, m_eventMsg); +// m_event->MakeEvent(newEvent, m_eventType); m_event->AddEvent(newEvent); } @@ -560,7 +571,7 @@ bool CEdit::IsLinkPos(Math::Point pos) if ( i == -1 ) return false; if ( i >= m_len ) return false; - if ( (m_format[i]&COLOR_MASK) == COLOR_LINK ) return true; + if ( (m_format[i]& Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) return true; // TODO return false; } @@ -635,13 +646,13 @@ void CEdit::MouseRelease(Math::Point mouse) if ( !m_bEdit ) { if ( m_format != 0 && i < m_len && m_cursor1 == m_cursor2 && - (m_format[i]&COLOR_MASK) == COLOR_LINK ) + (m_format[i]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) //TODO { rank = -1; for ( j=0 ; j<=i ; j++ ) { - if ( (j == 0 || (m_format[j-1]&COLOR_MASK) != COLOR_LINK) && - (m_format[j+0]&COLOR_MASK) == COLOR_LINK ) + if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_HIGHLIGHT) != Gfx::FONT_HIGHLIGHT_LINK) && // TODO check if good + (m_format[j+0]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) // TODO { rank ++; } @@ -694,14 +705,14 @@ int CEdit::MouseDetect(Math::Point mouse) if ( m_bAutoIndent ) { - indentLength = m_engine->RetText()->RetCharWidth(' ', 0.0f, m_fontSize, m_fontStretch, m_fontType) - * m_engine->RetEditIndentValue(); + indentLength = m_engine->GetText()->GetCharWidth(static_cast(' '), m_fontType, m_fontSize, 0.0f) + * m_engine->GetEditIndentValue(); } pos.y = m_pos.y+m_dim.y-m_lineHeight-(m_bMulti?MARGY:MARGY1); for ( i=m_lineFirst ; i= m_lineFirst+m_lineVisible ) break; @@ -720,19 +731,21 @@ int CEdit::MouseDetect(Math::Point mouse) if ( m_format == 0 ) { - c = m_engine->RetText()->Detect(m_text+m_lineOffset[i], - len, offset, m_fontSize, - m_fontStretch, m_fontType); +// c = m_engine->GetText()->Detect(m_text+m_lineOffset[i], +// len, offset, m_fontSize, +// m_fontStretch, m_fontType); + c = m_engine->GetText()->Detect(m_text+m_lineOffset[i], m_fontType, m_fontSize, offset); // TODO check if good } else { size = m_fontSize; - if ( bTitle ) size *= BIG_FONT; + if ( bTitle ) size *= Gfx::FONT_SIZE_BIG; - c = m_engine->RetText()->Detect(m_text+m_lineOffset[i], - m_format+m_lineOffset[i], - len, offset, size, - m_fontStretch); +// c = m_engine->GetText()->Detect(m_text+m_lineOffset[i], +// m_format+m_lineOffset[i], +// len, offset, size, +// m_fontStretch); + c = m_engine->GetText()->Detect(m_text+m_lineOffset[i],m_format+m_lineOffset[i], size, offset); // TODO check if good } return m_lineOffset[i]+c; } @@ -827,7 +840,7 @@ bool CEdit::HyperAdd(char *filename, int firstLine) // Indicates whether a button EVENT_HYPER_ * is active or not. -bool CEdit::HyperTest(EventMsg event) +bool CEdit::HyperTest(EventType event) { if ( event == EVENT_HYPER_HOME ) { @@ -849,7 +862,7 @@ bool CEdit::HyperTest(EventMsg event) // Performs the action corresponding to a button EVENT_HYPER_ *. -bool CEdit::HyperGo(EventMsg event) +bool CEdit::HyperGo(EventType event) { if ( !HyperTest(event) ) return false; @@ -911,8 +924,8 @@ void CEdit::Draw() if ( m_bAutoIndent ) { - indentLength = m_engine->RetText()->RetCharWidth(' ', 0.0f, m_fontSize, m_fontStretch, m_fontType) - * m_engine->RetEditIndentValue(); + indentLength = m_engine->GetText()->GetCharWidth(static_cast(' '), m_fontType, m_fontSize, 0.0f) + * m_engine->GetEditIndentValue(); } pos.y = m_pos.y+m_dim.y-m_lineHeight-(m_bMulti?MARGY:MARGY1); @@ -933,7 +946,7 @@ void CEdit::Draw() for ( j=0 ; jRetText()->DrawText(&s, 1, pos, 1.0f, 1, m_fontSize, m_fontStretch, m_fontType, 0); + m_engine->GetText()->DrawText(&s, m_fontType, m_fontSize, pos, 1.0f, Gfx::TEXT_ALIGN_RIGHT, 0); pos.x += indentLength; } } @@ -946,7 +959,7 @@ void CEdit::Draw() // Headline \b;? if ( beg+len < m_len && m_format != 0 && - (m_format[beg]&TITLE_MASK) == TITLE_BIG ) + (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG ) { start.x = ppos.x-MARGX; end.x = dim.x-MARGX*2.0f; @@ -960,7 +973,7 @@ void CEdit::Draw() // As \t;? if ( beg+len < m_len && m_format != 0 && - (m_format[beg]&TITLE_MASK) == TITLE_NORM ) + (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_NORM ) { start.x = ppos.x-MARGX; end.x = dim.x-MARGX*2.0f; @@ -971,7 +984,7 @@ void CEdit::Draw() // Subtitle \s;? if ( beg+len < m_len && m_format != 0 && - (m_format[beg]&TITLE_MASK) == TITLE_LITTLE ) + (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_LITTLE ) { start.x = ppos.x-MARGX; end.x = dim.x-MARGX*2.0f; @@ -982,7 +995,7 @@ void CEdit::Draw() // Table \tab;? if ( beg+len < m_len && m_format != 0 && - (m_format[beg]&COLOR_MASK) == COLOR_TABLE ) + (m_format[beg]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_TABLE ) { start.x = ppos.x-MARGX; end.x = dim.x-MARGX*2.0f; @@ -993,21 +1006,21 @@ void CEdit::Draw() // Image \image; ? if ( beg+len < m_len && m_format != 0 && - (m_format[beg]&IMAGE_MASK) != 0 ) + (m_format[beg]&Gfx::FONT_MASK_IMAGE) != 0 ) { line = 1; while ( true ) // includes the image slices { if ( i+line >= m_lineTotal || i+line >= m_lineFirst+m_lineVisible || - (m_format[beg+line]&IMAGE_MASK) == 0 ) break; + (m_format[beg+line]&Gfx::FONT_MASK_IMAGE) == 0 ) break; line ++; } iIndex = m_text[beg]; // character = index in m_image pos.y -= m_lineHeight*(line-1); DrawImage(pos, m_image[iIndex].name, - m_image[iIndex].width*(m_fontSize/SMALLFONT), + m_image[iIndex].width*(m_fontSize/Gfx::FONT_SIZE_SMALL), m_image[iIndex].offset, m_image[iIndex].height*line, line); pos.y -= m_lineHeight; i += line-1; @@ -1023,18 +1036,18 @@ void CEdit::Draw() if ( m_format == 0 ) { - start.x = ppos.x+m_engine->RetText()->RetStringWidth(m_text+beg, o1-beg, size, m_fontStretch, m_fontType); - end.x = m_engine->RetText()->RetStringWidth(m_text+o1, o2-o1, size, m_fontStretch, m_fontType); + start.x = ppos.x+m_engine->GetText()->GetStringWidth(m_text+beg, m_fontType, size); + end.x = m_engine->GetText()->GetStringWidth(m_text+o1, m_fontType, size); } else { - start.x = ppos.x+m_engine->RetText()->RetStringWidth(m_text+beg, m_format+beg, o1-beg, size, m_fontStretch); - end.x = m_engine->RetText()->RetStringWidth(m_text+o1, m_format+o1, o2-o1, size, m_fontStretch); + start.x = ppos.x+m_engine->GetText()->GetStringWidth(m_text+beg, m_format+beg, size); + end.x = m_engine->GetText()->GetStringWidth(m_text+o1, m_format+o1, size); } start.y = ppos.y-(m_bMulti?0.0f:MARGY1); end.y = m_lineHeight; - if ( m_format != 0 && (m_format[beg]&TITLE_MASK) == TITLE_BIG ) end.y *= BIG_FONT; + if ( m_format != 0 && (m_format[beg]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG) end.y *= BIG_FONT; DrawPart(start, end, 1); // plain yellow background } @@ -1051,11 +1064,11 @@ void CEdit::Draw() if ( !m_bMulti || !m_bDisplaySpec ) eol = 0; if ( m_format == 0 ) { - m_engine->RetText()->DrawText(m_text+beg, len, ppos, m_dim.x, 1, size, m_fontStretch, m_fontType, eol); + m_engine->GetText()->DrawText(m_text+beg, m_fontType, size, ppos, m_dim.x, Gfx::TEXT_ALIGN_RIGHT, eol); } else { - m_engine->RetText()->DrawText(m_text+beg, m_format+beg, len, ppos, m_dim.x, 1, size, m_fontStretch, eol); + m_engine->GetText()->DrawText(m_text+beg, m_format+beg, size, ppos, m_dim.x, Gfx::TEXT_ALIGN_RIGHT, eol); } pos.y -= m_lineHeight; @@ -1085,17 +1098,15 @@ void CEdit::Draw() if ( m_format == 0 ) { - m_engine->RetText()->DimText(m_text+m_lineOffset[i], len, - pos, 1, size, - m_fontStretch, m_fontType, + m_engine->GetText()->SizeText(m_text+m_lineOffset[i], m_fontType, + size, pos, Gfx::TEXT_ALIGN_RIGHT, start, end); } else { - m_engine->RetText()->DimText(m_text+m_lineOffset[i], + m_engine->GetText()->SizeText(m_text+m_lineOffset[i], m_format+m_lineOffset[i], - len, pos, 1, size, - m_fontStretch, + size, pos, Gfx::TEXT_ALIGN_RIGHT, start, end); } @@ -1104,8 +1115,8 @@ void CEdit::Draw() } pos.y -= m_lineHeight; } - pos.x -= 1.0f/640.0f; - dim.x = 2.0f/640.0f; + pos.x -= 1.0f / 640.0f; + dim.x = 2.0f / 640.0f; dim.y = m_lineHeight; DrawPart(pos, dim, 0); // red } @@ -1130,7 +1141,7 @@ void CEdit::DrawImage(Math::Point pos, char *name, float width, strcat(filename, ".bmp"); m_engine->SetTexture(filename); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f; uv2.x = 1.0f; @@ -1158,7 +1169,7 @@ void CEdit::DrawBack(Math::Point pos, Math::Point dim) if ( m_bGeneric ) return; m_engine->SetTexture("button2.tga"); - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( m_bMulti ) { @@ -1212,7 +1223,7 @@ void CEdit::DrawPart(Math::Point pos, Math::Point dim, int icon) #else m_engine->SetTexture("text.tga"); #endif - m_engine->SetState(D3DSTATENORMAL); + m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = (16.0f/256.0f)*(icon%16); uv1.y = (240.0f/256.0f); @@ -1291,32 +1302,32 @@ void CEdit::SetText(char *text, bool bNew) { if ( text[i+1] == 'n' ) // normal ? { - font &= ~FONT_MASK; - font |= FONT_COLOBOT; + font &= ~Gfx::FONT_MASK_FONT; + font |= Gfx::FONT_COLOBOT; i += 2; } else if ( text[i+1] == 'c' ) // cbot ? { - font &= ~FONT_MASK; - font |= FONT_COURIER; + font &= ~Gfx::FONT_MASK_FONT; + font |= Gfx::FONT_COURIER; i += 2; } else if ( text[i+1] == 'b' ) // big title ? { - font &= ~TITLE_MASK; - font |= TITLE_BIG; + font &= ~Gfx::FONT_MASK_TITLE; + font |= Gfx::FONT_TITLE_BIG; i += 2; } else if ( text[i+1] == 't' ) // title ? { - font &= ~TITLE_MASK; - font |= TITLE_NORM; + font &= ~Gfx::FONT_MASK_TITLE; + font |= Gfx::FONT_TITLE_NORM; i += 2; } else if ( text[i+1] == 's' ) // subtitle ? { - font &= ~TITLE_MASK; - font |= TITLE_LITTLE; + font &= ~Gfx::FONT_MASK_TITLE; + font |= Gfx::FONT_TITLE_LITTLE; i += 2; } } @@ -1326,7 +1337,7 @@ void CEdit::SetText(char *text, bool bNew) m_format[j] = font; j ++; - font &= ~TITLE_MASK; // reset title + font &= ~Gfx::FONT_MASK_TITLE; // reset title } } m_len = j; @@ -1342,7 +1353,7 @@ void CEdit::SetText(char *text, bool bNew) // Returns a pointer to the edited text. -char* CEdit::RetText() +char* CEdit::GetText() { m_text[m_len] = 0; return m_text; @@ -1361,7 +1372,7 @@ void CEdit::GetText(char *buffer, int max) // Returns the length of the text. -int CEdit::RetTextLength() +int CEdit::GetTextLength() { return m_len; } @@ -1394,7 +1405,7 @@ void GetNameParam(char *cmd, int rank, char *buffer) // Returns a number of a command. // \x nom n1 n2; -int RetValueParam(char *cmd, int rank) +int GetValueParam(char *cmd, int rank) { int n, i; @@ -1423,7 +1434,7 @@ void CEdit::FreeImage() //? sprintf(filename, "diagram\\%s.bmp", m_image[i].name); UserDir(filename, m_image[i].name, "diagram"); strcat(filename, ".bmp"); - m_engine->FreeTexture(filename); + m_engine->DeleteTexture(filename); } } @@ -1467,14 +1478,14 @@ bool CEdit::ReadText(char *filename, int addSize) FreeImage(); delete m_text; - m_text = (char*)malloc(sizeof(char)*(m_maxChar+1)); - buffer = (char*)malloc(sizeof(char)*(m_maxChar+1)); + m_text = new char[sizeof(char)*(m_maxChar+1)]; + buffer = new char[sizeof(char)*(m_maxChar+1)]; fread(buffer, 1, len, file); if ( m_format != 0 ) { delete m_format; - m_format = (char*)malloc(sizeof(char)*m_maxChar); + m_format = new char[sizeof(char)*m_maxChar]; } fclose(file); @@ -1515,8 +1526,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~FONT_MASK; - font |= FONT_COLOBOT; + font &= ~Gfx::FONT_MASK_FONT; + font |= Gfx::FONT_COLOBOT; } i += 3; } @@ -1524,8 +1535,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~FONT_MASK; - font |= FONT_COURIER; + font &= ~Gfx::FONT_MASK_FONT; + font |= Gfx::FONT_COURIER; } i += 3; } @@ -1533,8 +1544,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~TITLE_MASK; - font |= TITLE_BIG; + font &= ~Gfx::FONT_MASK_TITLE; + font |= Gfx::FONT_TITLE_BIG; } i += 3; } @@ -1542,8 +1553,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~TITLE_MASK; - font |= TITLE_NORM; + font &= ~Gfx::FONT_MASK_TITLE; + font |= Gfx::FONT_TITLE_NORM; } i += 3; } @@ -1551,8 +1562,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~TITLE_MASK; - font |= TITLE_LITTLE; + font &= ~Gfx::FONT_MASK_TITLE; + font |= Gfx::FONT_TITLE_LITTLE; } i += 3; } @@ -1560,8 +1571,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~COLOR_MASK; - font |= COLOR_LINK; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font |= Gfx::FONT_HIGHLIGHT_LINK; } i += 3; } @@ -1583,7 +1594,7 @@ bool CEdit::ReadText(char *filename, int addSize) GetNameParam(buffer+i+3, 1, m_link[iLink].marker); iLink ++; } - font &= ~COLOR_MASK; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; } i += strchr(buffer+i, ';')-(buffer+i)+1; } @@ -1620,9 +1631,9 @@ bool CEdit::ReadText(char *filename, int addSize) GetNameParam(buffer+i+7, 0, iName); #endif //? iWidth = m_lineHeight*RetValueParam(buffer+i+7, 1); - iWidth = (float)RetValueParam(buffer+i+7, 1); - iWidth *= m_engine->RetText()->RetHeight(SMALLFONT, FONT_COLOBOT); - iLines = RetValueParam(buffer+i+7, 2); + iWidth = static_cast(GetValueParam(buffer+i+7, 1)); + iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); + iLines = GetValueParam(buffer+i+7, 2); LoadImage(iName); // A part of image per line of text. @@ -1634,7 +1645,7 @@ bool CEdit::ReadText(char *filename, int addSize) m_image[iIndex].width = iWidth*0.75f; m_text[j] = (char)(iIndex++); // as an index into m_image - m_format[j] = (unsigned char)IMAGE_MASK; + m_format[j] = (unsigned char)Gfx::FONT_MASK_IMAGE; j ++; } } @@ -1652,8 +1663,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - m_text[j] = RetValueParam(buffer+i+8, 0); - m_format[j] = font|FONT_BUTTON; + m_text[j] = GetValueParam(buffer+i+8, 0); + m_format[j] = font|Gfx::FONT_BUTTON; j ++; } i += strchr(buffer+i, ';')-(buffer+i)+1; @@ -1669,8 +1680,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~COLOR_MASK; - font |= COLOR_TOKEN; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font |= Gfx::FONT_HIGHLIGHT_TOKEN; } i += 7; } @@ -1684,8 +1695,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~COLOR_MASK; - font |= COLOR_TYPE; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font |= Gfx::FONT_HIGHLIGHT_TYPE; } i += 6; } @@ -1700,8 +1711,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~COLOR_MASK; - font |= COLOR_CONST; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font |= Gfx::FONT_HIGHLIGHT_CONST; } i += 7; } @@ -1714,8 +1725,8 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~COLOR_MASK; - font |= COLOR_KEY; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font |= Gfx::FONT_HIGHLIGHT_KEY; } i += 5; } @@ -1728,7 +1739,7 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font |= COLOR_TABLE; + font |= Gfx::FONT_HIGHLIGHT_TABLE; } i += 5; } @@ -1742,7 +1753,7 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~COLOR_MASK; + font &= ~Gfx::FONT_MASK_HIGHLIGHT; } i += 6; } @@ -1775,7 +1786,7 @@ bool CEdit::ReadText(char *filename, int addSize) { if ( SearchKey(buffer+i+5, key) ) { - res = m_engine->RetKey(key, 0); + res = m_engine->GetKey(key, 0); // TODO if ( res != 0 ) { if ( GetResource(RES_KEY, res, iName) ) @@ -1794,7 +1805,7 @@ bool CEdit::ReadText(char *filename, int addSize) m_format[j] = font; j ++; - res = m_engine->RetKey(key, 1); + res = m_engine->GetKey(key, 1); // TODO if ( res != 0 ) { if ( GetResource(RES_KEY, res, iName) ) @@ -1804,7 +1815,7 @@ bool CEdit::ReadText(char *filename, int addSize) while ( text[n] != 0 ) { m_text[j] = text[n++]; - m_format[j] = font&~COLOR_MASK; + m_format[j] = font&~Gfx::FONT_MASK_HIGHLIGHT; j ++; } n = 0; @@ -1840,11 +1851,11 @@ bool CEdit::ReadText(char *filename, int addSize) } i ++; - font &= ~TITLE_MASK; // reset title + font &= ~Gfx::FONT_MASK_TITLE; // reset title - if ( (font&COLOR_MASK) == COLOR_TABLE ) + if ( (font&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_TABLE ) { - font &= ~COLOR_TABLE; + font &= ~Gfx::FONT_HIGHLIGHT_TABLE; } } } @@ -1945,7 +1956,7 @@ void CEdit::SetMaxChar(int max) UndoFlush(); } -int CEdit::RetMaxChar() +int CEdit::GetMaxChar() { return m_maxChar; } @@ -1958,7 +1969,7 @@ void CEdit::SetEditCap(bool bMode) m_bEdit = bMode; } -bool CEdit::RetEditCap() +bool CEdit::GetEditCap() { return m_bEdit; } @@ -1970,7 +1981,7 @@ void CEdit::SetHiliteCap(bool bEnable) m_bHilite = bEnable; } -bool CEdit::RetHiliteCap() +bool CEdit::GetHiliteCap() { return m_bHilite; } @@ -1982,7 +1993,7 @@ void CEdit::SetInsideScroll(bool bInside) m_bInsideScroll = bInside; } -bool CEdit::RetInsideScroll() +bool CEdit::GetInsideScroll() { return m_bInsideScroll; } @@ -1994,7 +2005,7 @@ void CEdit::SetSoluceMode(bool bSoluce) m_bSoluce = bSoluce; } -bool CEdit::RetSoluceMode() +bool CEdit::GetSoluceMode() { return m_bSoluce; } @@ -2006,7 +2017,7 @@ void CEdit::SetGenericMode(bool bGeneric) m_bGeneric = bGeneric; } -bool CEdit::RetGenericMode() +bool CEdit::GetGenericMode() { return m_bGeneric; } @@ -2019,7 +2030,7 @@ void CEdit::SetAutoIndent(bool bMode) m_bAutoIndent = bMode; } -bool CEdit::RetAutoIndent() +bool CEdit::GetAutoIndent() { return m_bAutoIndent; } @@ -2057,7 +2068,7 @@ void CEdit::SetFirstLine(int rank) // Returns the first displayed line. -int CEdit::RetFirstLine() +int CEdit::GetFirstLine() { if ( m_historyTotal > 0 ) { @@ -2091,7 +2102,7 @@ void CEdit::ShowSelect() cursor2 = m_cursor1; } - line = RetCursorLine(cursor2); + line = GetCursorLine(cursor2); if ( line >= m_lineFirst+m_lineVisible ) { line -= m_lineVisible-1; @@ -2099,7 +2110,7 @@ void CEdit::ShowSelect() Scroll(line, false); } - line = RetCursorLine(cursor1); + line = GetCursorLine(cursor1); if ( line < m_lineFirst ) { Scroll(line, false); @@ -2114,7 +2125,7 @@ void CEdit::SetDisplaySpec(bool bDisplay) m_bDisplaySpec = bDisplay; } -bool CEdit::RetDisplaySpec() +bool CEdit::GetDisplaySpec() { return m_bDisplaySpec; } @@ -2137,7 +2148,7 @@ void CEdit::SetMultiFont(bool bMulti) } } -bool CEdit::RetMultiFont() +bool CEdit::GetMultiFont() { return ( m_format != 0 ); } @@ -2161,7 +2172,7 @@ void CEdit::Scroll() if ( m_scroll != 0 ) { - value = m_scroll->RetVisibleValue(); + value = m_scroll->GetVisibleValue(); value *= m_lineTotal-m_lineVisible; Scroll((int)(value+0.5f), true); } @@ -2181,7 +2192,7 @@ void CEdit::Scroll(int pos, bool bAdjustCursor) if ( max < 0 ) max = 0; if ( m_lineFirst > max ) m_lineFirst = max; - line = RetCursorLine(m_cursor1); + line = GetCursorLine(m_cursor1); if ( bAdjustCursor && m_bEdit ) { @@ -2418,29 +2429,28 @@ void CEdit::MoveLine(int move, bool bWord, bool bSelect) } } - line = RetCursorLine(m_cursor1); + line = GetCursorLine(m_cursor1); column = m_column; if ( m_bAutoIndent ) { - indentLength = m_engine->RetText()->RetCharWidth(' ', 0.0f, m_fontSize, m_fontStretch, m_fontType) - * m_engine->RetEditIndentValue(); + indentLength = m_engine->GetText()->GetCharWidth(static_cast(' '), m_fontType, m_fontSize, 0.0f) + * m_engine->GetEditIndentValue(); column -= indentLength*m_lineIndent[line]; } if ( m_format == 0 ) { - c = m_engine->RetText()->Detect(m_text+m_lineOffset[line], - m_lineOffset[line+1]-m_lineOffset[line], - column, m_fontSize, - m_fontStretch, m_fontType); + c = m_engine->GetText()->Detect(m_text+m_lineOffset[line], + m_fontType, m_fontSize, + m_lineOffset[line+1]-m_lineOffset[line]); } else { - c = m_engine->RetText()->Detect(m_text+m_lineOffset[line], + c = m_engine->GetText()->Detect(m_text+m_lineOffset[line], m_format+m_lineOffset[line], - m_lineOffset[line+1]-m_lineOffset[line], - column, m_fontSize, m_fontStretch); + m_fontSize, + m_lineOffset[line+1]-m_lineOffset[line]); } m_cursor1 = m_lineOffset[line]+c; @@ -2457,32 +2467,27 @@ void CEdit::ColumnFix() float indentLength; int line; - line = RetCursorLine(m_cursor1); + line = GetCursorLine(m_cursor1); if ( m_format == 0 ) { - m_column = m_engine->RetText()->RetStringWidth - ( + m_column = m_engine->GetText()->GetStringWidth( m_text+m_lineOffset[line], - m_cursor1-m_lineOffset[line], - m_fontSize, m_fontStretch, m_fontType - ); + m_fontType, m_fontSize); } else { - m_column = m_engine->RetText()->RetStringWidth - ( + m_column = m_engine->GetText()->GetStringWidth( m_text+m_lineOffset[line], m_format+m_lineOffset[line], - m_cursor1-m_lineOffset[line], - m_fontSize, m_fontStretch + m_fontSize ); } if ( m_bAutoIndent ) { - indentLength = m_engine->RetText()->RetCharWidth(' ', 0.0f, m_fontSize, m_fontStretch, m_fontType) - * m_engine->RetEditIndentValue(); + indentLength = m_engine->GetText()->GetCharWidth(static_cast(' '), m_fontType, m_fontSize, 0.0f) + * m_engine->GetEditIndentValue(); m_column += indentLength*m_lineIndent[line]; } } @@ -2490,7 +2495,7 @@ void CEdit::ColumnFix() // Cut the selected characters or entire line. -bool CEdit::Cut() +bool CEdit::Cut() // TODO MS Windows allocations { HGLOBAL hg; char* text; @@ -2571,7 +2576,7 @@ bool CEdit::Cut() // Copy the selected characters or entire line. -bool CEdit::Copy() +bool CEdit::Copy() // TODO { HGLOBAL hg; char* text; @@ -2643,7 +2648,7 @@ bool CEdit::Copy() // Paste the contents of the notebook. -bool CEdit::Paste() +bool CEdit::Paste() // TODO { HANDLE h; char c; @@ -2777,7 +2782,7 @@ void CEdit::Insert(char character) #endif else if ( character == '\t' ) { - for ( i=0 ; iRetEditIndentValue() ; i++ ) + for ( i=0 ; iGetEditIndentValue() ; i++ ) { InsertOne(' '); } @@ -3025,8 +3030,8 @@ bool CEdit::MinMaj(bool bMaj) for ( i=c1 ; iRetText()->RetCharWidth(' ', 0.0f, m_fontSize, m_fontStretch, m_fontType) - * m_engine->RetEditIndentValue(); + indentLength = m_engine->GetText()->GetCharWidth(static_cast(' '), m_fontType, m_fontSize, 0.0f) + * m_engine->GetEditIndentValue(); } bString = bRem = false; @@ -3071,29 +3076,29 @@ void CEdit::Justif() if ( m_format == 0 ) { - i += m_engine->RetText()->Justif(m_text+i, m_len-i, width, - m_fontSize, m_fontStretch, - m_fontType); + // TODO check if good + i += m_engine->GetText()->Justify(m_text+i, m_fontType, + m_fontSize, width); } else { size = m_fontSize; - if ( (m_format[i]&TITLE_MASK) == TITLE_BIG ) // headline? + if ( (m_format[i]&Gfx::FONT_MASK_TITLE) == Gfx::FONT_TITLE_BIG ) // headline? { size *= BIG_FONT; bDual = true; } - if ( (m_format[i]&IMAGE_MASK) != 0 ) // image part? + if ( (m_format[i]&Gfx::FONT_MASK_IMAGE) != 0 ) // image part? { i ++; // jumps just a character (index in m_image) } else { - i += m_engine->RetText()->Justif(m_text+i, m_format+i, - m_len-i, width, - size, m_fontStretch); + // TODO check if good + i += m_engine->GetText()->Justify(m_text+i, m_format+i, + size, width); } } @@ -3149,7 +3154,7 @@ void CEdit::Justif() { if ( m_bEdit ) { - line = RetCursorLine(m_cursor1); + line = GetCursorLine(m_cursor1); if ( line < m_lineFirst ) { m_lineFirst = line; @@ -3175,13 +3180,13 @@ void CEdit::Justif() } else { - value = (float)m_lineVisible/m_lineTotal; + value = static_cast(m_lineVisible/m_lineTotal); m_scroll->SetVisibleRatio(value); - value = (float)m_lineFirst/(m_lineTotal-m_lineVisible); + value = static_cast(m_lineFirst/(m_lineTotal-m_lineVisible)); m_scroll->SetVisibleValue(value); - value = (float)1.0f/(m_lineTotal-m_lineVisible); + value = static_cast(1.0f/(m_lineTotal-m_lineVisible)); m_scroll->SetArrowStep(value); } } @@ -3191,7 +3196,7 @@ void CEdit::Justif() // Returns the rank of the line where the cursor is located. -int CEdit::RetCursorLine(int cursor) +int CEdit::GetCursorLine(int cursor) { int line, i; @@ -3314,3 +3319,4 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format) } +} diff --git a/src/ui/edit.h b/src/ui/edit.h index dbd94d1..99ec693 100644 --- a/src/ui/edit.h +++ b/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: }; +} diff --git a/src/ui/editvalue.cpp b/src/ui/editvalue.cpp index 71e06f2..f747c94 100644 --- a/src/ui/editvalue.cpp +++ b/src/ui/editvalue.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,13 +18,13 @@ // editvalue.cpp -#include -#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 "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(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(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(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; } +} diff --git a/src/ui/editvalue.h b/src/ui/editvalue.h index dbb7812..c5c857c 100644 --- a/src/ui/editvalue.h +++ b/src/ui/editvalue.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 @@ -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: }; +} -- cgit v1.2.3-1-g7c22