~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to plee-the-bear/src/ptb/layer/code/log_layer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Plee the Bear
3
 
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
5
 
 
6
 
  This program is free software; you can redistribute it and/or modify it
7
 
  under the terms of the GNU General Public License as published by the
8
 
  Free Software Foundation; either version 2 of the License, or (at your
9
 
  option) any later version.
10
 
 
11
 
  This program is distributed in the hope that it will be useful, but WITHOUT
12
 
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
 
  more details.
15
 
 
16
 
  You should have received a copy of the GNU General Public License along
17
 
  with this program; if not, write to the Free Software Foundation, Inc.,
18
 
  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 
20
 
  contact: plee-the-bear@gamned.org
21
 
 
22
 
  Please add the tag [PTB] in the subject of your mails.
23
 
*/
24
 
/**
25
 
 * \file log_layer.cpp
26
 
 * \brief Implementation of the ptb::log_layer class.
27
 
 * \author Julien Jorge
28
 
 */
29
 
#include "ptb/layer/log_layer.hpp"
30
 
 
31
 
#include "engine/level_globals.hpp"
32
 
 
33
 
#include <claw/logger.hpp>
34
 
#include <claw/string_algorithm.hpp>
35
 
 
36
 
/*----------------------------------------------------------------------------*/
37
 
/**
38
 
 * \brief Constructor.
39
 
 */
40
 
ptb::log_layer::log_layer()
41
 
  : m_visible(false), m_lines(15), m_append(false)
42
 
{
43
 
 
44
 
} // log_layer::log_layer()
45
 
 
46
 
/*----------------------------------------------------------------------------*/
47
 
/**
48
 
 * \brief Destructor.
49
 
 */
50
 
ptb::log_layer::~log_layer()
51
 
{
52
 
  claw::logger.remove(this);
53
 
 
54
 
  for (unsigned int i=0; i!=m_lines.size(); ++i)
55
 
    delete m_lines[i];
56
 
} // log_layer::~log_layer()
57
 
 
58
 
/*----------------------------------------------------------------------------*/
59
 
/**
60
 
 * \brief Initialize the layer.
61
 
 */
62
 
void ptb::log_layer::build()
63
 
{
64
 
  bear::visual::font font =
65
 
    get_level_globals().get_font( "font/fixed_white-7x12.fnt" );
66
 
 
67
 
  claw::math::coordinate_2d<unsigned int> pos( font->get_size() );
68
 
 
69
 
  for (unsigned int i=0; i!=m_lines.size(); ++i)
70
 
    {
71
 
      m_lines[i] = new bear::gui::static_text( NULL, font );
72
 
      m_lines[i]->set_auto_size( true );
73
 
      m_lines[i]->set_position( pos );
74
 
      pos.y += font->get_size().y;
75
 
    }
76
 
 
77
 
  claw::logger.merge(this);
78
 
} // log_layer::build()
79
 
 
80
 
/*----------------------------------------------------------------------------*/
81
 
/**
82
 
 * \brief Render the layer on a screen.
83
 
 * \param e (out) The scene elements.
84
 
 */
85
 
void ptb::log_layer::render( scene_element_list& e ) const
86
 
{
87
 
  if (m_visible)
88
 
    for (unsigned int i=0; i!=m_lines.size(); ++i)
89
 
      m_lines[i]->render(e);
90
 
} // log_layer::render()
91
 
 
92
 
/*----------------------------------------------------------------------------*/
93
 
/**
94
 
 * \brief Inform the layer that a keyboard key has been pressed.
95
 
 * \param key The value of the pressed key.
96
 
 */
97
 
bool ptb::log_layer::key_pressed( const bear::input::key_info& key )
98
 
{
99
 
  bool result = true;
100
 
 
101
 
  if ( key.is_function(6) )
102
 
    m_visible = !m_visible;
103
 
  else
104
 
    result = false;
105
 
 
106
 
  return result;
107
 
} // log_layer::key_pressed()
108
 
 
109
 
/*----------------------------------------------------------------------------*/
110
 
/**
111
 
 * \brief Write a string in the stream.
112
 
 * \param str The string to write.
113
 
 */
114
 
void ptb::log_layer::write( const std::string& str )
115
 
{
116
 
  std::list<std::string> lines;
117
 
  unsigned int i;
118
 
  std::list<std::string>::const_iterator it;
119
 
 
120
 
  claw::text::split(lines, str, '\n');
121
 
 
122
 
  if ( lines.size() > m_lines.size() )
123
 
    {
124
 
      i = m_lines.size();
125
 
      it=lines.end();
126
 
 
127
 
      do
128
 
  {
129
 
    --i;
130
 
    --it;
131
 
    m_lines[i]->set_text(*it);
132
 
  }
133
 
      while( i>0 );
134
 
    }
135
 
  else if ( !lines.empty() )
136
 
    {
137
 
      unsigned int keep = m_lines.size() - lines.size();
138
 
 
139
 
      if ( m_append )
140
 
  ++keep;
141
 
 
142
 
      unsigned int j = m_lines.size() - keep;
143
 
 
144
 
      for (i=0; i!=keep; ++i, ++j)
145
 
  m_lines[i]->set_text( m_lines[j]->get_text() );
146
 
 
147
 
      it = lines.begin();
148
 
 
149
 
      if (m_append)
150
 
  {
151
 
    m_lines[i-1]->set_text( m_lines[i-1]->get_text() + *it );
152
 
    ++it;
153
 
  }
154
 
 
155
 
      for ( ; it!=lines.end(); ++it, ++i )
156
 
  m_lines[i]->set_text(*it);
157
 
    }
158
 
 
159
 
  if ( str.size() > 0 )
160
 
    m_append = ( str[str.size() - 1] != '\n' );
161
 
} // log_layer::flush()