Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 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.
40 {
41  const Rect textRect = m_rect.copyAndInset( m_textMargins );
42  m_paintText.setRect( textRect );
43 }
44 
45 //Set text margins.
47 {
48  m_textMargins = s;
50 }
51 
52 //The outside boundaries of the control.
53 void StaticDisplay::setRect( const Rect &r )
54 {
55  Control::setRect( r );
57 }
58 
59 //Draw the control.
60 void StaticDisplay::draw( void )
61 {
62  //Draw the background.
64  //If we have a scroller and the layout has changed, need to reset the scroller.
66  const int lineCount = m_paintText.lineCount();
68  m_scroller->setRangeValues( lineCount-1, visible );
69  if (m_scrollPosition > lineCount-2 && lineCount > visible)
70  m_scrollPosition = lineCount-1;
72  m_layoutVersion = m_paintText.layoutVersion(); //Remember layout version for next time.
73  }
75 }
76 
77 //Set the object that takes care of scrolling.
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 );
90  return true;
91  }
92  return Control::processCommand( command, control );
93 }
94 
95 //Process wheel events for scrolling.
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 ) )
103  } else if (event.code == WHEELDOWN_MOUSE_BUTTON) {
104  if ( hitTest( event.loc ) )
106  }
107  }
108  return Control::processMouseDown( event );
109 }
110 
111 //CONSTRUCTION
113  m_textMargins( Size( 0.0, 0.0 ) )
114  , m_scrollPosition( 0 )
115  , m_layoutVersion( m_paintText.layoutVersion() )
116  , m_scroller( NULL )
117 {}
118