event handling

11
Event Handling H_Func(Event) { } Even t Receiver Object Source Object Registra tion

Upload: kalia-dejesus

Post on 30-Dec-2015

30 views

Category:

Documents


2 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Event Handling

Event Handling

H_Func(Event) {}Event

Receiver ObjectSource Object

Registration

Page 2: Event Handling

Source vs. Receiver

Source/Receiver Receiver

Source

Source

Page 3: Event Handling

Mouse Event Handling in C++/CLI

• Event: MouseEventArgs• Mouse Event Handlers: Form1_MouseDown, Form1_MouseUp, Form1_MouseMove

• Registration (delagate):– this->MouseDown += gcnew MouseEventHandler(…);

– this->MouseUp += gcnew MouseEventHandler(…);

– this->MouseMove += gcnew MouseEventHandler(…);

Page 4: Event Handling

Event Handling in an Window-based Application (win32)

MSG Msg;

while (GetMessage(&Msg, NULL, 0, 0)>0) {

TranslateMessage(&Msg); // ignore

DispatchMessage(&Msg);

}

Page 5: Event Handling

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

Page 6: Event Handling

Double Buffering

• Flicking problem with single buffering

• Double buffering– Front buffer for display– Back buffer for composition

• Triple buffering

Page 7: Event Handling

Single Buffering

Frame Buffer

Display

Composition

Page 8: Event Handling

Double Buffering in Computer Graphics

Front

Composition

Display

Back

Back Front

Display

Composition

Swap Buffers

Page 9: Event Handling

Double Buffering in C++/CLI

Front

Composition

DrawBack

ImageWindow

Page 10: Event Handling

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

Page 11: Event Handling

An Example

• Event-driven programming paradigm

• Class

• Array/Clollection

• Event Handling

• Double Buffering