BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tranformation

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Sabetay Toros
Guest





PostPosted: Fri Oct 03, 2003 3:51 pm    Post subject: Tranformation Reply with quote



Hi,


I'm using W2K operating system. In the following example I draw a sample
shape and Does not make the desired transfromations. All are the same.
Any ideas
Thanks

Sabetay

The .DFM file

object Form1: TForm1
Left = 241
Top = 318
Width = 870
Height = 640
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object Pb: TPaintBox
Left = 0
Top = 0
Width = 862
Height = 566
Align = alClient
end
object Panel1: TPanel
Left = 0
Top = 566
Width = 862
Height = 41
Align = alBottom
Caption = 'Panel1'
TabOrder = 0
object Button1: TButton
Left = 384
Top = 8
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
end

The header file
//--------------------------------------------------------------------------
-

#ifndef TransformH
#define TransformH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
enum TTransform {SCALE, TRANSLATE, ROTATE, SHEAR, REFLECT, NORMAL } ;
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TButton *Button1;
TPaintBox *Pb;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
TTransform trnsfrm;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void TransformAndDraw(int iTransform);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
The .cpp file

//--------------------------------------------------------------------------
-

#include <vcl.h>
#pragma hdrstop

#include "Transform.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner), trnsfrm(SCALE)
{

}
//--------------------------------------------------------------------------
-
// This section contains an example that demonstrates the following tasks:

//· Drawing graphics with predefined units.
//· Centering graphics in the application's client area.
//· Scaling graphics output to half its original size.
//· Translating graphics output 3/4 of an inch to the right.
//· Rotating graphics 30 degrees.
//· Shearing graphics output along the x-axis.
//· Reflecting graphics output about an imaginary horizontal axis drawn
through its midpoint.

//The following example was used to create the illustrations that appear
earlier in this topic.

void TForm1::TransformAndDraw(int iTransform)
{

HDC hDC;
XFORM xForm;
RECT rect;
TCanvas *cnvs = Pb->Canvas;
/* Retrieve a DC handle for the application's window. */

hDC = cnvs->Handle;



/*
* Set the mapping mode to LOENGLISH. This moves the
* client area origin from the upper left corner of the
* window to the lower left corner (this also reorients
* the y-axis so that drawing operations occur in a true
* Cartesian space). It guarantees portability so that

* the object drawn retains its dimensions on any
* display running Windows.
*/

SetMapMode(hDC, MM_LOENGLISH);

/*
* Set the appropriate world transformation (based on the
* user's menu selection).
*/

switch (iTransform) {
case SCALE: /* Scale to 1/2 of the original size. */
xForm.eM11 = (FLOAT) 0.5;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 0.5;

xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case TRANSLATE: /* Translate right by 3/4 inch. */
xForm.eM11 = (FLOAT) 1.0;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 1.0;
xForm.eDx = (FLOAT) 75.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);

break;

case ROTATE: /* Rotate 30 degrees counterclockwise. */
xForm.eM11 = (FLOAT) 0.8660;
xForm.eM12 = (FLOAT) 0.5000;
xForm.eM21 = (FLOAT) -0.5000;
xForm.eM22 = (FLOAT) 0.8660;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case SHEAR: /* Shear along the x-axis with a */

/* proportionality constant of 1.0. */
xForm.eM11 = (FLOAT) 1.0;
xForm.eM12 = (FLOAT) 1.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 1.0;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case REFLECT: /* Reflect about a horizontal axis. */
xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) -1.0;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case NORMAL: /* Set the unity transformation. */
xForm.eM11 = (FLOAT) 1.0;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 1.0;

xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

}

/* Find the midpoint of the client area. */

//GetClientRect(hWnd, (LPRECT) &rect);
rect = GetClientRect();
DPtoLP(hDC, (LPPOINT) &rect, 2);

/* Select a hollow brush. */


cnvs->Brush->Style = bsSolid;
/* Draw the exterior circle. */

cnvs->Ellipse((rect.right / 2 - 100), (rect.bottom / 2 + 100),
(rect.right / 2 + 100), (rect.bottom / 2 - 100));

/* Draw the interior circle. */

cnvs->Ellipse((rect.right / 2 - 94), (rect.bottom / 2 + 94),
(rect.right / 2 + 94), (rect.bottom / 2 - 94));

/* Draw the key. */

cnvs->Rectangle( (rect.right / 2 - 13), (rect.bottom / 2 + 113),
(rect.right / 2 + 13), (rect.bottom / 2 + 50));
cnvs->Rectangle( (rect.right / 2 - 13), (rect.bottom / 2 + 96),
(rect.right / 2 + 13), (rect.bottom / 2 + 50));

