Lines


Poly Line

It is possible to draw several connected straight lines using Polyline. Every time a drawing command is executed, a set of instructions flow from the processor to the video card. Thus, Polyline is faster than drawing the same lines separately. The code shown below creates an array of points to draw a square. Observe that the first and last points in the array are the same so that the figure can be a closed shape.
Es posible dibujar varias líneas rectas conectadas usando Polyline. Cada vez que un comando de dibujo se ejecuta, un conjunto de instrucciones viaja desde el procesador a la tarjeta de video. Así, Polyline es más rápida que dibujar las mismas líneas por separado. El código mostrado debajo crea un arreglo de puntos para dibujar un cuadrado. Observe que el primer y último punto en el arreglo son los mismos para que la silueta quede cerrada.

Program.h
void Program::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     POINT points[5] = {100, 100, 200, 100, 200, 200, 100, 200, 100, 100 };
     gdi.Polyline(points, 5);
}

Polyline

WM_SIZE or Window_Size

The operating system sends the message WM_SIZE or calls the function Window_Size every time the window changes of size. This message is usually receives before the window is painted. This message is useful to make any computation that depends on the size of the window.
El sistema operativo envia el mensaje WM_SIZE o llama la función Window_Size cada vez que la ventana cambia de tamaño. Este mensaje usualmente se recibe antes de que la ventana se pinte. Este mensaje es útil para hacer cualquier cálculo que dependa del tamaño de la ventana.

Problem 1
Create a program called Seno to draw a sine wave a shown using Microsoft GDI. Use the event Window_Size to compute the coordinates of the points.
Cree un programa llamado Seno para dibujar una onda senoidal como se muestra usando Microsoft GDI. Use el evento Window_Size para calcular las coordenadas de los puntos.

Seno1

Seno2

Seno.h
#pragma once //______________________________________ Seno.h
#include "resource.h"
#define POINT_COUNT 1024
class Seno: public Win::Window
{
public:
     Seno()
     {
     }
     ~Seno()
     {
     }
     POINT graph[POINT_COUNT];
     const wchar_t * GetClassName(){return L"SENO";}
protected:
     . . .
};


Seno.cpp
#include "stdafx.h" //________________________________________ Seno.cpp
#include "Seno.h"

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR cmdLine, int cmdShow){
     Seno app;
     CG::Brush blackBrush(RGB(0, 0, 0));
     app.CreateMainWindow(L"Seno", cmdShow, IDI_SENO, NULL, blackBrush, hInstance);
     return app.MessageLoop(IDC_SENO);
}

void Seno::Window_Open(Win::Event& e)
{     
}

void Seno::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     CG::Pen pen;
     pen.Create(PS_SOLID, 3, RGB(0, 255, 0));
     gdi.Select(pen);
     gdi.Polyline(graph, POINT_COUNT);
}

void Seno::Window_Size(Win::Event& e)
{
     . . .
     for (int i = 0; i < POINT_COUNT; i++)
     {
          graph[i].x = . . . ;
          graph[i].y = . . . ;
     }
}


Problem 2
Create a program called SenoD to draw a sine wave a shown using Microsoft Direct2D. Use the event Window_Size to compute the coordinates of the points.
Cree un programa llamado SenoD para dibujar una onda senoidal como se muestra usando Microsoft Direct2D. Use el evento Window_Size para calcular las coordenadas de los puntos.

SenoDRun

SenoD.h
#pragma once //______________________________________ SenoD.h
#include "Resource.h"
#define POINT_COUNT 1024

class SenoD: public Win::Window
{
public:
     SenoD()
     {
     }
     ~SenoD()
     {
     }
     Direct::Graphics graphics;
     Direct::SolidBrush brushGreen;
     Direct::PathGeometry geometry;
     . . .
};


SenoD.cpp
. . .
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR cmdLine, int cmdShow){
     SenoD app;
     app.CreateMainWindow(L"SenoD", cmdShow, IDI_SenoD, NULL, (HBRUSH)::GetStockObject(NULL_BRUSH), hInstance);
     return app.MessageLoop(IDC_SenoD);
}

void SenoD::Window_Open(Win::Event& e)
{
     brushGreen.Create(graphics, . . .); // red, green, blue, alpha
}

void SenoD::Window_Paint(Win::Event& e)
{
     if (graphics.BeginDraw(hWnd, width, height, . . .) == false) return; // red, green, blue, alpha
     graphics.SetTransform(D2D1::Matrix3x2F::Identity());
     graphics.DrawGeometry(geometry, brushGreen, 2.0f);
     graphics.EndDraw(true);
}

