Chapter2: Drawing a Window. Drawing with the GDI.

Slides:



Advertisements
Similar presentations
Lesson One: The Beginning
Advertisements

CHAPTER 20 CREATING SVG GRAPHICS. LEARNING OBJECTIVES How to embed a graphic stored within a.SVG file in an HTML page How to use the and tag pair to specify.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
CHAPTER 3 2D GRAPHICS ALGORITHMS
By Paul Richard and Jim Fitzgerald Chapter 9 - Drawing and Editing Complex Objects.
Chapter 12 Using Clipping Masks, Paths, & Shapes.
Drawing Objects with Illustrator 1.Start a new image in RGB mode. 2.Size 1024 X Unit = pixels 4.Go to View > Show Grid to turn on the grid. 5.Go.
Using MS Paint by A. Satariano Launching MS Paint Click on the Start Button Move the mouse up to the Programs Folder. Then move the mouse up to the Accessories.
Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or.
Adobe Photoshop CS Design Professional PATHS, & SHAPES USING CLIPPING MASKS,
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
By: Zaiba Mustafa Copyright ©
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
Macromedia Fireworks 8 Revealed WORKING WITH OBJECTS.
COMPUTER GRAPHICS Prepared by S.MAHALAKSHMI Asst. Prof(Sr) / SCSE VIT University.
1 Chapter 15 Drawing in a Window. 2 The Window Client Area  A coordinate system that is local to the window.  It always uses the upper-left corner of.
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
Graphics and Multimedia Part #2
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Adobe Illustrator Basics Instructor: Cristol Gregory Assistant: Tara Caimi.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
Macromedia Studio 8 Step-by-Step MACROMEDIA FIREWORKS 8 Project 2: Experience Bank Logo.
Chapter 6 Working with Patterns and Brushes. Objectives Use the Move command Create a pattern Design a repeating pattern Use the Pattern Options panel.
Chapter 9 Fireworks: Part I The Web Warrior Guide to Web Design Technologies.
INT 840E Computer graphics Introduction & Graphic’s Architecture.
PowerPoint Basics Tutorial 1: Objects These tutorials will introduce you to the most basic and useful functions of Microsoft PowerPoint We’re going.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Tkinter Canvas.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Bitmap (Chapter 15).
Chapter2: Drawing a Window. Review: Introducing MFC.
By: Affaf Muzammal ALLIED SCHOOL 46-Iqbal Block, Ittefaq Town, Multan Road, Lahore ,
Chapter 8 Dialog Boxes and Property Sheet. 2 Two kinds of dialog boxes Dialog boxes –Modal dialog When appear, it takes all ownership of input. It disables.
Chapter2: Drawing a Window
Adobe Fireworks CS3 Revealed CHAPTER TWO: WORKING WITH OBJECTS.
Fall UI Design and Implementation1 Lecture 6: Output.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
© 2011 Delmar, Cengage Learning Chapter 12 Using Clipping Masks, Paths, & Shapes.
Paint Tutorial Created February 2006 Start Paint: Start>Programs>Accessories>Paint.
Chapter2: Drawing a Window. Drawing with the GDI.
Drawing in Windows. To help with drawing on the Windows operating system, Microsoft created the Graphical Device Interface, abbreviated as GDI. – It is.
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Adobe Photoshop CS5.
12 Graphics and Java 2D™.
MS Paint A simple drawing tool that can be used to create simple or elaborate drawings. These drawings can be either black-and-white or color, and can.
Programming windows with MFC Chapter 2 - Drawing in a Window
Text on a curve.
Starburst.
Dr. Jim Rowan ITEC 2110 Wednesday, September 12
Pertemuan 05 Drawing with Shape
Graphics and Multimedia
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
First text statement positioned here at guide intersection
Basic Graphics Drawing Shapes 1.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Building Java Programs
Graphics -- Introduction
Digital Media Dr. Jim Rowan ITEC 2110.
Chapter Lessons Use the Macromedia Flash drawing tools
1.
Extend Text Editor to Draw shapes
Otasuke GP-EX! Chapter 1 Menu Screen.
对 话 无 界 限 “对话是两个集合出现交集的一个刹那。” “对话是发现共同点的捷径。”.
Chapter 14 Drawing in a Window
Chapter 16 Drawing in a Window
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

