1 //============================================================================
2 //
3 //   SSSS    tt          lll  lll
4 //  SS  SS   tt           ll   ll
5 //  SS     tttttt  eeee   ll   ll   aaaa
6 //   SSSS    tt   ee  ee  ll   ll      aa
7 //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
8 //  SS  SS   tt   ee      ll   ll  aa  aa
9 //   SSSS     ttt  eeeee llll llll  aaaaa
10 //
11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
12 // and the Stella Team
13 //
14 // See the file "License.txt" for information on usage and redistribution of
15 // this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 //============================================================================
17 
18 #include "Dialog.hxx"
19 #include "FrameBufferConstants.hxx"
20 #include "TimeMachineDialog.hxx"
21 #include "TimeMachine.hxx"
22 
23 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TimeMachine(OSystem & osystem)24 TimeMachine::TimeMachine(OSystem& osystem)
25   : DialogContainer(osystem),
26     myWidth{FBMinimum::Width}
27 {
28   myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth);
29 }
30 
31 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
~TimeMachine()32 TimeMachine::~TimeMachine()
33 {
34   delete myBaseDialog;  myBaseDialog = nullptr;
35 }
36 
37 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
requestResize()38 void TimeMachine::requestResize()
39 {
40   uInt32 w = 0, h = 0;
41   myBaseDialog->getDynamicBounds(w, h);
42 
43   // Only re-create when absolutely necessary
44   if(myWidth != w)
45   {
46     myWidth = w;
47     Dialog* oldPtr = myBaseDialog;
48     Int32 enterWinds = static_cast<TimeMachineDialog*>(myBaseDialog)->getEnterWinds();
49     delete myBaseDialog;
50     myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth);
51     setEnterWinds(enterWinds);
52     Dialog* newPtr = myBaseDialog;
53 
54     // Update the container stack; it may contain a reference to the old pointer
55     if(oldPtr != newPtr)
56     {
57       myDialogStack.applyAll([&oldPtr,&newPtr](Dialog*& d){
58         if(d == oldPtr)
59           d = newPtr;
60         });
61     }
62   }
63 }
64 
65 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
baseDialog()66 Dialog* TimeMachine::baseDialog()
67 {
68   return myBaseDialog;
69 }
70 
71 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setEnterWinds(Int32 numWinds)72 void TimeMachine::setEnterWinds(Int32 numWinds)
73 {
74   static_cast<TimeMachineDialog*>(myBaseDialog)->setEnterWinds(numWinds);
75 }
76