void SenoD::Window_Size(Win::Event& e)
{
     graphics.Resize(hWnd, width, height);
     D2D1_SIZE_F size = graphics.GetSize();
     const float scaleX = (float)(4.0*M_PI/size.width); // units/pixels
     const float deltaX = size.width /POINT_COUNT; // pixels
     const float deltaY = size.height / 2.0f;
     D2D1_POINT_2F graph[POINT_COUNT];
     //____________________________________________________________ 1. Create geometry
     geometry.Open(graphics);
     geometry.SetFillMode(D2D1_FILL_MODE_WINDING);
     geometry.BeginFigure(D2D1::Point2F(0.0f, deltaY), D2D1_FIGURE_BEGIN_FILLED);
     //____________________________________________________________ 2. Compute points
     for (int i = 0; i < POINT_COUNT; i++)
     {
          graph[i].x = . . .;
          graph[i].y = . . .;
     }
     geometry.AddLines(graph, POINT_COUNT);
     geometry.EndFigure(D2D1_FIGURE_END_OPEN);
     geometry.Close();
}


Problem 3
Create a Wintempla Window application called Periodic to draw the periodic table of elements wave a shown. After creating the application check the Paint and LButtonDown events. The program will require a dialog called ElementDlg with a label. The program also requires a class called ElementInfo to store the information of each element, to add a class Project > Add Class ....
Cree una Aplicación de Ventana con Wintempla llamado Periodic para dibujar la tabla periódica de los elementos como se muestra. Después de crear la aplicación marque los eventos de Paint y LButtonDown. El programa requerirá de un diálogo llamado ElementDlg con una etiqueta. El programa también requiere de una clase llamada ElementInfo para almacenar la información de cada elemento, para agregar una clase Project > Add Class ....

PeriodicRun1

PeriodicRun2

Periodic.h
#pragma once //______________________________________ Periodic.h
#include "Resource.h"
#include "ElementInfo.h"
#include "ElementDlg.h"
#define COLUMN_COUNT 18
#define ROW_COUNT 7

class Periodic: public Win::Window
{
public:
     Periodic()
     {
     }
     ~Periodic()
     {
     }
     vector<ElementInfo> element;
     const wchar_t * GetClassName(){return L"Periodic";}
protected:
     ...
};


Periodic.cpp
void Periodic::Window_Open(Win::Event& e)
{
     element.push_back(ElementInfo(1, 1.008, L"Hydrogen", L"H", 1, 1));
     element.push_back(ElementInfo(2, 4.003, L"Helium", L"He", 1, 18));
     ...
}

void Periodic::Window_LButtonDown(Win::Event& e)
{
     //____________________________________________________________________________ 1. Find row and column
     const short x = GET_X_LPARAM(e.lParam);
     const short y = GET_Y_LPARAM(e.lParam);
     const int deltaX = width/COLUMN_COUNT;
     const int deltaY = height/ROW_COUNT;
     const int row = y/deltaY;
     const int col = x/deltaX;
     //____________________________________________________________________________ 2. Find element_index
     ...

     //____________________________________________________________________________ 3. Open dialog
     if (element_index < elementCount)
     {
          ElementDlg dlg;
          ...
          dlg.BeginDialog(hWnd);
     }
}

void Periodic::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     const int deltaX = width/COLUMN_COUNT;
     const int deltaY = height/ROW_COUNT;
     CG::Font fontBig;
     fontBig.Create(L"Arial", PERCENT(30, deltaY), false, false, false, false);
     //
     CG::Font fontSmall;
     fontSmall.Create(L"Arial", PERCENT(15, deltaY), false, false, false, false);
     const int offset = PERCENT(5, deltaY);

     int i, j;
     int x, y;
     //_____________________________________________________ 1. Horizontal lines
     for (i = 0; i < ROW_COUNT; i++)
     {
          ...
     }
     //_____________________________________________________ 2. Vertical lines
     for (j = 0; j < COLUMN_COUNT; j++)
     {
          ...
     }
     //_____________________________________________________ 3. Elements
     RECT rect;
     int k;
     const int elementCount = (int)element.size();
     wchar_t text[32];
     for (i = 0; i < ROW_COUNT; i++)
     {
          for (j = 0; j < COLUMN_COUNT; j++)
          {
               ...
          }
     }
}


ElementDlg.cpp
#include "stdafx.h" //_____________________________________________ ElementDlg.cpp
#include "ElementDlg.h"

void ElementDlg::Window_Open(Win::Event& e)
{
     this->Text = caption;
     lbInfo.Text = text;
}

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