171 likes | 601 Views
The .NET Framework and the CLI 2D Graphics with GDI+ Visual Studio.NET 2008. The .NET Platform. Based on the Common Language Infrastructure (CLI) ECMA (European Computer Manufacturers’ Association) and ISO standard
E N D
The .NET Framework and the CLI2D Graphics with GDI+Visual Studio.NET 2008 Software Engineering
The .NET Platform • Based on the Common Language Infrastructure (CLI) • ECMA (European Computer Manufacturers’ Association) and ISO standard • CLI exists only for Windows but is being developed for other platforms (Linux, Mac …) • Contains a collection of classes called Framework Class Library (FCL) • FCL is shared by all .NET languages • C++, C#, J#, COBOL, Fortran, Eiffel, … Software Engineering
Common Language Runtime (CLR) • Executes managed code • Compilation is performed in two phases: • Program is compiled into the Microsoft Common Intermediate Language (CIL) • CIL is composed of instructions for the CLR • CLR links FCL function calls and compiles the program to machine code • .NET Web Services are applications that expose (make available) functionality to clients through the Internet Software Engineering
Common Language Infrastructure (CLI) Software Engineering
C++/CLI • When we program in C++ using the .NET framework, we program in an extension of C++ called C++/CLI • C++/CLI is a binding between the ISO standard C++ language and CLI • C++/CLI retains all the features of C++ • C++/CLI can use the .NET FCL • C++/CLI can use all CTS types Software Engineering
C++ and the CTS types • Classes can be defined in C++/CLI in four ways: class MyClass { … }; //native C++ class ref class MyClass { … }; //abstract base class value class MyClass { … }; //concrete class interface class MyClass { … }; //interface class • A new safe pointer type called handle is introduced MyClass ^ myObject = gcnewMyClass( ); // ^ is for handle myObject->myMethod( “Hello” ); // old -> syntax When myObject goes out of scope its memory is automagically released – no need to worry about destructors and such. Software Engineering
C++/CLI Handles • In C++/CLI a handle is created using the gcnew keyword • With native pointers new is still used • gc stands for “garbage collected” • Literal strings like ”Hello” are resolved to the System::String ^ type (ISO C++ would resolve to const char*) Software Engineering
2D Graphics in .NET • FCL contains a 2D graphics API called Graphical Device Interface Plus or GDI+ • GDI+ is part of the System::Drawing namespace and some other namespaces • Such as System::Drawing::Drawing2D • and System::Drawing::Drawing3D and more.. • There is a newer graphics API called Direct2D • but it is criticized as to complex and having other issues Software Engineering
Graphics Coordinate System ( 0, 0 ) x-axis (x, y) Coordinates are measured in pixels y-axis Software Engineering
Graphics Context and Objects • All Windows Form objects inherit a virtual void Paint( PaintEventArgs * paintEvent ) event handler that contains all drawing code • In the Paint event the Graphics, Pen, and Brush objects (and others) are extracted to perform drawing • Text is drawn by DrawString( ) calls Software Engineering
2-D Drawing Functions • DrawLine( Pen *p, int x1, int x2, int y1, int y2 ) • DrawRectangle( Pen * p, int x, int y, int w, int h ) • FillRectangle( Brush *b, int x, int y, int w, int h ) • DrawEllipse( Pen *p, int x, int y, int w, int h ) • FillEllipse( Brush *b, int x, int y, int w, int h ) • DrawArc( Pen *p, int x, int y, int w, int h, int, stA, int swA ) • DrawPie( Pen *p, int x, int y, int w, int h, int, stA, int swA ) • FillPie( Brush *b, int x, int y, int w, int h, int, stA, int swA ) • DrawLines( Pen *p, Point [ ] ) • DrawPolygon( Pen *p, Point [ ] ) • FillPolygon( Brush *b, Point [ ] ) Software Engineering
Mouse Event Handling • GUI controls are derived from the class System::Windows::Forms::Control • All can handle mouse and keyboard events • Mouse event information is passed by a MouseEventArgs object • The Mouse Events are: • MouseEnter, MouseLeave, MouseDown, MouseHover, MouseMove, MouseUp • The MouseEventArgs Properties are: • Button, Clicks, x, y Software Engineering
Keyboard Event Handling • Keyboard event information is passed by a KeyEventArgs object • The Keyboard Events are: • KeyUp, KeyDown, KeyPress • The KeyEventArgs Properties are: • KeyChar, Handled, Alt, Control, Shift, KeyCode, KeyData, KeyValue, Modifiers Software Engineering
The ArrayList Container • .NET equivalent of a dynamic array (vector) • Has Capacity and Count properties • Main methods: • Add • Clear • Contains • IndexOf • Insert • array<type>still can be used • Remove • RemoveAt • RemoveRange • Sort • TrimToSize Software Engineering
Explicit Type Conversions in .NET • Standard C++ supports two explicit cast operations: • static_cast < new_type > ( old_type ) • dynamic_cast < new_type > ( old_type ) • const_cast < new_type > ( old_type ) • reinterpret_cast < new_type > ( old_type ) • The operation static_cast performs conversion at compile time • The operation dynamic_cast converts at run-time • .NET boxing converts a value type to a managed type using the __box( ) operation (byte by byte) Software Engineering
Spatial Visual App Software Engineering