Chapter2: Drawing a Window

Drawing with the GDI

3 Drawing Functions of CDC (1/3) Point Same with the SetPixel, but it does not return the original color value. So it is more efficient. SetPixelV Set the given color value at the position and return the original color value at the position SetPixel Get the color value at the given position.GetPixel Descriptionfunction COLORREF color = dc.GetPixel (x,y); dc.SetPixelV(x,y, RGB(r,g,b)); COLORREF color = dc.GetPixel (x,y); dc.SetPixelV(x,y, RGB(r,g,b));

4 COLORREF A data type for storing a color value 32 bit as 0x00rrggbb Macro function easy to use: COLORREF color = RGB(r,g,b); r = GetRValue (color); g = GetGValue (color); b = GetBValue (color); COLORREF color = RGB(r,g,b); r = GetRValue (color); g = GetGValue (color); b = GetBValue (color);

Drawing test:

6 Drawing Functions of CDC (2/3) Drawing shapes dc.Rectangle (x1, y1, x2, y2); dc.Ellipse (x1, y1, x2, y2); (x1, y1) (x2, y2) FunctionDescription Rectangle()Drawing a rectangle Ellipse()Drawing an ellipse

void GetClientRect(CRect) How to get the window size? CRect : a class for storing a rectangle information –member variables: bottom top right left CRect rect; GetClientRect(rect); CRect rect; GetClientRect(rect); (left, top) (right, top) (right, bottom)(left, bottom) msdn2.microsoft.com/ko-kr/library/zzs00fs6(VS.80 ).aspx

void GetClientRect(CRect) Practice: draw an ellipse fit to the client area CRect rect; GetClientRect(rect); CRect rect; GetClientRect(rect);

More shapes of CDC (2/3) FunctionDescription ChordDraws a closed figure bounded by the intersection of an ellipse and a line EllipseDraws a circle or an ellipse PieDraws a pie-shaped wedge PolygonConnects a set of points to form a polygon RectangleDraws a rectangle with square corners RoundRectDraws a rectangle with rounded corners

10 Drawing Functions of CDC (3/3) Drawing a Line Drawing a line from the original position to the given position LineTo() Move your pen to the given positionMoveTo() Descriptionfunction dc.MoveTo(x1,y1); dc.LineTo(x2,y2); dc.MoveTo(x1,y1); dc.LineTo(x2,y2); (x1,y1) (x2,y2)

Coding practice

More line functions(3/3) FunctionDescription MoveTo Sets the current position in preparation for drawing LineTo Draws a line from the current position to a specified position and moves the current position to the end of the line Polyline Connects a set of points with line segments PolylineTo Connects a set of points with line segments beginning with the current position and moves the current position to the end of the polyline Arc Draws an arc ArcTo Draws an arc and moves the current position to the end of the arc PolyBezier Draws one or more Bézier splines PolyBezierTo Draws one or more Bézier splines and moves the current position to the end of the final spline PolyDraw Draws a series of line segments and Bézier splines through a set of points and moves the current position to the end of the final line segment or spline

13 Drawing a Text by using CDC Text-related functions Sets alignment parametersSetTextAlign() Sets the background colorSetBkColor() Sets the text output colorSetTextColor() Draws text in a formatting rectangleDrawText() Outputs a line of test at the positionTextOut() DescriptionFunction Name dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(0,255,0)); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,_T(“Sejong University”)); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(0,255,0)); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,_T(“Sejong University”));

Coding Test CRect rect; GetClientRect(rect); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(255,255,0)); dc.DrawText(CString(_T("Draw Text Test")), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,CString(_T("Welcome"))); CRect rect; GetClientRect(rect); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(255,255,0)); dc.DrawText(CString(_T("Draw Text Test")), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,CString(_T("Welcome")));

Coding Test CRect rect; GetClientRect(rect); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(255,255,0)); dc.DrawText(CString(_T(“Draw Text Test”)), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,CString(_T("Welcome“))); CRect rect; GetClientRect(rect); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(255,255,0)); dc.DrawText(CString(_T(“Draw Text Test”)), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,CString(_T("Welcome“))); Output text The text will be placed in the rectangle Text Alignment xy Output text

