1 / 11

Event Handling

Event Handling. Source Object. Receiver Object. H_Func (Event) { }. Event. Registration. Source vs. Receiver. Source/Receiver. Receiver. Source. Source. Mouse Event Handling in C++/CLI. Event: MouseEventArgs Mouse Event Handlers : Form1_MouseDown, Form1_MouseUp, Form1_MouseMove

Download Presentation

Event Handling

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. Event Handling Source Object Receiver Object H_Func(Event) { } Event Registration

  2. Source vs. Receiver Source/Receiver Receiver Source Source

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

  4. Event Handling in an Window-based Application (win32) MSG Msg; while (GetMessage(&Msg, NULL, 0, 0)>0) { TranslateMessage(&Msg); // ignore DispatchMessage(&Msg); }

  5. 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

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

  7. Single Buffering Display Frame Buffer Composition

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

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

  10. 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);

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

More Related