+ All Categories
Home > Documents > Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B...

Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B...

Date post: 30-Mar-2021
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
71
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay Session: Advanced Graphics Events Guest Lecturer: Dr. Abhiram Ranade
Transcript
Page 1: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Computer Programming

Dr. Deepak B PhatakDr. Supratik Chakraborty

Department of Computer Science and EngineeringIIT Bombay

Session: Advanced Graphics EventsGuest Lecturer: Dr. Abhiram Ranade

Page 2: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Quick recap

Last session: The getClick function for waiting for clicks.

This session: How to wait for other kinds of events.

Reference: Chapter 20 of ”An introduction to programmingthrough C++”, McGraw Hill Education, 2014.

Page 3: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Quick recap

Last session: The getClick function for waiting for clicks.

This session: How to wait for other kinds of events.

Reference: Chapter 20 of ”An introduction to programmingthrough C++”, McGraw Hill Education, 2014.

Page 4: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Quick recap

Last session: The getClick function for waiting for clicks.

This session: How to wait for other kinds of events.

Reference: Chapter 20 of ”An introduction to programmingthrough C++”, McGraw Hill Education, 2014.

Page 5: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Quick recap

Last session: The getClick function for waiting for clicks.

This session: How to wait for other kinds of events.

Reference: Chapter 20 of ”An introduction to programmingthrough C++”, McGraw Hill Education, 2014.

Page 6: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 7: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 8: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 9: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 10: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 11: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 12: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 13: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Basics of Events

The term event is used in Simplecpp to denote

I Pressing of a button of the mouse.

I Release of a button of the mouse.

I Dragging of the mouse.Dragging = moving the mouse with a button pressed.

I Pressing of a key on the keyboard.

A C++ program can choose to wait for above events to happen,and once they happen, can find out what has happened, and thencontinue.

A C++ program can also merely check whether any of the aboveevents has already happened, without any waiting.

If there are many windows on the screen, then you must first clickon the canvas so that subsequent events will be detected by yourprogram.

Page 14: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Event Objects

Objects of (built-in) class XEvent are used for holding informationabout events.

You do not need to know the exact definition of XEvent. Somefunctions etc. are provided which enable you to get the requiredinformation.

Page 15: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Event Objects

Objects of (built-in) class XEvent are used for holding informationabout events.

You do not need to know the exact definition of XEvent. Somefunctions etc. are provided which enable you to get the requiredinformation.

Page 16: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Event Objects

Objects of (built-in) class XEvent are used for holding informationabout events.

You do not need to know the exact definition of XEvent. Somefunctions etc. are provided which enable you to get the requiredinformation.

Page 17: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 18: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.

It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 19: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 20: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 21: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.

Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 22: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 23: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.

After this execution continues.

Page 24: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Waiting for an event

The function nextEvent is used for waiting for an event.It takes as argument a reference to an XEvent object.

Typical use:XEvent e1;

nextEvent(e1);

The call causes the program to wait for an event to happen.Calling nextEvent is like waiting for the user to type in data, i.e.executing cin >> ...

When some event finally happens, the information about it is putinto the passed XEvent object, in this case e1.After this execution continues.

Page 25: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 26: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 27: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 28: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 29: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 30: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 31: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 32: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 33: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 34: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 35: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting information about events

The following functions are available

I bool mouseButtonPressEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being pressed.

I bool mouseButtonReleaseEvent(XEvent &e1);

Returns true iff e1 involves some mouse button being released.

I bool mouseDragEvent(XEvent &e1);

Returns true iff e1 involves the mouse being dragged.

I bool keyPressEvent(XEvent &e1);

Returns true iff e1 involves some key being pressed.

How to get more detailed information: next.

Page 36: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 37: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 38: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 39: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 40: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 41: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 42: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The following data members can be accessed.

I e1.xbutton.button : Equals 1, 2, 3 depending upon whichbutton was pressed or released, assuming event e1 involvedpressing or releasing a mouse button.

I e1.xbutton.x : Equals the x-coordinate of the positionwhere e1 happened.

I e1.xbutton.y : Equals the y-coordinate of the positionwhere e1 happened.

I e1.xmotion.x : Equals the x-coordinate of where dragginghappened, in case e1 was a mouse drag event.

I e1.xmotion.y : Equals the y-coordinate of where dragginghappened, in case e1 was a mouse drag event.

Page 43: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 44: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 45: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 46: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.

The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 47: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 48: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 49: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 50: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Getting more information about an event e1

The function

char charFromEvent(XEvent &e1);

returns the ASCII value of the key pressed, in case e1 is a key pressevent.The following data members are also useful.

I e1.xkey.x : Equals the x-coordinate of the cursor positionwhen e1 happened.

I e1.xkey.y : Equals the y-coordinate of the cursor positionwhen e1 happened.

Key press events may not be detected properly if ”caps lock” or”Num lock” modes are on. Remove these first.

Page 51: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.It takes as argument a reference to an XEvent object.It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 52: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.

It takes as argument a reference to an XEvent object.It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 53: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.It takes as argument a reference to an XEvent object.

It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 54: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.It takes as argument a reference to an XEvent object.It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 55: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.It takes as argument a reference to an XEvent object.It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 56: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.It takes as argument a reference to an XEvent object.It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 57: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Checking for events

Function checkEvent checks if an event has happened.It takes as argument a reference to an XEvent object.It returns true iff an event has happened after the last call tonextEvent and has not been yet reported in any checkEvent.

Typical use:XEvent e1;

if(checkEvent(e1)){ ..A..}else { ..B..}

The call to checkEvent does not wait; either code A or code B isimmediately executed, depending upon whether the eventhappened.

Information about the event that happened (if any) can beobtained using the functions and members described earlier.

Page 58: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 59: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 60: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 61: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 62: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 63: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 64: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

An example program

We will write a program that allows you to draw on the canvas.

I Drawing starts when you press a mouse button.

I If you drag the mouse, then the line follows the path taken bythe mouse.

I The drawing stops when the mouse button is released.

I If you merely move the mouse without pressing any button,no line is drawn.

I If the escape key is pressed, the program ends.

Page 65: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..

Page 66: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..

Page 67: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..

Page 68: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..

Page 69: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..

Page 70: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..

Page 71: Computer Programming - IIT Bombaycs101/2014.2/lecture-slides/...Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT

Summary

We discussed how to handle mouse and keyboard events.

I nextEvent enables waiting for mouse and keyboard events.

I checkEvent enables determining if an event has alreadyhappened.

I Information about events can be obtained by calling functionson the event object, or examining its members.

I Chapter 20 gives an example of a ”Snake” game that can bedeveloped. Other games are also possible.

I The drawing program developed above can be extended torecognize what is drawn: Is the user writing something? Is theuser drawing a circle?

I The possibilities for doing interesting projects are endless..


Recommended