Review


Problem 1
Write a program called Tiro to visualize a parabolic throw using a SimulationView control.
Escriba un programa llamado Tiro para visualizar un tiro parabólico usando el control SimulationView.

Tiro

Tiro.h
#pragma once //______________________________________ Tiro.h
#include "resource.h"
#define PIXELS_PER_METER 100
class Tiro: public Win::Dialog
{
public:
     Tiro()
     {
          vox = 0.0;
          voy = 0.0;
     }
     ~Tiro()
     {
     }
     double vox;
     double voy;
protected:
     ...
};

Tiro.cpp
void Tiro::Window_Open(Win::Event& e)
{
     this->tbxSpeed.DoubleValue = 10.0; // 10 m/s
     this->tbxAngle.DoubleValue = 40.0;
     this->simvView.Start(10);
}

void Tiro::simvView_Paint(Win::Event& e)
{
     CG::Gdi &gdi = *((CG::Gdi*)(e.lParam));
     const double t = simvView.time.GetSeconds();
     const int Width = simvView.GetWidth();
     const int Height = simvView.GetHeight();
     const int ballRadio = (int)(0.1*PIXELS_PER_METER+0.5); // 0.1 meters
     const double g = 9.81*PIXELS_PER_METER; // 9.81 m/s2

     const int x = (int)(ballRadio*2 + vox*t+0.5); // x = x0 + vx * t
     const int y = (int)(3.0*Height/4.0 - 2*ballRadio - voy*t+ 0.5*g*t*t+0.5); // y = y0 - (vy0*t + 1/2 * g * t*t);
     //____________________________ Paint object
     CG::Brush brushObject(RGB(200, 0, 200));
     gdi.Select(brushObject);
     gdi.Circle(x, y, ballRadio);
}

void Tiro::btSimulate_Click(Win::Event& e)
{
     const double speed = tbxSpeed.DoubleValue;
     const double angleRad = tbxAngle.DoubleValue*M_PI/180.0; // Convert to radians
     vox = speed*cos(angleRad)*PIXELS_PER_METER;
     voy = speed*sin(angleRad)*PIXELS_PER_METER;
     simvView.time.Start();
}

Tip
The next example uses a timer. During Window_Open the timer 1 is set to fire every 20000 milliseconds. The function Window_Timer is called every 20 seconds. When the window is closed the timer is killed (more information can be found in Wintempla > GUI > Progress Bar and Timer .
El próximo ejemplo se usa un timer. Durante Window_Open el timer 1 se fija para que se active cada 20000 milliseconds. La función Window_Timer es llamada cada 20 segundos. Cuando la ventana se cierra el timer se cancelar (más información se puede encontrar en Wintempla > GUI > Progress Bar and Timer .

Problem 2
Repeat the previous problem to display an ICON (an image) instead of the circle in the previous problem. Call your project Rocket. Using resource view to add an Icon called IDI_SHIP as shown
Modifique el problema previo para mostrar un ICONO (una imagen) en lugar del círculo en el problema previo. Llame a su proyecto Rocket. Use la Vista de Recurso para agregar un icono llamada IDI_SHIP como se muestra. FIGPNG ship

Rocket.h
#pragma once //______________________________________ Rocket.h
#include "Resource.h"
#define PIXELS_PER_METER 100
class Rocket: public Win::Dialog
{
public:
     Rocket()
     {
          vox = 0.0;
          voy = 0.0;
     }
     ~Rocket()
     {
     }
     Sys::Icon icon;
     double vox;
     double voy;
     ...
};


Rocket.cpp
...
void Rocket::Window_Open(Win::Event& e)
{
     icon.Load(hInstance, IDI_SHIP, 40, 40);
     this->tbxSpeed.DoubleValue = 10.0; // 10 m/s
     this->tbxAngle.DoubleValue = 40.0;
     this->simvView.Start(10);
}

void Rocket::simvView_Paint(Win::Event& e)
{
     CG::Gdi &gdi = *((CG::Gdi*)(e.lParam));
     const double t = simvView.time.GetSeconds();
     const int Width = simvView.GetWidth();
     const int Height = simvView.GetHeight();
     const int ballRadio = (int)(0.1*PIXELS_PER_METER+0.5); // 0.1 meters
     const double g = 9.81*PIXELS_PER_METER; // 9.81 m/s2

     const int x = (int)(ballRadio*2 + vox*t+0.5); // x = x0 + vx * t
     const int y = (int)(Height/2.0 - 2*ballRadio - voy*t+ 0.5*g*t*t+0.5); // y = y0 - (vy0*t + 1/2 * g * t*t);
     //____________________________ Draw Ship
     gdi.DrawIcon(x, y, icon);
}

void Rocket::btSimulate_Click(Win::Event& e)
{
     const double speed = tbxSpeed.DoubleValue;
     const double angleRad = tbxAngle.DoubleValue*M_PI/180.0; // Convert to radians
     vox = speed*cos(angleRad)*PIXELS_PER_METER;
     voy = speed*sin(angleRad)*PIXELS_PER_METER;
     simvView.time.Start();
}

RocketRun

Problem 3
Write a Window Application called WallClock to draw a clock with the current time.
Escriba una aplicación de ventana llamada WallClock para dibujar un reloj usando la hora actual.

WallClock1

WallClock2

WallClock.cpp
void WallClock::Window_Open(Win::Event& e)
{
     this->timer.Set(1, 20000);
}

void WallClock::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);

     CG::Pen pen;
     pen.Create(PS_SOLID, 3, RGB(80, 80, 100));
     gdi.Select(pen);
     //_________________________________________ Round Rectangle
     ...
     gdi.RoundRect(...);
     //_________________________________________ Circle
     CG::Brush brushGray(RGB(245, 245, 245));
     const int radius =(int)( MINIMUM(width/2-40, height/2-40)*0.8 +0.5);
     gdi.Select(brushGray);
     gdi.Circle(...);
     //_________________________________________ Numbers
     double angle = -60.0;
     int x, y;
     CG::Font font(L"Times New Roman", radius/5);
     gdi.Select(font);
     gdi.SetTextColor(RGB(100, 100, 255));
     gdi.SetBkMode(true);
     SIZE size;
     wchar_t text[32];
     for(int i = 1; i <= 12; i++, angle+=30.0)
     {
          x =(int)(...);
          y = (int)(...);
          _snwprintf_s(text, 32, _TRUNCATE, L"%d", i);
          gdi.GetTextExtentPoint32(text, size);
          gdi.TextOut(x - size.cx/2, y - size.cy/2, text);
     }
     //________________________________________ Small Hand
     Sys::Time now;
     angle = ...;
     x =(int)(...);
     y = (int)(...);
     gdi.Line(width/2, height/2, x, y);
     //________________________________________ Big Hand
     angle = ...;
     x =(int)(...);
     y = (int)(...);
     gdi.Line(width/2, height/2, x, y);
     //_________________________________________ Center
     CG::Brush brushCenter(RGB(190, 190, 210));
     gdi.Select(brushCenter);
     gdi.Circle(width/2, height/2, radius/19);
}

