1 / 12

Outline

Learn about event-driven programming paradigm and its example - event handling and double buffering in C++/CLI. Explore topics like event registration, graphics using GDI+, state representation, and triple buffering.

dgalloway
Download Presentation

Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Outline • Event-driven programming paradigm • Example: • Event Handling • Class • Array/Collection • Graphics • Double Buffering

  2. Event Handling Source Object Receiver Object H_Func(Event) { } Event Registration/delegate

  3. Source vs. Receiver Source/Receiver Receiver Source Source

  4. Mouse Event Handling in C++/CLI • Event: MouseEventArgs • Mouse Event Handlers: Form1_MouseDown, Form1_MouseUp, Form1_MouseMove • Registration (delegate): • this->MouseDown += gcnew MouseEventHandler(…); • this->MouseUp += gcnew MouseEventHandler(…); • this->MouseMove += gcnew MouseEventHandler(…);

  5. A look at Graphics using GDI+ • GDI: Graphical Device Interface • Paint event is associated with all controls. Triggered when create, resize, restore, etc. • Graphicsclass • PaintEventHandler() • Invalidate() • Manually trigger Paint event

  6. Event-driven Programming • Programming paradigm • State representation • State presentation : Form1_Paint in C++/CLI • Event handling and state change • Request for presentation to reflect new state:Invalidate in C++/CLI

  7. Double Buffering • Flicking problem with single buffering • Double buffering • Front buffer for display • Back buffer for composition • Triple buffering

  8. Single Buffering Display Frame Buffer Composition

  9. Double Buffering in Computer Graphics Display Front Back Composition Swap Buffers Display Back Front Composition

  10. Double Buffering in C++/CLI Window Image Front Back Draw Composition

  11. Double Buffering in C++/CLI • Step 1: Create the back buffer and its graphics • Bitmap^ backBuffer = gcnew Bitmap(width, height); • Graphics^ gBackBuffer = Graphics::FromImage(backBuffer); • Step 2: Compose the scene in the back buffer • gBackBuffer->Clear(Color::White); • gBackBuffer->FillEllipse(…); • .... • Step 3: copy the back buffer to the front • e->Graphics->DrawImageUnscaled(backBuffer, 0, 0);

  12. An Example • Event-driven programming paradigm • Class • Array/Clollection • Event Handling • Double Buffering

More Related