summaryrefslogtreecommitdiff
path: root/rhtvision/examples/dyntxt/dyntext.cpp
blob: 56b1f20ef5de0f8c1dc04fc6aae7eb1c1138a65b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//  Copyright (c) 1992 by James H. Price, All rights reserved
//
//  DYNTEXT.CPP
//
//    Member functions for DynamicText class
//

#define Uses_string
#define Uses_TView
#define Uses_TStreamableClass
#define Uses_TPalette
#include <tv.h>

#include "dyntext.h"

#define cpDynamicText "\x06"

DynamicText::DynamicText( const TRect& r, const char *aText,
  Boolean rj ) : TView( r ), text( new char[size.x+1] ),
  rightJustify( rj )
{
  strncpy( text, aText, size.x );
  text[size.x] = EOS;
}

DynamicText::~DynamicText()
{
  delete text;
}

void DynamicText::draw()
{
  TDrawBuffer b;
  uchar color = getColor(1);
  int offset = ( rightJustify ) ? size.x-strlen(text) : 0;

  b.moveChar( 0, ' ', color, size.x );
  b.moveStr( offset, text, color );
  writeBuf( 0, 0, size.x, 1, b );
}

TPalette& DynamicText::getPalette() const
{
  static TPalette palette( cpDynamicText, sizeof( cpDynamicText )-1 );
  return palette;
}

void DynamicText::setText( const char *s )
{
  setData( (void *)s );
  drawView();
}

void DynamicText::setData( void *rec )
{
  memmove( text, rec, size.x+1 );
  text[size.x] = EOS;
}

void DynamicText::getData( void *rec )
{
  strcpy( (char *)rec, text );
}

unsigned DynamicText::dataSize()
{
  return( size.x+1 );
}

void DynamicText::write( opstream& os )
{
  TView::write( os );
  os.writeString( text );
  os << (int)rightJustify;
}

void *DynamicText::read( ipstream& is )
{
  int rj;
  TView::read( is );
  text = is.readString();
  is >> rj;
  rightJustify = Boolean( rj );
  return this;
}

const char * const DynamicText::name = "DynamicText";
TStreamableClass RDynamicText( DynamicText::name,
  DynamicText::build,  __DELTA(DynamicText) );