void WallClock::Window_Timer(Win::Event& e)
{
     this->Repaint(NULL, true);
}

void WallClock::Window_Close(Win::Event& e)
{
     this->timer.Kill(1);
     e.returnValue = ::DefWindowProc(hWnd, WM_CLOSE, e.wParam, e.lParam);
}

Tip
When a window is painted with several colors one over the other one, this may produce some flickering when the window is resized. It is recommended, if possible, to paint the window just once. To do this, the window background can be painted using the NULL brush. It is also possible to use the style WS_CLIPCHILDREN to reduce the flickering.
Cuando se pintan colores encima de otros en forma rápida se produce parpadeo en la imagen cuando la ventana cambia de tamaño. Se recomienda en lo posible pintar la superficie de la ventana sólo una vez. Para esto se puede crear una ventana con un fondo que se pinta con la brocha nula. También se puede utilizar el estilo WS_CLIPCHILDREN para minimizar el parpadeo.

Region and Path

There are two GDI objects to create complex objects: the region and the path. The main functions to manipulate regions are paths are: CreateRectRgn(), CreateRectRgnIndirect(), CreateEllipticRgn(), CreateEllipticRgnIndirect(), CreatePolygonRgn(), CombineRgn(), ValidateRgn(), InvalidateRgn(), SelectClipRgn(), BeginPath(hdc), EndPath(hdc), FillPath().
Existen dos objectos GDI útiles para crear objetos complejos: la región y el path. Las principales API's para manipular regiones y paths son: CreateRectRgn(), CreateRectRgnIndirect(), CreateEllipticRgn(), CreateEllipticRgnIndirect(), CreatePolygonRgn(), CombineRgn(), ValidateRgn(), InvalidateRgn(), SelectClipRgn(), BeginPath(hdc), EndPath(hdc), FillPath().

Problem 4
Create a Window Application called PuertoRico to draw the flag of Puerto Rico.
Cree una aplicación de ventana llamada PuertoRico para dibujar la bandera de Puerto Rico.

PuertoRico1

PuertoRico2

PuertoRico.cpp
void PuertoRico::Window_Open(Win::Event& e)
{
}

void PuertoRico::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     CG::Brush brushBlue(RGB(30, 40, 220));
     CG::Brush brushRed(RGB(255, 0, 39));
     gdi.SelectNullPen();

     const double redBandHeight = height/5.0;

     double y;
     //______________________________________ Red Bands
     gdi.Select(brushRed);
     ...

     //______________________________________ Blue Triangle
     POINT point[4];
     point[0].x = ...;
     point[0].y = ...;
     point[1].x = ...;
     point[1].y = ...;
     point[2].x = ...;
     point[2].y = ...;
     point[3].x = ...;
     point[3].y = ...;
     //__________________ Option 1
     gdi.BeginPath();
     gdi.Polyline(point, 4);
     gdi.EndPath();
     gdi.Select(brushBlue);
     gdi.FillPath();
     //__________________ Option 2
     //gdi.Select(brushBlue);
     //gdi.Polygon(point, 3);
     //______________________________________ Star
     CG::Font font(L"Wingdings", height/2);
     ...
}


© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home