greenhouse
a creative coding toolkit for spatial interfaces

Event Routing

Pointing Events can be ignored or passed to parent objects.

  • SetObliviousness ()
  • QueryObliviousness ()
  • HitCheck ()
  • PointerWithinKid ()

Example

#include "Greenhouse.h"

class Snoop  :  public Text
{ public:

  Snoop ()  :  Text ()  {  SlapOnFeld (); }

  //  Not efficient or clever.  Demo purposes only.
  void PointingMove (PointingEvent *e)
    { Thing *ship = Find <Thing> ("mama");
      for (int64 i = 0 ; i < ship -> KidCount () ; i++)
        { if (Image *img = ship -> NthKid <Image> (i))
            if (img -> HitCheck (e))
              SetString (img -> Name ());
        }
    }
};

struct Mothership  :  public Thing
{ public:
  Mothership ()  :  Thing ()
    { SlapOnFeld ();
      SetName ("mama");

      for (int64 i = 0 ; i < 20 ; i++)
        { Image *k = new Image ("images/heart.png");
          k -> SetName ("heart " + ToStr(i));
          AppendKid (k);
          k -> SetDiagonal (15);
          float64 v = Random (10, Feld () -> Height ()/3);
          float64 h = Random (-0.5, 0.5) * Feld () -> Width () * v/100;
          k -> IncTranslation (Vect (h, v, 0));
        }
    }

  void DrawSelf ()
    { SetGLColor (Color (1, 1, 1, 0.2));
      glEnable (GL_LINE_SMOOTH);

      for (int64 i = 0 ; i < KidCount () ; i++)
        { glBegin (GL_LINES);

          glVertex (UnWrangleLoc (Loc ()));

          //  Bare Node pointers (like NthKid) don't have Loc,
          //  they have PhysLoc :(
          glVertex (UnWrangleLoc (NthKid (i) -> PhysLoc ()));

          glEnd ();
        }
      glDisable (GL_LINE_SMOOTH);
    }

  void Blurt (BlurtEvent *e)
    { if (Utters (e, "o"))
        SetObliviousness (! QueryObliviousness ());

      // Rotate around the Over () axis
      if (Utters (e, "w"))
        IncRotation (UnWrangleRay (Feld () -> Over ()), -PI / 18);
      else if (Utters (e, "s"))
        IncRotation (UnWrangleRay (Feld () -> Over ()), PI / 18);

      //  Rotate around the Up () axis
      else if (Utters (e, "a"))
        IncRotation (UnWrangleRay (Feld () -> Up ()), -PI / 18);
      else if (Utters (e, "d"))
        IncRotation (UnWrangleRay (Feld () -> Up ()), PI / 18);
    }

  void PointerWithinKid (PointingEvent *e, Node *kid)
    { if (IsHardened (e))
        kid -> Heartbeat ();
    }
};


void Setup ()
{ //  We want to layer things ourselves, logically; turn off depth sorting
  SetDepthSorting (false);

  new Mothership ();
  new Snoop ();
}