PEBL
2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
sdl/PlatformTextBox.h
Go to the documentation of this file.
1
//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3
// Name: src/platforms/sdl/PlatformTextBox.h
4
// Purpose: Contains platform-specific interface for text boxes
5
// Author: Shane T. Mueller, Ph.D.
6
// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7
// License: GPL 2
8
//
9
//
10
//
11
// This file is part of the PEBL project.
12
//
13
// PEBL is free software; you can redistribute it and/or modify
14
// it under the terms of the GNU General Public License as published by
15
// the Free Software Foundation; either version 2 of the License, or
16
// (at your option) any later version.
17
//
18
// PEBL is distributed in the hope that it will be useful,
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
// GNU General Public License for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with PEBL; if not, write to the Free Software
25
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#ifndef __PLATFORMTEXTBOX_H__
28
#define __PLATFORMTEXTBOX_H__
29
30
#include "
PlatformWidget.h
"
31
#include "
PlatformFont.h
"
32
#include "../../objects/PTextBox.h"
33
34
#ifdef PEBL_OSX
35
#include "SDL.h"
36
#include "SDL_ttf.h"
37
#else
38
#include "SDL.h"
39
#include "SDL_ttf.h"
40
#endif
41
42
#include "../../utility/rc_ptrs.h"
43
#include "../../base/PEBLObject.h"
44
#include "../../utility/FormatParser.h"
45
46
#include <vector>
47
#include <map>
48
#include <tuple>
49
53
54
55
class
PlatformTextBox
:
virtual
public
PlatformWidget
,
virtual
public
PTextBox
56
{
57
public
:
58
PlatformTextBox
(std::string text,
counted_ptr<PEBLObjectBase>
font,
int
width,
int
height);
59
61
PlatformTextBox
(
const
PlatformTextBox
& textbox);
62
63
virtual
~PlatformTextBox
();
64
65
66
virtual
bool
RenderText
();
67
68
virtual
bool
SetProperty
(std::string,
Variant
v);
69
virtual
Variant
GetProperty
(std::string name)
const
;
70
//These need to be overridden because the text needs to be re-rendered when they are called.
71
virtual
void
SetFont
(
counted_ptr<PEBLObjectBase>
font);
72
virtual
void
SetText
(std::string text);
73
virtual
void
SetHeight
(
int
h);
74
virtual
void
SetWidth
(
int
w);
75
76
//This needs to be overridden so that it returns a PlatformFont.
77
// Return adaptive font if it exists, otherwise return original
78
virtual
counted_ptr<PEBLObjectBase>
GetFont
()
const
{
79
return
mAdaptiveFontObject.
get
() ? mAdaptiveFontObject : mFontObject;
80
}
81
82
83
virtual
bool
Draw
();
84
virtual
void
HandleKeyPress
(
int
keycode,
int
modkeys, Uint16 unicode);
85
virtual
void
HandleTextInput
(std::string input);
86
virtual
std::string
ObjectName
()
const
{
return
"PlatformTextBox"
;} ;
87
virtual
int
FindCursorPosition
(
long
int
x,
long
int
y);
88
virtual
void
SetEditable
(
bool
val);
89
Variant
GetLineBreaks
();
90
protected
:
91
92
virtual
std::ostream &
SendToStream
(std::ostream& out)
const
;
93
94
std::vector<int>
mBreaks
;
95
96
private
:
97
// Helper to get PlatformFont pointer from counted_ptr when needed
98
// Returns adaptive font if it exists, otherwise returns original font
99
PlatformFont
* GetPlatformFont()
const
{
100
if
(mAdaptiveFontObject.
get
()) {
101
return
dynamic_cast<
PlatformFont
*
>
(mAdaptiveFontObject.
get
());
102
}
103
return
dynamic_cast<
PlatformFont
*
>
(mFontObject.
get
());
104
}
105
106
void
FindBreaks();
107
int
FindNextLineBreak(
unsigned
int
curposition);
108
109
// Size-aware line breaking for formatted text
110
void
FindBreaksFormatted(
const
std::vector<FormatParser::FormatSegment>& segments);
111
void
FindBreaksInSegment(
const
FormatParser::FormatSegment
& seg,
112
PlatformFont
* segFont,
113
int
& currentLineWidth,
114
int
& currentLineMaxHeight,
115
std::string& currentLineText,
116
int
& strippedTextPos,
117
int
& totalHeight);
118
119
void
DrawCursor();
120
121
counted_ptr<PEBLObjectBase>
mFontObject;
122
counted_ptr<PEBLObjectBase>
mAdaptiveFontObject;
// Holds adapted font separately to avoid destructor cascade
123
std::vector<counted_ptr<PEBLObjectBase>> mIntermediateFonts;
// Keeps intermediate adaptive fonts alive
124
bool
mIsUTF8;
125
std::string mStrippedText;
// For formatted mode: stores text with tags stripped (used for line breaking)
126
127
};
128
129
130
131
#endif
PTextBox
This class is the basic generic text box.
Definition
PTextBox.h:40
PlatformFont
Definition
sdl/PlatformFont.h:53
PlatformTextBox
Validator platform textbox - no rendering, used only for compilation.
Definition
sdl/PlatformTextBox.h:56
PlatformTextBox::SetHeight
virtual void SetHeight(int h)
Definition
sdl/PlatformTextBox.cpp:669
PlatformTextBox::GetFont
virtual counted_ptr< PEBLObjectBase > GetFont() const
Definition
sdl/PlatformTextBox.h:78
PlatformTextBox::FindCursorPosition
virtual int FindCursorPosition(long int x, long int y)
Definition
sdl/PlatformTextBox.cpp:1454
PlatformTextBox::SetFont
virtual void SetFont(counted_ptr< PEBLObjectBase > font)
Definition
sdl/PlatformTextBox.cpp:691
PlatformTextBox::HandleKeyPress
virtual void HandleKeyPress(int keycode, int modkeys, Uint16 unicode)
Definition
sdl/PlatformTextBox.cpp:1791
PlatformTextBox::SetText
virtual void SetText(std::string text)
Definition
sdl/PlatformTextBox.cpp:718
PlatformTextBox::HandleTextInput
virtual void HandleTextInput(std::string input)
Definition
sdl/PlatformTextBox.cpp:1945
PlatformTextBox::PlatformTextBox
PlatformTextBox(std::string text, counted_ptr< PEBLObjectBase > font, int width, int height)
PlatformTextBox::GetLineBreaks
Variant GetLineBreaks()
Definition
sdl/PlatformTextBox.cpp:1952
PlatformTextBox::SetEditable
virtual void SetEditable(bool val)
Definition
sdl/PlatformTextBox.cpp:739
PlatformTextBox::Draw
virtual bool Draw()
This method initiates everything needed to display the main window
Definition
sdl/PlatformTextBox.cpp:1651
PlatformTextBox::GetProperty
virtual Variant GetProperty(std::string name) const
Definition
sdl/PlatformTextBox.cpp:655
PlatformTextBox::~PlatformTextBox
virtual ~PlatformTextBox()
Standard Destructor.
Definition
sdl/PlatformTextBox.cpp:172
PlatformTextBox::ObjectName
virtual std::string ObjectName() const
Definition
sdl/PlatformTextBox.h:86
PlatformTextBox::RenderText
virtual bool RenderText()
Definition
sdl/PlatformTextBox.cpp:190
PlatformTextBox::mBreaks
std::vector< int > mBreaks
Definition
sdl/PlatformTextBox.h:94
PlatformTextBox::SetProperty
virtual bool SetProperty(std::string, Variant v)
Definition
sdl/PlatformTextBox.cpp:626
PlatformTextBox::SendToStream
virtual std::ostream & SendToStream(std::ostream &out) const
An inheritable printing class used by PEBLObjectBase::operator<<.
Definition
validator/PlatformTextBox.cpp:44
PlatformTextBox::SetWidth
virtual void SetWidth(int w)
Definition
sdl/PlatformTextBox.cpp:679
PlatformWidget
Definition
sdl/PlatformWidget.h:45
Variant
Definition
Variant.h:67
counted_ptr
Definition
rc_ptrs.h:66
counted_ptr::get
X * get() const
Definition
rc_ptrs.h:110
FormatParser::FormatSegment
Definition
FormatParser.h:44
PlatformFont.h
PlatformWidget.h
src
platforms
sdl
PlatformTextBox.h
Generated by
1.9.8