Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
staticdisplay.cpp
Go to the documentation of this file.
1
/*
2
* Vega Strike
3
* Copyright (C) 2003 Mike Byron
4
*
5
* http://vegastrike.sourceforge.net/
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
*/
21
22
#include "
vegastrike.h
"
23
24
#include "
staticdisplay.h
"
25
26
#include "
guidefs.h
"
27
#include "
scroller.h
"
28
29
#include "
vs_globals.h
"
30
#include "
config_xml.h
"
31
#include "
xml_support.h
"
32
33
//The StaticDisplay class is used to show something on a window.
34
//Right now, it only supports text, but could be expanded to support
35
//images, textures, meshes, etc.
36
//This control does not respond to input events.
37
38
//The rect for the text object has changed -- reset it.
39
void
StaticDisplay::setPaintTextRect
(
void
)
40
{
41
const
Rect
textRect =
m_rect
.
copyAndInset
(
m_textMargins
);
42
m_paintText
.
setRect
( textRect );
43
}
44
45
//Set text margins.
46
void
StaticDisplay::setTextMargins
(
const
Size
&s )
47
{
48
m_textMargins
= s;
49
setPaintTextRect
();
50
}
51
52
//The outside boundaries of the control.
53
void
StaticDisplay::setRect
(
const
Rect
&r )
54
{
55
Control::setRect
( r );
56
setPaintTextRect
();
57
}
58
59
//Draw the control.
60
void
StaticDisplay::draw
(
void
)
61
{
62
//Draw the background.
63
drawBackground
();
64
//If we have a scroller and the layout has changed, need to reset the scroller.
65
if
(
m_scroller
&&
m_layoutVersion
!=
m_paintText
.
layoutVersion
() ) {
66
const
int
lineCount =
m_paintText
.
lineCount
();
67
const
int
visible =
m_paintText
.
visibleLineCountStartingWith
(
m_scrollPosition
,
m_rect
.
size
.
height
);
68
m_scroller
->
setRangeValues
( lineCount-1, visible );
69
if
(
m_scrollPosition
> lineCount-2 && lineCount > visible)
70
m_scrollPosition
= lineCount-1;
71
m_scroller
->
setScrollPosition
(
m_scrollPosition
);
72
m_layoutVersion
=
m_paintText
.
layoutVersion
();
//Remember layout version for next time.
73
}
74
m_paintText
.
drawLines
(
m_scrollPosition
);
75
}
76
77
//Set the object that takes care of scrolling.
78
void
StaticDisplay::setScroller
(
Scroller
*s )
79
{
80
m_scroller
= s;
81
s->
setCommandTarget
(
this
);
82
}
83
84
//Process a command event.
85
bool
StaticDisplay::processCommand
(
const
EventCommandId
&command,
Control
*control )
86
{
87
if
(command ==
"Scroller::PositionChanged"
) {
88
assert( control ==
m_scroller
);
89
m_scrollPosition
=
m_scroller
->
scrollPosition
();
90
return
true
;
91
}
92
return
Control::processCommand
( command, control );
93
}
94
95
//Process wheel events for scrolling.
96
bool
StaticDisplay::processMouseDown
(
const
InputEvent
&event )
97
{
98
static
int
zoominc =
XMLSupport::parse_int
(
vs_config
->
getVariable
(
"general"
,
"wheel_increment_lines"
,
"3"
) );
99
if
(
m_scroller
) {
100
if
(event.
code
==
WHEELUP_MOUSE_BUTTON
) {
101
if
(
hitTest
( event.
loc
) )
102
m_scroller
->
setScrollPosition
(
m_scroller
->
scrollPosition
()-zoominc );
103
}
else
if
(event.
code
==
WHEELDOWN_MOUSE_BUTTON
) {
104
if
(
hitTest
( event.
loc
) )
105
m_scroller
->
setScrollPosition
(
m_scroller
->
scrollPosition
()+zoominc );
106
}
107
}
108
return
Control::processMouseDown
( event );
109
}
110
111
//CONSTRUCTION
112
StaticDisplay::StaticDisplay
(
void
) :
113
m_textMargins(
Size
( 0.0, 0.0 ) )
114
, m_scrollPosition( 0 )
115
, m_layoutVersion( m_paintText.layoutVersion() )
116
, m_scroller( NULL )
117
{}
118
src
gui
staticdisplay.cpp
Generated on Fri May 29 2015 23:07:33 for Vegastrike 0.5.1 rc1 by
1.8.4