/// <summary> /// Attempts to add a region /// Note that a region will be disabled by default /// </summary> /// <param name="newRegion"></param> /// <returns> /// will return an identifier to your newly created region /// should you want to fiddle with it later /// </returns> private WindowBoundInteractionRegionIdentifier AddRegion(GUIRegion newRegion) { newRegion.CanActivate = true; if (newRegion.DwellTime == null) { newRegion.DwellTime = new TimeSpan(0, 0, DEFAULT_TIME_SPAN); } newRegion.Enabled = false; //TODO: Figure out what these calls does //newRegion.AlwaysInteractive = true; //newRegion.IsActivating = true; //newRegion.UsesCoordinate = true; try { logger.Info("about to add a new region"); Interaction.AddRegion(newRegion); //this is what actually makes tobii start tracking our region } catch (Exception) //will occur if the region was already added, Interaction.AddRegion can throw stuff { logger.Warn("Failed to add a new region, region was most likely already added"); return(null); } logger.Info("Successfully added a new region"); newRegion.regionActivated += newRegion_regionActivated; return(newRegion.RegionIdentifier); }
private void AddBotOffScreen(GUIRegion bot) { this.bot = bot; AddRegion(this.bot); this.bot.Enabled = true; this.bot.FocusEnter += new EventHandler <RegionFocusEventArgs>(FocusEnter); }
private void AddTopOffScreen(GUIRegion top) { this.top = top; AddRegion(this.top); this.top.Enabled = true; this.top.FocusEnter += new EventHandler <RegionFocusEventArgs>(FocusEnter); }
private void AddRightOffScreen(GUIRegion right) { this.right = right; AddRegion(this.right); this.right.Enabled = true; this.right.FocusEnter += new EventHandler <RegionFocusEventArgs>(FocusEnter); }
//We'll just do them like this for now private void AddLeftOffScreen(GUIRegion left) { this.left = left; AddRegion(left); this.left.Enabled = true; this.left.FocusEnter += new EventHandler <RegionFocusEventArgs>(FocusEnter); }
/// <summary> /// Blocking function that will, eventually, return an Event /// consisting of the GUIRegion that Published the event, and any EventArgs /// </summary> /// <returns></returns> public GUIRegion GetActivatedRegion() { for (; ;) { System.Threading.Thread.Sleep(200); // so I heard you like hogging cpu time lastKBState = kBState; kBState = Recellection.publicKeyBoardState; #if DEBUG if (kBState.IsKeyDown(Keys.W) && lastKBState.IsKeyUp(Keys.W)) { if (top != null) { top.Publish(top, new global::Recellection.Code.Utility.Events.EventType()); } } else if (kBState.IsKeyDown(Keys.S) && lastKBState.IsKeyUp(Keys.S)) { if (bot != null) { bot.Publish(bot, new global::Recellection.Code.Utility.Events.EventType()); } } else if (kBState.IsKeyDown(Keys.A) && lastKBState.IsKeyUp(Keys.A)) { if (left != null) { left.Publish(left, new global::Recellection.Code.Utility.Events.EventType()); } } else if (kBState.IsKeyDown(Keys.D) && lastKBState.IsKeyUp(Keys.D)) { if (right != null) { right.Publish(right, new global::Recellection.Code.Utility.Events.EventType()); } } #endif if (newActivatedRegion != null) { GUIRegion temp = newActivatedRegion; newActivatedRegion = null; return(temp); } } }
/// <summary> /// Gets input from the Tobii controller. /// </summary> /// <returns>An activated Region in the current menu</returns> public static MenuIcon GetInput() { while (true) { tobiiController.SetRegionsEnabled(true); GUIRegion activated = tobiiController.GetActivatedRegion(); tobiiController.SetRegionsEnabled(false); //tobiiController.UnloadMenu(menuModel.Peek()); Menu m = menuModel.Peek(); List <MenuIcon> options = m.GetIcons(); foreach (MenuIcon mi in options) { if (mi.region.RegionIdentifier == activated.RegionIdentifier) { return(mi); } } if (m.leftOff != null && m.leftOff.region.RegionIdentifier == activated.RegionIdentifier) { return(m.leftOff); } else if (m.rightOff != null && m.rightOff.region.RegionIdentifier == activated.RegionIdentifier) { return(m.rightOff); } else if (m.topOff != null && m.topOff.region.RegionIdentifier == activated.RegionIdentifier) { return(m.topOff); } else if (m.botOff != null && m.botOff.region.RegionIdentifier == activated.RegionIdentifier) { return(m.botOff); } } }
// the TobiiController subscribes to all regions Activate event void newRegion_regionActivated(object publisher, global::Recellection.Code.Utility.Events.Event <GUIRegion> ev) { newActivatedRegion = (GUIRegion)publisher; }
void FocusEnter(object sender, RegionFocusEventArgs e) { newActivatedRegion = (GUIRegion)sender; }
//use only with offscreenregion! public MenuIcon(GUIRegion region) { this.region = region; }