I made a simple Turbo Vision application, based in part on the example in the old Borland manual. Adapting the random number generator, I made it fixed to the size of the desktop.
In modern terminal emulators, the desktop size can change; I can trivially test this even in Windows.
Is there a simple way to adapt this to flexible desktop sizes?
// In the class
std::default_random_engine generator;
std::uniform_int_distribution<int> x_distribution, y_distribution;
int random_x() { return x_distribution( generator ); }
int random_y() { return y_distribution( generator ); }
//constructor
TMyApp::TMyApp() :
TProgInit( &TMyApp::initStatusLine,
&TMyApp::initMenuBar,
&TMyApp::initDeskTop ),
x_distribution( 0, size.x - 26 /* width of desktop */ ),
y_distribution( 0, size.y - 7 /* height of desktop */ )
{
}
//window creation
void TMyApp::myNewWindow() {
TRect r( 0, 0, 26, 7 );
r.move( random_x(), random_y() );
TMyWindow *window = new TMyWindow( r, "My Window", ++winNumber );
deskTop->insert( window ); // attache and draw it.
}```