Text Color related functions AttributeDefault Text colorblack Background Color white Background color mode OPAQUE  TRANSPARE NT Get with GetTextColor() GetBkColor() GetBkMode() Set with SetTextColor() SetBkColor() SetBkMode()

Drawing with GDI An Initial Rectangle: How to change the color and attributes? –Changing the Pen : LINE –Changing the Brush : FACE

18 GDI Objects (1/3) GDI Objects (class) –Tools for drawing with the GDI –Changing the attributes of the shapes toolusageClass name penWhen drawing a lineCPen brushWhen filling a regionCBrush fontWhen printing out a textCFont bitmapWhen filling a region with an imageCBitmap regionWhen defining a polygonal regionCRgn

19 GDI Objects(2/3) Class hierarchy

20 GDI Objects (3/3) When you draw an image (in real world): 1.Choosing a pen 2.Grabbing the pen 3.Drawing an image 4.Releasing the pen

21 GDI Objects (3/3) When you draw an image (by using GDI) 1.Defining a tool (pen) 2.Assigning the tool to the DC (CDC::SelectObject()) 3.Drawing an image 4.(Releasing the tool from the DC)

22 CPen (1/2) How to use: Pen Style // method 1 CPen pen(PS_SOLID, 2, RGB(255, 0, 0)); // using constructor // or method 2 CPen pen; pen.CreatePen (PS_SOLID, 2, RGB (255, 0, 0)); // using initializer Stylewidthcolor

CPen (2/2) Coding Example CPaintDC dc(this); CPen pen(PS_SOLID, 1, RGB(0, 0, 255)); dc.SelectObject(&pen); dc.Rectangle(100, 100, 200, 200); CPaintDC dc(this); CPen pen(PS_SOLID, 1, RGB(0, 0, 255)); dc.SelectObject(&pen); dc.Rectangle(100, 100, 200, 200);

24 CBrush (1/2) A Brush defines how to fill a region Different kinds of the brush (by using different constructor) Various BrushesExample Solid brush: filling with a color CBrush brush(RGB(255, 0, 0)); Hatch brush: filling with a pattern CBrush brush(HS_DIAGCROSS, RGB(255, 0, 0)); Bitmap brush: filling with an image CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); CBrush brush(&bitmap);

CBrush (2/2) Coding Example CPaintDC dc(this); CBrush brush(RGB(255, 0, 0)); dc.SelectObject(&brush); dc.Ellipse(100, 100, 200, 200); CPaintDC dc(this); CBrush brush(RGB(255, 0, 0)); dc.SelectObject(&brush); dc.Ellipse(100, 100, 200, 200); CPaintDC dc(this); CBrush brush(HS_DIAGCROSS, RGB(255, 0, 0)); dc.SelectObject(&brush); dc.Ellipse(100, 100, 200, 200); CPaintDC dc(this); CBrush brush(HS_DIAGCROSS, RGB(255, 0, 0)); dc.SelectObject(&brush); dc.Ellipse(100, 100, 200, 200);

26 CFont (1/2) How to use 1.Create a CFont variable 2.Call CreateFont() function CFont font; font.CreateFont(...); // font.CreateFontIndirect(...); // font.CreatePointFont(...); // font.CreatePointFontIndirect(...); CFont font; font.CreateFont(...); // font.CreateFontIndirect(...); // font.CreatePointFont(...); // font.CreatePointFontIndirect(...);

27 CFont (2/2) Coding Example CPaintDC dc(this); CFont font; font.CreatePointFont(400, _T("Arial")); dc.SelectObject(&font); dc.TextOut(10, 10, _T("Hello")); CPaintDC dc(this); CFont font; font.CreatePointFont(400, _T("Arial")); dc.SelectObject(&font); dc.TextOut(10, 10, _T("Hello")); SizeFont name

28 Predefined Objects (stock objects) –Call CDC::SelectStockObject(…) fucntion namemeaning BLACK_PENblack pen with 1 pixel width WHITE_PENwhite pen with 1 pixel width NULL_PENtransparent pen with 1 pixel width BLACK_BRUSHblack solid brush DKGRAY_BRUSHdark gray brush GRAY_BRUSHgray brush LTGRAY_BRUSHlight gray brush HOLLOW_BRUSH or NULL_BRUSH transparent brush SYSTEM_FONTdefault font used by windows system ex) menu, dialog box