#Making C++ Random Generator Flexible for Turbo Vision Desktop Resize?

7 messages · Page 1 of 1 (latest)

shut lichen
#

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.
}```
prime voidBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

raw surge
#

If you have some way of detecting the new terminal size, you can use x_distribution.param({ 0, new_size.x - 26 }) or something to change the distribution's parameters on resize

shut lichen
#

Right, thanks.

#

!solved

prime voidBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] Making C++ Random Generator Flexible for Turbo Vision Desktop Resize?