Re: Please explain



Can someone, please, explain these lines of code.
(The example does not give sufficient explanation...)
  int x, y;
  GdkModifierType state;

  if (event->is_hint)
    gdk_window_get_pointer (event->window, &x, &y, &state);
  else
    {
      x = event->x;
      y = event->y;
      state = event->state;
    }
    
  if (state & GDK_BUTTON1_MASK && pixmap != NULL)
    draw_brush (widget, x, y);

The line:

        if (event->is_hint)

Checks if the given event is a `hint' that the user has started something
of a drag and future events for the drag will *not* be reported *unless*
you call gdk_window_get_pointer() (which the code does).

The gdk_window_get_pointer() call says, 'okay, give me those motion
events'. This is to make it easier on widgets that have dragging over
(button press and then pointer motion) on it to only recieve motion events
if there is a hint that there is an actual need to.

I use this type of code in my programs, it's very useful for handling
drags.

The else case:

        x = event->x;
        y = event->y;
        state = event->state;

Basically just fetches the event's values for this event only and does not
ask for further motion events.


The code:

        if (state & GDK_BUTTON1_MASK && pixmap != NULL)
                draw_brush (widget, x, y);

Is program specific, and a bit ambigulous in the if case since.
It implies a bitwise compare if the GDK_BUTTON1_MASK bit is set in
variable state and also if the variable pixmap (a pointer) is not NULL.

If all are true call program specific function draw_brush().

--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
..__                         ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]