User Interface Programming in C#: Graphics

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Nov 2005 MSc Slide 1 - Another Example of a Structural Pattern Alternative way of adding Functionality to an existing class (alternative to a derived class)
Chapter 9 Color, Sound and Graphics
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
Foundation Level Course
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
Chapter 13: Advanced GUI and Graphics
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
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.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
By: Zaiba Mustafa Copyright ©
Web Design & Development Lecture 18. Java Graphics.
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take Home lab#4 Recap New topics – Drawing Coming up: – GUI Bloopers.
Exploring 2D Graphics: The Sudoku Example Content taken from book: “Hello, Android” by Ed Burnette Third Edition.
BFTAW BDPA Workshop Introduction to GIMP Chris
BFTAW BDPA Workshop Introduction to GIMP Chris
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
CSC 298 Windows Forms.
Graphics and Multimedia Part #2
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Tutorial 1 Introducing Adobe Flash CS3 Professional
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Chapter 9 Fireworks: Part I The Web Warrior Guide to Web Design Technologies.
CS- 375 Graphics and Human Computer Interaction Lecture 1: 12/4/1435 Fundamental Techniques in Graphics Lecturer: Kawther Abas.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Java Direct Manipulation Chris North cs3724: HCI.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
Java Dynamic Graphics.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
Paint Tutorial Created February 2006 Start Paint: Start>Programs>Accessories>Paint.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Introduction to Microsoft publisher
Flash Interface, Commands and Functions
Graphics and Multimedia
Chapter 3:- Graphics Eyad Alshareef Eyad Alshareef.
Drawing Mouse and Keyboard Events Part A - Drawing
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
GUI Graphics Chris North cs3724: HCI.
Lecture 9 GUI and Event Driven CSE /16/2019.
Object Oriented Programming
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

User Interface Programming in C#: Graphics Chris North CS 3724: HCI

GUI Topics Components GUI layouts Events Graphics Manipulation Animation Databases MVC

Review 3 kinds of elements in a component’s API? Receive Events? GUI Layout techniques?

Graphics Screen is like a painter’s canvas App must paint its window contents GUI components paint themselves Anything else: Programmer How to paint? When to paint? Button

1. How to Paint? Examples: Draw static graphics On startup, on click

Pixels

Coordinate System Upside-down Cartesian Ywindow = height - Ycartesian (0,0) (width,0) (0,height) (width, height)

Component Hierarchy Each component has its own subwindow Clipping: Subwindow = rectangular area within parent component Has own coordinate system Clipping: Can’t paint outside its subwindow Can’t paint over child components? (0,0) Panel Button (0,0) Button (wb, hb) (wp, hp)

Painting Components Can paint any component Panel is good for custom graphics area Panel Button

Painting in C# 1. The GDI+ graphics library: using System.Drawing; 2. Get the “graphics context” of a component: Graphics g = myPanel.CreateGraphics( ); 3. Paint in it: g.DrawLine(pen, x1,y1, x2,y2);

Graphics Primitives Draw Fill Line (pt1,pt2) Lines (pt list) Arc (rect) Curves, Bezier (pt list) Ellipse (rect) Rectangle (rect) Polygon (pt list) Image (img, x,y) String (string, x,y) label

Graphics Attributes Pen (for lines) Brush (for filling) Color, width, dash, end caps, joins, Brush (for filling) Color, Solid, texture, pattern, gradient Font, String Format (for strings) Bitmap/Metafile (for images) Bmp, gif, jpeg, png, tiff, wmf, …

Color Combinations of Red, Green, Blue Alpha value = opacity Each in [0, 255] C#: Color.FromArgb(255, 150, 0)

Color Combinations of Red, Green, Blue Alpha value = opacity Each in [0, 255] C#: Color.FromArgb(255, 150, 0) Hokie Orange

2. When to Paint? Examples: Draw graphics On repaint

Re-Paint Screen is like a painter’s canvas All windows paint on the same surface! Windows don’t “remember” whats under them Need to re-paint when portions are newly exposed Receive Repaint events Open, resize, bring to front When other windows in front move, resize, close

MyApp

Open WinExp, Notepad

Close WinExplorer Repaint event sent to: Desktop, MyApp

Desktop gets repaint event

MyApp gets repaint event MyApp Form gets repaint event

MyApp gets repaint event MyApp Form forwards repaint event to Button

Repainting Static Graphics Repaint event: Erase (fill with background color) - usually automatically done by the control Draw graphics

In C# Receive “paint” event: (select the event in VisStudio) this.Paint += new PaintEventHandler(this.Form1_Paint); private void Form1_Paint(object sender, PaintEventArgs e){ Graphics g = e.Graphics; g.DrawLine(new Pen(Color.Red,10), 10,10,300,300); } OR: Override the OnPaint method override void OnPaint(PaintEventArgs e){ base.OnPaint(e); //preserve base class functionality Can call Refresh( ) to force a repaint

Typical program structure for Dynamic Graphics Store data structure of graphics items E.g. user drawn picture in a paint program Paint event: Erase window (draw background color) Draw graphics for items in data structure Other user events that alter the graphics items: modify the data structure send repaint event by calling Refresh( )

Program Structure C# WinApp: Program State -data structures Class{ declare data storage; constructor(){ initialize data storage; } cntrl1_paintevent(e){ draw graphics from data; cntrl2_mouseEvent(e){ manipulate data; cntrl1.refresh(); … Program State -data structures Paint event -display data Interaction events -modify data

Data structure for graphics items 2 approaches: Store logical contents in a data structure, then draw graphics based on the data E.g. drawing program: lines, shapes, colors, … E.g. visualization program: data table Store visual contents as an off-screen image (bitmap) E.g. pixels Then use g.DrawImage( ) in paint event

What Control’s Subwindows Do Directs mouse input to correct component Determines repaint events Own coordinate system Don’t need repaint when moving Clipping: hides drawing behind a subwindow Some subwindows remember what’s under them: Popup menus