Upload
rajesh1158
View
236
Download
0
Embed Size (px)
Citation preview
8/9/2019 Mapping Modes
1/50
VISUAL PROGRAMMING
8/9/2019 Mapping Modes
2/50
COLORS
8/9/2019 Mapping Modes
3/50
COLOR
- one the most fundamental objects that enhances the aesthetic
appearance of an object
- non-spatial object that is added to an object to modify some of
its visual aspects
-Three numeric values are used to create a color
Red
Green
Blue
8/9/2019 Mapping Modes
4/50
COLOR
- Each one represented in 8-bits and the value for each color
ranges from 0-255
- These 3 colors can be combined to form other colors
- Using these 3 we can create approximately 16 million colors
(255*255*255=16581375)
8/9/2019 Mapping Modes
5/50
COLOR
- computer monitor has a surface that resembles a series of tiny
horizontal and vertical lines
- intersection of a one horizontal line and a vertical line is called a
pixel that holds, carries, or displays one color
- As the pixels close to each other have different colors, the effect
is a wonderful distortion that creates an aesthetic picture
8/9/2019 Mapping Modes
6/50
8/9/2019 Mapping Modes
7/50
8/9/2019 Mapping Modes
8/50
- After declaring initialize it with a 32-bit numeric value.It can be
done as follows
COLORREF NewColor = 16711935;
- Although the above number is a legitimate color value it doesnot mean much
- One macro is defined to create a color called RGB macro. Its
syntax is
COLORREF RGB(BYTE byRed, BYTE byGreen, BYTE
byBlue);
8/9/2019 Mapping Modes
9/50
RGB MACRO
- The RGB macro behaves like a function and allows you to pass
three numeric values separated by a comma.
- Each value must be between 0 and 255
- Initialization can be done as follows
COLORREF NewColor = RGB(255, 0, 255);
8/9/2019 Mapping Modes
10/50
8/9/2019 Mapping Modes
11/50
COLORING A PIXEL
- A pixel is the real object that holds a color
-The pixels are stored in an array of [x][y] value. To change thecolor of a pixel, you can call the CDC::SetPixel() method
- Its syntaxes are:
COLORREF SetPixel(int x, int y, COLORREF crColor);
COLORREF SetPixel(POINT point, COLORREF crColor);
8/9/2019 Mapping Modes
12/50
FONTS
8/9/2019 Mapping Modes
13/50
FONT
- A list of symbols that can be drawn on a device context to
produce a readable message
- FONT CREATION
- FONT SELECTION
8/9/2019 Mapping Modes
14/50
FONT CREATION
- Font is created as a variable of the CFont class which is based
on the CGdiObject
- To declare aC
Font variable use the default constructor asfollows
CFont NewFont;
- After declaring a CFont variable, you must initialize it. Callingone of the Create member functions can do
8/9/2019 Mapping Modes
15/50
- There are three class methods used for creating fonts
CreatePointFont
CreateFont CreateFontIndirect
8/9/2019 Mapping Modes
16/50
CreatePointFont Method
- Its syntax is
BOOL CreatePointFont(int nPointSize, LPCTSTR
lpszFaceName, CDC* pDC= NULL);
Where nPointSize is the height of the font
lpszFaceName is the name of the font or NULL
8/9/2019 Mapping Modes
17/50
void myframe::
OnLButtonDown(UINTnFlags,CPoint point)
{
CFont font;
CClientDC pDC(this);
font.CreatePointFont(920, "Arial");pDC.SelectObject(&font);
pDC.SetTextColor(RGB(0, 125, 250));
pDC.TextOut(20, 18, "Hello", 5);
}
8/9/2019 Mapping Modes
18/50
CreateFont Method
- Its syntax is
BOOL CreateFont( int nHeight,
int nWidth,
int nEscapement,
int nOrientation,
int nWeight,BYTE bItalic,
BYTE bUnderline,
BYTE cStrikeOut,
BYTE nCharSet,
BYTE nOutPrecision,
BYTE nClipPrecision,
BYTE nQuality,BYTE nPitchAndFamily,
LPCTSTRlpszFacename);
8/9/2019 Mapping Modes
19/50
CreateFont Method
- nHeight- height applied to the text.
- nWidth - desired width that will be applied on the text.
- nEscapement- angle used to orient the text (orientedcounterclockwise)
- nOrientation -angular orientation of the text with regards to thehorizontal axis.
- nWeight-Font weight
- bItalic specifies whether the font will be italicized (TRUE) ornot (FALSE).
- bUnderline is used to underline (TRUE) or not underline(FALSE) the text.
- cStrikeOutis specifies whether the text should be stroke out(TRUE) or not (FALSE) with a line.
8/9/2019 Mapping Modes
20/50
CreateFont Method
- nCharSet specifies the character set used
- nOutPrecision - amount precision used to evaluate the numeric
values used on this function for the height, the width, and angles
-nClipPrecisionamount ofclipping
-nQuality specifies how the function will attempt to match the
font's characteristics
-nPitchAndFamily specifies the category of the font used
-lpszFacename is the name of the font used
8/9/2019 Mapping Modes
21/50
void myframe::OnLButtonDown(UINT nFlags,CPoint
point)
{
CFont font;
font.CreateFont(46, 28, 215, 0,FW_NORMAL, FALSE,
FALSE, FALSE,ANSI_C HARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITC
H | FF_ROMAN, "Times NewRoman");
pDC->SelectObject(&font);
pDC->TextOut(20, 128, Hello", 5);
}
8/9/2019 Mapping Modes
22/50
CreateFontIndirect Method
-Its syntax is
BOOL CreateFontIndirect(const LOGFONT* lpLogFont);
- LOGFONT structure is used to define all the characteristics of
the font
8/9/2019 Mapping Modes
23/50
8/9/2019 Mapping Modes
24/50
void myframe::OnLButtonDown(UINT nFlags,CPoint
point)
{ CClientDC pDC(this);
CFont font;
LOGFONT LogFont;
LogFont.lfStrikeOut = 0;
LogFont.lfUnderline = 0;
LogFont.lfHeight = 42;
LogFont.lfEscapement = 0;
LogFont.lfItalic = TRUE;
font.CreateFontIndirect(&LogFont);
pDC.SelectObject(&font);pDC.TextOut(20, 18, Hello", 5);
}
8/9/2019 Mapping Modes
25/50
MAPPING MODES
8/9/2019 Mapping Modes
26/50
DEFAULT COORDINATE SYSTEM
- The coordinates of the drawing area are located on
the upper-left corner of the screen.
- The horizontal axis moves from (0,0) to the right and
the vertical axis moves from (0,0) down
- For example, consider the code for creating anellipse
0,0+X
+Y
8/9/2019 Mapping Modes
27/50
DEFAULT COORDINATE SYSTEM
void CExoDraw1View::OnPaint()
{
CPaintDC dc(this); // device context for painting// A circle whose center is at the origin (0, 0)dc.Ellipse(-50, -50, 50, 50);
// A line that starts at (0, 0) and ends at (100, 100)dc.MoveTo(0, 0);
dc.LineTo(100, 100);}
- The output of this is shown in the figure as follows
8/9/2019 Mapping Modes
28/50
8/9/2019 Mapping Modes
29/50
CHANGING COORDINATE SYSTEM
- The MFC provides various functions to deal with the coordinatespositions and extents of the drawing area .
- One such function is the CDC::SetViewportOrg(). The syntaxes ofthis method are
SetViewportOrg(int X, int Y);
SetViewportOrg(CPoint Pt);
- The function of this method is to change the origin of thecoordinate system
8/9/2019 Mapping Modes
30/50
CHANGING COORDINATE SYSTEM
- To see the effect of this method change the previous OnPaint()
method as follows
void CExoDraw1View::OnPaint()
{
CPaintDC dc(this); // device context for paintingdc.SetViewportOrg(200, 150);
// A circle whose center is at the origin (0, 0)dc.Ellipse(-50, -50, 50, 50);
// A line that starts at (0, 0) and ends at (100, 100)dc.MoveTo(0, 0);
dc.LineTo(100, 100);
}
8/9/2019 Mapping Modes
31/50
8/9/2019 Mapping Modes
32/50
MAP MODES
- To control the orientation of the axes of the device context , amethod called SetMapMode() is used.
- The syntax of this method is
int SetMapMode(int nMapMode);
- It performs two functions
-> controls the orientation of the coordinate system
-> helps with the unit system you would prefer to use.
8/9/2019 Mapping Modes
33/50
8/9/2019 Mapping Modes
34/50
MM_TEXT
- Default map mode
- With this map mode the dimensions or measurements specified inthe CDC methods are kept as it is.
- horizontal axis moves from (0, 0) to the right and the vertical axis
moves from (0, 0) down
- In general, no change is made to both the orientation and the
measurement units.
8/9/2019 Mapping Modes
35/50
MM_TEXT
void CExoDraw1View::OnPaint() {
CPaintDC dc(this); // device context for painting
dc.SetMapMode(MM_TEXT);
dc.SetViewportOrg(380, 220);
CPen PenRed(PS_SOLID, 1, RGB(255, 0, 0));dc.SelectObject(PenRed);
dc.Ellipse(-100, -100, 100, 100);
CPen PenBlue(PS_SOLID, 1, RGB(0, 0, 255));
dc.SelectObject(PenBlue);
dc.MoveTo(-380, 0); dc.LineTo(380, 0);dc.MoveTo(0, -220); dc.LineTo(0, 220);
CPen PenOrange(PS_SOLID, 1, RGB(255, 128, 0));
dc.SelectObject(PenOrange);
// A diagonal line at 45 degrees
dc.MoveTo(0, 0); dc.LineTo(120, 120); }
8/9/2019 Mapping Modes
36/50
MM_TEXT
8/9/2019 Mapping Modes
37/50
MM_LOENGLISH
- It performs two actions
* It changes the orientation of the vertical axis: the positivey axis would move from (0, 0) up
* Each unit of measure provided is divided by 100
(unit/100)
- If we change the map mode in the previous code to
MM_LOENGLISH the output will look as follows
0,0 +X
+Y
8/9/2019 Mapping Modes
38/50
8/9/2019 Mapping Modes
39/50
MM_HIENGLISH
- It sets the orientation so the vertical axis moves from (0, 0)
- Each unit is divided by 1000 (1/1000 = 1000th
) that is significantand can change the display of a drawing
- Now the output will look as follows
8/9/2019 Mapping Modes
40/50
MM_HIENGLISH
8/9/2019 Mapping Modes
41/50
MM_LOMETRIC & MM_HIMETRIC
- uses the same axes orientation as the previous two modes
- With MM_LOMETRIC map mode each unit is reduced by 10%
- With MM_HIMETRIC map mode each unit is multiplied with
0.01mm.
- The example program using these modes are shown in following
figures.
8/9/2019 Mapping Modes
42/50
MM_LOMETRIC
8/9/2019 Mapping Modes
43/50
MM_HIMETRIC
8/9/2019 Mapping Modes
44/50
MM_TWIPS
- The MM_TWIPS map mode divides each logical unit by 20
- Actually a twip is equivalent to 1/1440 inch
8/9/2019 Mapping Modes
45/50
MM_TWIPS
8/9/2019 Mapping Modes
46/50
CUSTOMIZING THE UNIT AND
COORDINATE SYSTEM
- To control the unit system & the orientation of the axes two
map modes are used. They are
MM_ISOTROPHIC
MM_ANISOTROPHIC
- With MM_ISOTROPHIC , one unit in the horizontal axis is
equivalent to one unit in the vertical axis
- With MM_ANISOTROPHIC, the units should be converted on
each individual axis
- One more method used to change the unit system isSetWindowExt() that specifies how much each new unit will bemultiplied by the old or default unit system
8/9/2019 Mapping Modes
47/50
MM_ISOTROPHIC
- The syntaxes of this method are
CSize SetWindowExt(int cx, int cy);
CSize SetWindowExt(SIZE size);
- The following example shows the effect of this method
void CExoDraw1View::OnPaint()
{
CPaintDC dc(this); // device context for paintingdc.SetMapMode(MM_ISOTROPIC);
dc.SetViewportOrg(340, 220);dc.SetWindowExt(480, 480);
. Same as previous
}
8/9/2019 Mapping Modes
48/50
Without Using MM_ISOTROPHIC
8/9/2019 Mapping Modes
49/50
8/9/2019 Mapping Modes
50/50
THANK YOU