From 1e9fa8e06de5da7fcc268e9cccb2d6b21c5f53a3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 20 Jul 2024 20:15:52 +0900 Subject: Rename graphics class nt* related files to equivalent tq* (part 2) Signed-off-by: Michele Calgaro --- doc/html/tutorial1-12.html | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'doc/html/tutorial1-12.html') diff --git a/doc/html/tutorial1-12.html b/doc/html/tutorial1-12.html index 7aef83897..3a90243c8 100644 --- a/doc/html/tutorial1-12.html +++ b/doc/html/tutorial1-12.html @@ -161,10 +161,10 @@ hit the target).

        void  paintTarget( TQPainter * );
 

This private function paints the target. -

        TQRect targetRect() const;
+

        TQRect targetRect() const;
 

This private function returns the enclosing rectangle of the target. -

        TQPoint target;
+

        TQPoint target;
 

This private variable contains the center point of the target.

t12/cannon.cpp @@ -192,10 +192,10 @@ repaint() on a hidden widget. TQTime midnight( 0, 0, 0 ); srand( midnight.secsTo(TQTime::currentTime()) ); } - TQRegion r( targetRect() ); + TQRegion r( targetRect() ); target = TQPoint( 200 + rand() % 190, 10 + rand() % 255 ); - repaint( r.unite( targetRect() ) ); + repaint( r.unite( targetRect() ) ); }

This private function creates a target center point at a new "random" @@ -225,13 +225,13 @@ the left edge and with x values increasing to the right.

Note that rand() returns a random integer >= 0.

    void CannonField::moveShot()
     {
-        TQRegion r( shotRect() );
+        TQRegion r( shotRect() );
         timerCount++;
 
-        TQRect shotR = shotRect();
+        TQRect shotR = shotRect();
 

This part of the timer event has not changed from the previous chapter. -

        if ( shotR.intersects( targetRect() ) ) {
+

        if ( shotR.intersects( targetRect() ) ) {
             autoShootTimer->stop();
             emit hit();
 
@@ -242,7 +242,7 @@ world that a target was destroyed, and return.

Note that we could have created a new target on the spot, but because the CannonField is a component we leave such decisions to the user of the component. -

        } else if ( shotR.x() > width() || shotR.y() > height() ) {
+

        } else if ( shotR.x() > width() || shotR.y() > height() ) {
             autoShootTimer->stop();
             emit missed();
 
@@ -254,7 +254,7 @@ failure.

And the rest of the function is as before.

CannonField::paintEvent() is as before, except that this has been added: -

        if ( updateR.intersects( targetRect() ) )
+

        if ( updateR.intersects( targetRect() ) )
             paintTarget( &p );
 

These two lines make sure that the target is also painted when necessary. @@ -269,15 +269,15 @@ added: with a black outline.

    TQRect CannonField::targetRect() const
     {
-        TQRect r( 0, 0, 20, 10 );
-        r.moveCenter( TQPoint(target.x(),height() - 1 - target.y()) );
+        TQRect r( 0, 0, 20, 10 );
+        r.moveCenter( TQPoint(target.x(),height() - 1 - target.y()) );
         return r;
     }
 

This private function returns the enclosing rectangle of the target. Remember from newTarget() that the target point uses y coordinate 0 at the bottom of the widget. We calculate the point in widget coordinates -before we call TQRect::moveCenter(). +before we call TQRect::moveCenter().

The reason we have chosen this coordinate mapping is to fix the distance between the target and the bottom of the widget. Remember that the widget can be resized by the user or the program at any time. @@ -305,7 +305,7 @@ makefile and build the application.)

Make a cheat button that, when pressed, makes the CannonField display the shot trajectory for five seconds.

If you did the "round shot" exercise from the previous chapter, try -changing the shotRect() to a shotRegion() that returns a TQRegion so +changing the shotRect() to a shotRegion() that returns a TQRegion so you can have really accurate collision detection.

Make a moving target.

Make sure that the target is always created entirely on-screen. -- cgit v1.2.3