summaryrefslogtreecommitdiff
path: root/tvision/examples/desklogo/set-logo.cc
blob: 56bae179537e773c8699e2103f6fba592bdf845a (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//========================================================================
//  The following example routines have been provided by the Technical
//  Support staff at Borland International.  They are provided as a
//  courtesy and not as part of a Borland product, and as such, are
//  provided without the assurance of technical support or any specific
//  guarantees.
//========================================================================
//
// Ported and contributed by Joel <jso@europay.com>
//
// SET: 1999/12/05, Added an example to show how to stop and resume the
// application under Linux. Based in a test from Matt Mueller
// <donut@azstarnet.com>
//
//========================================================================

// To avoid pulling TScreen and signal.h for anything but UNIX
#include <tv/configtv.h>

#define Uses_string

#define Uses_TApplication
#define Uses_TBackground
#define Uses_TButton
#define Uses_TKeys
#define Uses_TDeskTop
#define Uses_TDialog
#define Uses_TMenu
#define Uses_TMenuBar
#define Uses_TMenuItem
#define Uses_TRect
#define Uses_TStaticText
#define Uses_TStatusDef
#define Uses_TStatusItem
#define Uses_TStatusLine

#ifdef TVOS_UNIX
 #define Uses_TScreen
 #define Uses_signal
#endif

#include <tv.h>

#define   PATTERN 177

const int cmAbout   = 100;  // User selected menu item 'About'

char *lines[]=
{
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                   ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛÛÛÛ                       ",
"                   ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛÛÛÛ                       ",
"                   ÛÛÛÛ          ÛÛÛÛ             ÛÛÛÛ                          ",
"                   ÛÛÛÛ          ÛÛÛÛ             ÛÛÛÛ                          ",
"                   ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛ          ÛÛÛÛ                          ",
"                   ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛ             ÛÛÛÛ                          ",
"                         ÛÛÛÛ    ÛÛÛÛ             ÛÛÛÛ                          ",
"                         ÛÛÛÛ    ÛÛÛÛ             ÛÛÛÛ                          ",
"                   ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛÛÛÛ       ÛÛÛÛ                          ",
"                   ÛÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÛÛÛÛÛÛ       ÛÛÛÛ                          ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                ",
"                                                                                "
};


//========================================================================
//  class definitions
//------------------------------------------------------------------------
class TApp : public TApplication {
    //  main application class

public:
    TApp();

    static TMenuBar *initMenuBar( TRect r );
    static TDeskTop *initDeskTop( TRect r );
    void handleEvent( TEvent &event );
    void AboutDialog();

};

//------------------------------------------------------------------------
class TNewDeskTop : public TDeskTop
{   // we derive a new desk top which will instantiate the background
    // object with the character we select for the pattern
    // also, the initBackground function is overridden to return
    // our specialized TNewBackground
public:
    TNewDeskTop( const TRect& r );
    static TBackground* initBackground( TRect r );
};

//------------------------------------------------------------------------
class TNewBackground : public TBackground
{
public:
    TNewBackground( const TRect& r, char pattern );
    void draw();
};



//===========================================================================
//           Draw the background
//===========================================================================
void TNewBackground::draw()
{

  TDrawBuffer b;

  for(int i= 0; i < size.y; i++)
	 {
	 for( int j= 0; j < size.x; j++)
		{
		if (i<25 && j<80)
			b.moveChar( j, lines[i][j], getColor(0x01), 1 );
		else
			b.moveChar( j, ' ', getColor(0x01), 1 );
		}
	 writeLine( 0, i, size.x, 1, b );
	 }

}


TApp::TApp() : TProgInit( &TApplication::initStatusLine,
		    &TApp::initMenuBar, &TApp::initDeskTop )
{
}



TMenuBar *TApp::initMenuBar( TRect r )
{
    r.b.y = r.a.y + 1;
    return( new TMenuBar( r, new TMenu(
	*new TMenuItem( "~A~bout", cmAbout, kbAltA, hcNoContext, 0 )
	) ) );
}

//------------------------------------------------------------------------
//  redefine desktop initialization to cause usage of newly
//  defined desktop
//------------------------------------------------------------------------
TDeskTop *TApp::initDeskTop( TRect r )
{
    // initDeskTop is passed a TRect which is the size of the
    // application's window - in our case the whole screen
    r.a.y++;
    r.b.y--;
    return ( new TNewDeskTop( r ) );

}

#ifdef TVOS_UNIX
void ResumeApp(int signum)
{
 TProgram::application->resume();
 TProgram::deskTop->setState(sfVisible,True);
 TProgram::deskTop->redraw();
 TProgram::application->redraw();
}
#endif

void TApp::handleEvent (TEvent &event)
{
  // override the handleEvent so we can call the about box
  TApplication::handleEvent( event );
  if( event.what == evCommand )
	 {
	 switch( event.message.command )
		{
		case cmAbout:
				 {
				 AboutDialog();
				 clearEvent( event );
				 break;
				 }
		}
	 }
  #ifdef TVOS_UNIX
  else
  if( event.what == evKeyDown && event.keyDown.keyCode == kbCtrlZ )
	 {
     suspend();
     signal(SIGCONT,ResumeApp);
     kill(0,SIGSTOP);
    }
  #endif
}

//------------------------------------------------------------------------
// create modal About dialog box
//------------------------------------------------------------------------
void TApp::AboutDialog()
{

    TDialog *pd = new TDialog( TRect( 0, 0, 35, 12 ), "About" );
    if (pd)
    {
	pd->options |= ofCentered;
	pd->insert( new TStaticText( TRect( 1, 2, 34, 7 ),
		"\003Turbo Vision Example\n\003\n"
		"\003Modifying the desk top\n\003\n"
		"\003Borland Technical Support"));
	pd->insert( new TButton( TRect( 3,9,32,11 ), "~O~k",
				cmOK, bfDefault ) );
	deskTop->execView( pd );
    }
    CLY_destroy( pd );
}

//========================================================================
//  implementation of TNewDeskTop
//------------------------------------------------------------------------
TNewDeskTop::TNewDeskTop( const TRect& r ) :
		    TDeskInit( &initBackground ), 
	            TDeskTop( r )
{
}

//------------------------------------------------------------------------

TBackground *TNewDeskTop::initBackground( TRect r )
{
    // initializing the TBackground object allows us
    // to pass it a character for the desktop pattern
    return new TNewBackground( r, PATTERN );
}


//========================================================================
//  implementation of TNewBackground
//------------------------------------------------------------------------

TNewBackground::TNewBackground( const TRect& r, char pattern ) :
			TBackground( r, pattern )
{
}

//========================================================================
int main(void)
{
    TApp myApp;
    myApp.run();
    return 0;
}