/* Draw the horizontal lines. */


cnvs->MoveTo( (rect.right / 2 - 150), (rect.bottom / 2 + 0));
cnvs->LineTo( (rect.right / 2 - 16), (rect.bottom / 2 + 0));

cnvs->MoveTo((rect.right / 2 - 13), (rect.bottom / 2 + 0));
cnvs->LineTo( (rect.right / 2 + 13), (rect.bottom / 2 + 0));

cnvs->MoveTo( (rect.right / 2 + 16), (rect.bottom / 2 + 0));
cnvs->LineTo( (rect.right / 2 + 150), (rect.bottom / 2 + 0));



/* Draw the vertical lines. */


cnvs->MoveTo( (rect.right / 2 + 0), (rect.bottom / 2 - 150));
cnvs->LineTo( (rect.right / 2 + 0), (rect.bottom / 2 - 16));

cnvs->MoveTo( (rect.right / 2 + 0), (rect.bottom / 2 - 13));
cnvs->LineTo( (rect.right / 2 + 0), (rect.bottom / 2 + 13));

cnvs->MoveTo( (rect.right / 2 + 0), (rect.bottom / 2 + 16));
cnvs->LineTo( (rect.right / 2 + 0), (rect.bottom / 2 + 150));


}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
// trnsfrm = ROTATE;
TransformAndDraw(trnsfrm);
if (trnsfrm == NORMAL) trnsfrm = SCALE;
else if (trnsfrm == SCALE ) trnsfrm = TRANSLATE;
else if (trnsfrm == TRANSLATE ) trnsfrm = ROTATE;
else if (trnsfrm == ROTATE ) trnsfrm = SHEAR;
else if (trnsfrm == SHEAR ) trnsfrm = REFLECT;
else if (trnsfrm == REFLECT ) trnsfrm = NORMAL;
}
//--------------------------------------------------------------------------
-


Back to top
Jacob E. Olsson
Guest





PostPosted: Fri Oct 03, 2003 9:04 pm    Post subject: Re: Tranformation Reply with quote



Hello

Set the following:
SetGraphicsMode( hDC, GM_ADVANCED );
just belowe:
SetMapMode(hDC, MM_LOENGLISH);
this in you code then you will see the result.

Best regards

Jacob E. Olsson

"Sabetay Toros" <bilsarbiz (AT) ttnet (DOT) net.tr> wrote

Quote:
Hi,


I'm using W2K operating system. In the following example I draw a sample
shape and Does not make the desired transfromations. All are the same.
Any ideas
Thanks

Sabetay

The .DFM file

object Form1: TForm1
Left = 241
Top = 318
Width = 870
Height = 640
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object Pb: TPaintBox
Left = 0
Top = 0
Width = 862
Height = 566
Align = alClient
end
object Panel1: TPanel
Left = 0
Top = 566
Width = 862
Height = 41
Align = alBottom
Caption = 'Panel1'
TabOrder = 0
object Button1: TButton
Left = 384
Top = 8
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
end

The header file

//--------------------------------------------------------------------------
-

#ifndef TransformH
#define TransformH

//--------------------------------------------------------------------------
-
#include <Classes.hpp
#include #include #include #include enum TTransform {SCALE, TRANSLATE, ROTATE, SHEAR, REFLECT, NORMAL } ;

//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TButton *Button1;
TPaintBox *Pb;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
TTransform trnsfrm;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void TransformAndDraw(int iTransform);
};

//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;

//--------------------------------------------------------------------------
-
#endif
The .cpp file


//--------------------------------------------------------------------------
-

#include #pragma hdrstop

#include "Transform.h"

//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner), trnsfrm(SCALE)
{

}

//--------------------------------------------------------------------------
-
// This section contains an example that demonstrates the following tasks:

//· Drawing graphics with predefined units.
//· Centering graphics in the application's client area.
//· Scaling graphics output to half its original size.
//· Translating graphics output 3/4 of an inch to the right.
//· Rotating graphics 30 degrees.
//· Shearing graphics output along the x-axis.
//· Reflecting graphics output about an imaginary horizontal axis drawn
through its midpoint.

//The following example was used to create the illustrations that appear
earlier in this topic.

