SPEAKER 1: Let's now write a program that involves a window, a circle, and my cursor. In particular, let's instantiate a black circle on the screen, and then let's train it to follow my cursor. So if I move my mouse up, down, left or right, the circle follows along. Let's first include gevents.h, so that we have access to graphical events. Let's next include gobjects, so that we have access to objects like circles-- or more precisely, ovals, as we'll see. And then let's include gwindow.h, so that we have access to a graphical window. Next, let's declare main in the usual way. Int main void. Let's now instantiate, or create, a window with GWindow. And we'll call the variable window. Gets newGWindow. And I'll somewhat arbitrarily make the window 320 pixels by 240 pixels. Now we need to instantiate that circle. Well, it turns out that a circle is a special case of an oval. It just so happens that the width and the height of a circle are equal. So let's instantiate an oval as follows. GOval. We'll call it circle, though. And that's going to get newGOval. And we're going to specify that it will begin in the top left-hand corner, whose coordinates are 0 comma 0. And the width of this global are going to be 50 by 50-- in other words, a circle. Now we have a window, we have a circle. But we haven't yet added that circle to the window. So we need to do that explicitly. Add window, circle. Thereby adding the latter to the former. Now let's do something forever. Let's sit in an infinite loop, listening for mouse events. Specifically not clicks, but movements of the mouse. And respond to those movements by moving the circle. Here we go. While true. Let's check for an event with GEvent, calling it event. Gets getNextEvent. And let's specifically try to get a mouse event of some type. Let's next make sure that the event does not equal null, so that there's actually something to respond to. And let's next check if getEventType, passing in event, equals MOUSE_MOVED, which is a special constant, declared in the Stanford Portable Library, that signifies that the mouse has indeed been moved. Then let's proceed to do the following. Declare a double. And I'll call it x. Specifically storing in that the return value of getX of the event. In other words, get me the x-coordinate of where the mouse was moved to. But just to make the circle line up exactly atop my cursor, let me now subtract off the width of the circle itself divided by 2. In other words, let's subtract off its radius. Let's do something similar now for y. Y gets get the y-coordinate of that event-- that is, the moved mouse-- minus getWidth of the circle. And this time we'll do the full diameter, not the radius. Finally, let's set the location of the circle to be that new x comma y. Let's now save, compile, and run this program. Make cursor. ./cursor. There's the circle in the top left hand corner. Now, let me move my mouse over that window and see if the circle latches onto it as expected. And indeed it does. Notice that specifically, the circle is at the very top of my cursor, perfectly centered, because of the math we did involving its diameter and its radius.