greenhouse
a creative coding toolkit for spatial interfaces

Mobile Device Events

Greenhouse handles most events sent by a mobile device and funnels them through traditional Pointing and Blurt events so that Greenhouse objects get these events by default. Greenhouse further abstracts the Blurt events into individual mobile events: SwipeUp, SwipeDown, SwipeLeft, SwipeRight so that Greenhouse objects can override these methods rather than doing the sorting out themselves in a Blurt event. (blurt events => discrete events that do not have a duration, intensity, or location). In addition to the Pointing and Swipe events produced, a Greenhouse object can register to receive an additional set of events a mobile device can produce: Hello, ImageUploadBegin, ImageUploadComplete, TextUploadUpdate & TestUploadComplete.

  • SwipeUp ()
  • SwipeDown ()
  • SwipeRight ()
  • SwipeLeft ()
  • RegisterForMobileNotifications ()
  • Hello ()
  • RequestImageFromMobileDevice ()
  • ImageUploadBegin ()
  • ImageUploadComplete ()
  • RequestTextFromMobileDevice ()
  • TextUploadUpdate ()
  • TextUploadComplete ()
  • SendImageToMobileDevice ()
  • DisplayImageOnMobileDevice ()

Example

#include "Greenhouse.h"

class CustomText  :  public Text
{
private:
  Image *img;

public:
  CustomText (const Str &s)  :  Text (s)
  { RegisterForMobileNotifications ();
    img = new Image ();
    AppendKid (img);
    img -> SetAdjColor (Color (1.0, 0.0));
    img -> SetTranslation (-2 * Height () * Up ());
  }

  void SwipeUp (BlurtEvent *e)
  { IncRotation (WrangleRay (Feld () -> Over ()), -PI / 4);
    RequestImageFromMobileDevice (e -> Provenance (), "Take a photo to upload");
  }

  void SwipeDown (BlurtEvent *e)
  { IncRotation (WrangleRay (Feld () -> Over ()), PI / 4);
    RequestTextFromMobileDevice (e -> Provenance (), "Enter text to upload");
  }

  void SwipeRight (BlurtEvent *e)
  { IncRotation (WrangleRay (Feld () -> Up ()), PI / 4); }

  void SwipeLeft (BlurtEvent *e)
  { IncRotation (WrangleRay (Feld () -> Up ()), -PI / 4); }

  void Hello (const Str &provenance, const Str &name)
  { SetString ("Welcome " + name);
    ImageData *id = Image::FetchImageData ("images/heart.png");
    if (id)
      { SendImageToMobileDevice (provenance, "heart", id);
        DisplayImageOnMobileDevice (provenance, "heart");
      }
  }

  void ImageUploadBegin (const Str &provenance, int width, int height)
  { img -> SetWidth (width);
    img -> SetHeight (height);
    img -> SetHeightUniformly (0.2 * Feld () -> Height ());
    img -> SetAdjColor (Color (1.0, 1.0));
  }

  void ImageUploadComplete (const Str &provenance, ImageData *img_data)
  { img -> SetImage (img_data); }

  void TextUploadUpdate (const Str &provenance, const Str &text)
  { SetString (text); }

  void TextUploadComplete (const Str &provenance, const Str &text)
  { SetString (text + "!"); }
};

void Setup ()
{ CustomText *ct = new CustomText ("Connect using your mobile device");
  ct -> SlapOnFeld ();
  ct -> RotationAnimateChase (0.75);
}