void TForm1::TransformAndDraw(int iTransform)
{

HDC hDC;
XFORM xForm;
RECT rect;
TCanvas *cnvs = Pb->Canvas;
/* Retrieve a DC handle for the application's window. */

hDC = cnvs->Handle;



/*
* Set the mapping mode to LOENGLISH. This moves the
* client area origin from the upper left corner of the
* window to the lower left corner (this also reorients
* the y-axis so that drawing operations occur in a true
* Cartesian space). It guarantees portability so that

* the object drawn retains its dimensions on any
* display running Windows.
*/

SetMapMode(hDC, MM_LOENGLISH);

/*
* Set the appropriate world transformation (based on the
* user's menu selection).
*/

switch (iTransform) {
case SCALE: /* Scale to 1/2 of the original size. */
xForm.eM11 = (FLOAT) 0.5;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 0.5;

xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case TRANSLATE: /* Translate right by 3/4 inch. */
xForm.eM11 = (FLOAT) 1.0;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 1.0;
xForm.eDx = (FLOAT) 75.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);

break;

case ROTATE: /* Rotate 30 degrees counterclockwise. */
xForm.eM11 = (FLOAT) 0.8660;
xForm.eM12 = (FLOAT) 0.5000;
xForm.eM21 = (FLOAT) -0.5000;
xForm.eM22 = (FLOAT) 0.8660;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case SHEAR: /* Shear along the x-axis with a */

/* proportionality constant of 1.0. */
xForm.eM11 = (FLOAT) 1.0;
xForm.eM12 = (FLOAT) 1.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 1.0;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case REFLECT: /* Reflect about a horizontal axis. */
xForm.eM11 = (FLOAT) 1.0;

xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) -1.0;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

case NORMAL: /* Set the unity transformation. */
xForm.eM11 = (FLOAT) 1.0;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 1.0;

xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform(hDC, &xForm);
break;

}

/* Find the midpoint of the client area. */

//GetClientRect(hWnd, (LPRECT) &rect);
rect = GetClientRect();
DPtoLP(hDC, (LPPOINT) &rect, 2);

/* Select a hollow brush. */


cnvs->Brush->Style = bsSolid;
/* Draw the exterior circle. */

cnvs->Ellipse((rect.right / 2 - 100), (rect.bottom / 2 + 100),
(rect.right / 2 + 100), (rect.bottom / 2 - 100));

/* Draw the interior circle. */

cnvs->Ellipse((rect.right / 2 - 94), (rect.bottom / 2 + 94),
(rect.right / 2 + 94), (rect.bottom / 2 - 94));

/* Draw the key. */

cnvs->Rectangle( (rect.right / 2 - 13), (rect.bottom / 2 + 113),
(rect.right / 2 + 13), (rect.bottom / 2 + 50));
cnvs->Rectangle( (rect.right / 2 - 13), (rect.bottom / 2 + 96),
(rect.right / 2 + 13), (rect.bottom / 2 + 50));

/* Draw the horizontal lines. */


cnvs->MoveTo( (rect.right / 2 - 150), (rect.bottom / 2 + 0));
cnvs->LineTo( (rect.right / 2 - 16), (rect.bottom / 2 + 0));

cnvs->MoveTo((rect.right / 2 - 13), (rect.bottom / 2 + 0));
cnvs->LineTo( (rect.right / 2 + 13), (rect.bottom / 2 + 0));

cnvs->MoveTo( (rect.right / 2 + 16), (rect.bottom / 2 + 0));
cnvs->LineTo( (rect.right / 2 + 150), (rect.bottom / 2 + 0));



/* Draw the vertical lines. */


cnvs->MoveTo( (rect.right / 2 + 0), (rect.bottom / 2 - 150));
cnvs->LineTo( (rect.right / 2 + 0), (rect.bottom / 2 - 16));

cnvs->MoveTo( (rect.right / 2 + 0), (rect.bottom / 2 - 13));
cnvs->LineTo( (rect.right / 2 + 0), (rect.bottom / 2 + 13));

cnvs->MoveTo( (rect.right / 2 + 0), (rect.bottom / 2 + 16));
cnvs->LineTo( (rect.right / 2 + 0), (rect.bottom / 2 + 150));


}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
// trnsfrm = ROTATE;
TransformAndDraw(trnsfrm);
if (trnsfrm == NORMAL) trnsfrm = SCALE;
else if (trnsfrm == SCALE ) trnsfrm = TRANSLATE;
else if (trnsfrm == TRANSLATE ) trnsfrm = ROTATE;
else if (trnsfrm == ROTATE ) trnsfrm = SHEAR;
else if (trnsfrm == SHEAR ) trnsfrm = REFLECT;
else if (trnsfrm == REFLECT ) trnsfrm = NORMAL;
}

//--------------------------------------------------------------------------
-





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.