Exemplo n.º 1
0
void World::update(const Buttons& buttons,uint32_t frame_counter) {

  Point topLeft(_background.getTopLeft());
  uint16_t i;
  float f;

  // sample the navigation buttons

  if(buttons.isRightPressed() && topLeft.Y>0)
    topLeft.Y-=4;
  else if(buttons.isLeftPressed() && topLeft.Y!=1920-640)
    topLeft.Y+=4;

  if(buttons.isUpPressed() && topLeft.X>0)
    topLeft.X-=4;
  else if(buttons.isDownPressed() && topLeft.X!=1280-360)
    topLeft.X+=4;

  // set the new position

  _background.setTopLeft(topLeft);

  // update the components

  _background.update();

  f=static_cast<float>(frame_counter);
  for(i=0;i<_levelDef.ActorCount;i++)
    _actors[i]->update(f,_background.getTopLeft());
}
Exemplo n.º 2
0
void Buttons::mousePassiveMotion(void *buttonsInstance, int x, int y) {
	Buttons * b = (Buttons *)buttonsInstance;
	Button * button = b->getBtnUnderCursor(x, y);
	b->unhoverAll();
	if (button && button->enabled)
		button->hover();
}
Exemplo n.º 3
0
/**
Deals with dimensions menu control and pause
*/
void Level::TakeInput(Buttons &buttons)
{
	if (buttons.LIsHeld() && !paused && !player.isholding)
	{
		indimensionsmenu = true;
	}
	else
	{
		indimensionsmenu = false;
	}
	
	if (buttons.StartJustPressed() && !buttons.LIsHeld())
	{
		paused = !paused;
	}	
	
	if (!paused && !indimensionsmenu)
	{
		player.ReadButtons(buttons, *this);
	}
	
	if (indimensionsmenu)
	{
		DimensionMenuControl(buttons);
	}
}
Exemplo n.º 4
0
// ----------------------------------------------------------------------
void EventInputQueue::push_RelativePointerEventCallback(OSObject* target,
                                                        int buttons_raw,
                                                        int dx,
                                                        int dy,
                                                        AbsoluteTime ts,
                                                        OSObject* sender,
                                                        void* refcon) {
  GlobalLock::ScopedLock lk;
  if (!lk) return;

  Params_RelativePointerEventCallback::log(true, Buttons(buttons_raw), dx, dy);

  // ------------------------------------------------------------
  Buttons buttons(buttons_raw);
  Buttons justPressed;
  Buttons justReleased;

  IOHIPointing* device = OSDynamicCast(IOHIPointing, sender);
  if (!device) return;

  ListHookedPointing::Item* item = static_cast<ListHookedPointing::Item*>(ListHookedPointing::instance().get(device));
  if (!item) return;

  // ------------------------------------------------------------
  CommonData::setcurrent_ts(ts);

  // ------------------------------------------------------------
  justPressed = buttons.justPressed(item->get_previousbuttons());
  justReleased = buttons.justReleased(item->get_previousbuttons());
  item->set_previousbuttons(buttons);

  // ------------------------------------------------------------
  // divide an event into button and cursormove events.
  for (int i = 0; i < ButtonStatus::MAXNUM; ++i) {
    PointingButton btn(1 << i);
    if (justPressed.isOn(btn)) {
      Params_RelativePointerEventCallback params(buttons, 0, 0, btn, true);
      bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
      enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());
    }
    if (justReleased.isOn(btn)) {
      Params_RelativePointerEventCallback params(buttons, 0, 0, btn, false);
      bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
      enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());
    }
  }
  // If (dx == 0 && dy == 0), the event is either needless event or just pressing/releasing buttons event.
  // About just pressing/releasing buttons event, we handled these in the above processes.
  // So, we can drop (dx == 0 && dy == 0) events in here.
  if (dx != 0 || dy != 0) {
    Params_RelativePointerEventCallback params(buttons, dx, dy, PointingButton::NONE, false);
    bool retainFlagStatusTemporaryCount = true;
    enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());
  }

  setTimer();
}
  void
  EventOutputQueue::FireRelativePointer::fire(Buttons toButtons, int dx, int dy)
  {
    // When changing space to command+left click,
    //   --KeyToPointingButton-- KeyCode::SPACE, PointingButton::LEFT, ModifierFlag::COMMAND_L
    //
    // We need to release command key after left click was released as follows.
    //   (1) KeyDown   Command_L
    //   (2) MouseDown Left
    //   (3) MouseUp   Left
    //   (4) KeyUp     Command_L
    //
    // For mouse drag support, command modifier is increased as normal (not temporary_increase).
    // Therefore, command modifier is decreased when space key is released.
    // If we call FireModifiers::fire() at the begining of this function,
    // input events are fired as follows order.
    //   (1) KeyDown   Command_L
    //   (2) MouseDown Left
    //   (3) KeyUp     Command_L
    //   (4) MouseUp   Left
    //
    // It's not desired order.
    // So, we call FireModifiers::fire() at the end of this function when button is released.

    Buttons releasedButtons = lastButtons_;
    releasedButtons.remove(toButtons);
    bool isButtonReleased = ! releasedButtons.isNONE();

    if (! isButtonReleased) {
      FireModifiers::fire();
    }

    // Sending button event
    if (lastButtons_ != toButtons) {
      lastButtons_ = toButtons;

      Params_RelativePointerEventCallback::auto_ptr ptr(Params_RelativePointerEventCallback::alloc(toButtons, 0, 0, PointingButton::NONE, false));
      if (! ptr) return;
      Params_RelativePointerEventCallback& params = *ptr;

      EventOutputQueue::push(params);
    }

    // Sending cursor
    if (dx != 0 || dy != 0) {
      Params_RelativePointerEventCallback::auto_ptr ptr(Params_RelativePointerEventCallback::alloc(toButtons, dx, dy, PointingButton::NONE, false));
      if (! ptr) return;
      Params_RelativePointerEventCallback& params = *ptr;

      EventOutputQueue::push(params);
    }

    if (isButtonReleased) {
      FireModifiers::fire();
    }
  }
Exemplo n.º 6
0
/**
Deals with button presses in dimensions menu
*/
void Level::DimensionMenuControl(Buttons &buttons)
{
	prevdimension = curdimension;
	
	if (buttons.UpJustPressed())
	{
		if (curdimension == NORMAL)
		{
			curdimension = FLUFFY;
		}
		else if (curdimension == HEAVY)
		{
			curdimension = NORMAL;
		}
	}
	else if (buttons.DownJustPressed())
	{
		if (curdimension == NORMAL)
		{
			curdimension = HEAVY;
		}
		else if (curdimension == FLUFFY)
		{
			curdimension = NORMAL;
		}
	}
	else if (buttons.LeftJustPressed())
	{
		if (curdimension == NORMAL)
		{
			curdimension = SLOWMOTION;
		}
		else if (curdimension == ANTIGRAVITY)
		{
			curdimension = NORMAL;
			//Reverse gravity for all cubes in level
			ApplyAntigravity();
		}
	}
	else if (buttons.RightJustPressed())
	{
		if (curdimension == NORMAL)
		{
			curdimension = ANTIGRAVITY;
			//Reverse gravity for all cubes in level
			ApplyAntigravity();
		}
		else if (curdimension == SLOWMOTION)
		{
			curdimension = NORMAL;
		}
	}
}
Exemplo n.º 7
0
TEST(Buttons, add) {
  Buttons buttons;
  buttons.add(PointingButton::LEFT);
  EXPECT_EQ(Buttons(PointingButton::LEFT), buttons);

  buttons.add(PointingButton::MIDDLE);
  EXPECT_EQ(Buttons(PointingButton::LEFT | PointingButton::MIDDLE), buttons);

  // some PointingButton twice.
  buttons.add(PointingButton::LEFT);
  EXPECT_EQ(Buttons(PointingButton::LEFT | PointingButton::MIDDLE), buttons);

  buttons = 0;
  buttons.add(PointingButton::LEFT | PointingButton::MIDDLE);
  EXPECT_EQ(Buttons(PointingButton::LEFT | PointingButton::MIDDLE), buttons);
}
Exemplo n.º 8
0
	virtual void onDraw(GLV& g){
		draw::color(colors().text);
		float x = tabs.width()+10;
		const char * str = "Amazingly few discotheques provide jukeboxes.";
		font.size( 6).render(str, x, 10);
		font.size( 8).render(str, x, 30);
		font.size(12).render(str, x, 50);
	}
Exemplo n.º 9
0
void
FormProperties::setButtons( Buttons b )
{
	if( b.testFlag( MinimizeButton ) )
		d->m_ui.m_minimize->setChecked( true );
	else
		d->m_ui.m_minimize->setChecked( false );

	if( b.testFlag( MaximizeButton ) )
		d->m_ui.m_maximize->setChecked( true );
	else
		d->m_ui.m_maximize->setChecked( false );

	if( b.testFlag( CloseButton ) )
		d->m_ui.m_close->setChecked( true );
	else
		d->m_ui.m_close->setChecked( false );
}
Exemplo n.º 10
0
void UIVR::update_device_lists() {
  VMDTracker *tracker = NULL;
  Buttons *buttons = NULL;

  tracker = new SpaceballTracker(app);
  trackerList.add_name(tracker->device_name(), tracker);
  buttons = new SpaceballButtons(app);
  buttonList.add_name(buttons->device_name(), buttons);

  tracker = new MobileTracker(app);
  trackerList.add_name(tracker->device_name(), tracker);
  buttons = new MobileButtons(app);
  buttonList.add_name(buttons->device_name(), buttons);

#ifdef VMDVRPN
  Feedback *feedback = NULL;
  tracker = new VRPNTracker;
  trackerList.add_name(tracker->device_name(), tracker);
  feedback = new VRPNFeedback;
  feedbackList.add_name(feedback->device_name(), feedback);
  buttons = new VRPNButtons;
  buttonList.add_name(buttons->device_name(), buttons);
#endif

#ifdef VMDCAVE
  tracker = new CaveTracker;
  trackerList.add_name(tracker->device_name(), tracker);
  buttons = new CaveButtons;
  buttonList.add_name(buttons->device_name(), buttons);
#endif

#ifdef VMDFREEVR
  tracker = new FreeVRTracker(app);
  trackerList.add_name(tracker->device_name(), tracker);
  buttons = new FreeVRButtons(app);
  buttonList.add_name(buttons->device_name(), buttons);
#endif

#ifdef WINGMAN
  buttons = new JoystickButtons;
  buttonList.add_name(buttons->device_name(), buttons);
#endif
}
Exemplo n.º 11
0
void MessageDialog::addButtons(const Buttons &f) {
	_actionLayout.setSpacing(8);
	_actionLayout.setContentsMargins(0, 8, 0, 8);
	_actionLayout.addStretch();
	if (f.testFlag(Button::NoButton)) return;
	if (align() == Align::Ltr) {
		if (f.testFlag(Button::Cancel)) {
			_cancel = new FlatButton("CANCEL", this);
			_actionLayout.addWidget(_cancel);
			QObject::connect(_cancel, SIGNAL(clicked()), this, SLOT(onClick()));
		}
		if (f.testFlag(Button::OK)) {
			_ok = new FlatButton("OK", this);
			_actionLayout.addWidget(_ok);
			QObject::connect(_ok, SIGNAL(clicked()), this, SLOT(onClick()));
		}
		if (f.testFlag(Button::No)) {
			_no = new FlatButton("No", this);
			_actionLayout.addWidget(_no);
			QObject::connect(_no, SIGNAL(clicked()), this, SLOT(onClick()));
		}
		if (f.testFlag(Button::Yes)) {
			_yes = new FlatButton("YES", this);
			_actionLayout.addWidget(_yes);
			QObject::connect(_yes, SIGNAL(clicked()), this, SLOT(onClick()));
		}
		if (f.testFlag(Button::Close)) {
			_close = new FlatButton("CLOSE", this);
			_actionLayout.addWidget(_close);
			QObject::connect(_close, SIGNAL(clicked()), this, SLOT(onClick()));
		}

		if (f.testFlag(Button::Dicard)) {
			_dicard = new FlatButton("DISCARD", this);
			_actionLayout.addWidget(_dicard);
			QObject::connect(_dicard, SIGNAL(clicked()), this, SLOT(onClick()));
		}
	}
}
Exemplo n.º 12
0
 bool isOn(Buttons buttons) const {
   return (value_ & buttons.get()) == buttons.get();
 }
Exemplo n.º 13
0
void drawCB(View * v, GLV& g){
	using namespace glv::draw;
	for(int i=0; i<tabs.size(); ++i) groups[i].property(Visible, tabs.getValue(i));
}
Exemplo n.º 14
0
int main(int argc, char ** argv){
	
	GLV top(drawCB);
	
	Window win(600, 400, "Example: Widgets", &top);

	sl1HS.interval(1,-1);
	sl1VS.interval(1,-1);
	sliders1.interval(1,-1);
	sg3.interval(20,-20);
	sl2.interval(20,-20);
	slRH.interval(2,-2);
	
	glv::Style::standard().color.set(StyleColor::BlackOnWhite);
//	glv::Style::standard().color.set(StyleColor::WhiteOnBlack);
//	glv::Style::standard().color.set(StyleColor::Gray);
//	glv::Style::standard().color.hsv(0.5,0.5,0.2);
	
	for(int i=0; i<pages; ++i){
		top << groups[i].disable(Visible | HitTest).stretch(1,1);
	}
	
	fg.tension(1.);

	table	<< new Label("col span") << new Label("row span", true)
			<< new Label("top-left") << new Label("top-center") << new Label("top-right") 
			<< new Label("center-left") << new Label("center-center") << new Label("center-right")
			<< new Label("bottom-left") << new Label("bottom-center") << new Label("bottom-right");
	table.arrange();
	//table.enable(DrawBorder);

	plotXY.data().resize(Data::FLOAT, 2, 64);
	const float ffreq = 2*M_PI/(plotXY.data().size(1)-1);
	for(int i=0; i<plotXY.data().size(1); ++i){
		float phs = i*ffreq;
		float sigX = (cos(phs) + 0.5*cos(2*phs))/(1+0.5);
		float sigY = (sin(phs) + 0.5*sin(2*phs))/(1+0.5);
		plotXY.data().assign(sigX, 0,i);
		plotXY.data().assign(sigY, 1,i);
	}
	plotXY.numbering(true);
	plotY.data() = plotXY.data().slice(0).shape(1,1,64).stride(2);
	plotX.data() = plotXY.data().slice(1).shape(1,64,1).stride(2);
	plotY.major(8,1).range(0, plotXY.data().size(1), 1);
	plotX.major(8,0).range(0, plotXY.data().size(1), 0);

	plotX.disable(glv::Controllable);

	// Produce matrix of values
	{
		dplot.data().resize(Data::FLOAT, 1,32,32);
		Data& data = dplot.data();
		for(int j=0; j<data.size(2); ++j){
			for(int i=0; i<data.size(1); ++i){
				double y = double(j)/data.size(2)*2-1;
				double x = double(i)/data.size(1)*2-1;
				double r = (sin(hypot(x,y)*8));
				data.assign(r, 0, i,j);
			}
		}
	}

	v3D << v3D2.pos(Place::BR).anchor(Place::BR);

//btsLED.enable(Momentary);
	int i=-1;
	groups[++i]<< bt1.pos(Place::BL).anchor(Place::CC)(Event::MouseDrag, Behavior::mouseResize);
	groups[  i]<< bt2.pos(Place::BR, -4,0).anchor(Place::CC)(Event::MouseDrag, Behavior::mouseResize);
	groups[  i]<< (btl.pos(Place::TR, -4, 4).anchor(Place::CC) << new Label("OK", Place::CC, 0,0));
	groups[++i]<< bts14.pos(Place::BR, -4,0).anchor(Place::CC);
	groups[  i]<< bts41.pos(Place::TL, 0, 4).anchor(Place::CC);
	groups[  i]<< bts44.pos(Place::BL).anchor(Place::CC);
	groups[  i]<< btsLED.padding(3).pos(Place::BL, bts44.w+4,0).anchor(Place::CC).enable(SelectOnDrag).disable(DrawGrid);
	groups[++i]<< fg.pos(Place::BL).anchor(Place::CC);
//	groups[++i]<< fontView.stretch(1,1);
	groups[++i]<< (new Label("Horizontal"))->pos(Place::BL).anchor(Place::CC);
	groups[  i]<< (new Label("Vertical", true))->pos(Place::BR,-16,0).anchor(Place::CC);
	groups[++i]<< nd1.pos(Place::BL).anchor(Place::CC);
	groups[  i]<< nd2.showSign(false).pos(Place::TL, 0, 4).anchor(Place::CC);
	groups[++i]<< sl1H.pos(Place::BL).anchor(Place::CC);
	groups[  i]<< sl1V.pos(Place::BR, -4,0).anchor(Place::CC);
	groups[  i]<< sl1HS.pos(Place::BL).anchor(Place::CC); sl1HS.top(sl1H.bottom()+4);
	groups[  i]<< sl1VS.pos(Place::BR, -4,0).anchor(Place::CC); sl1VS.right(sl1V.left()-4);
	groups[++i]<< sl2.pos(Place::BL).anchor(Place::CC);
	groups[++i]<< sg3.pos(Place::BL).anchor(Place::CC);
	groups[  i]<< sg4.pos(Place::TL, 0, 4).anchor(Place::CC);
	groups[++i]<< slRH.pos(Place::BL).anchor(Place::CC);
	groups[  i]<< slRV.pos(Place::BR, -4,0).anchor(Place::CC);
	groups[++i]<< sliders1.pos(Place::BR).anchor(Place::CC); 
	groups[  i]<< sliders2.pos(Place::BL, 4,0).anchor(Place::CC);
	groups[++i]<< table.pos(Place::BC).anchor(Place::CC);
	groups[++i]<< plotXY.pos(Place::BL).anchor(Place::CC);
	groups[  i]<< plotX.pos(Place::TL, 0,4).anchor(Place::CC);
	groups[  i]<< plotY.pos(Place::BR,-4,0).anchor(Place::CC);
	groups[++i]<< dplot.pos(Place::CC).anchor(Place::CC);
	groups[++i]<< tv1.pos(Place::CC, 0,0).anchor(Place::CC);
	groups[++i]<< v3D.pos(Place::CC, 0,0).anchor(Place::CC);

	float y = 1./(tabs.size()*2), dy=2*y;
	tabs << (new Label("Button"			))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Buttons"		))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("FunctionGraph"	))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Label"			))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("NumberDialer"	))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Slider"			))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Slider2D"		))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("SliderGrid"		))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("SliderRange"	))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Sliders"		))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Table"			))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Function Plots"	))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("Density Plot"	))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("TextView"		))->anchor(0.5, y).pos(Place::CC); y+=dy;
	tabs << (new Label("View3D"			))->anchor(0.5, y).pos(Place::CC); y+=dy;
	top << tabs;

	//tabs(Event::MouseDrag, Behavior::mouseResize);

	//#define PRINT_SIZE(x) printf("sizeof(%s) = %d\n", #x, sizeof(x));
	//PRINT_SIZE(View) PRINT_SIZE(Notifier) PRINT_SIZE(Rect)

	Application::run();
}
Exemplo n.º 15
0
//						Update game5
void update( ESContext* ctx, float deltaTime )
{
    if(getKeyState(KeyCodes::KEY_ESCAPE))
    {
        deinit(ctx);
        exit(0);
    }

    if(player.isHeJumping == true)
    {
        PlayHop();
    }

    int number = button1.Update(deltaTime);



    switch(gameState)
    {
    case 0:
        menu.background->setPosition(0,0);
        insertText.background->setPosition(400,400);
        dead.background->setPosition(400,400);
        //gameState = 1;
        button1.buttons->setPosition(-6, 1);
        switch (number)
        {
        case 1:
            gameState = 1;
            break;
        case 2:
            break;
        case 3:
            break;
        }
        break;
    case 1:

        switch (letterState)
        {
        case 0:
            insertText.background->setPosition(0,0.35f);
            button1.buttons->setPosition(-400, 400);
            insertText.background->setPosition(0,0.35f);
            score->m_nameText1->setText( to_string(score->letters[score->lindex]));
            score->nameText1->setPosition(-0.5f,0);
            break;
        case 1:
            score->m_nameText2->setText( to_string(score->letters[score->lindex]));
            score->nameText2->setPosition(0,0);
            break;
        case 2:
            score->m_nameText3->setText( to_string(score->letters[score->lindex]));
            score->nameText3->setPosition(0.5f,0);
            break;
        case 3:
            //gameState = 2;
            //button1.buttons->setPosition(4, 4);
            if(getKeyState(KeyCodes::KEY_RETURN))
            {
                menu.background->setPosition(400,400);
                insertText.background->setPosition(400,400);
                score->nameText1->setPosition(-0.5f,-5);
                score->nameText2->setPosition(0,-5);
                score->nameText3->setPosition(0.5f,-5);

                gameState = 2;
            }

            break;
        }

        if(isButtonPressed == false)
        {
            if(getKeyState(KeyCodes::KEY_DOWN))
            {
                score->lindex++;
                isButtonPressed = true;
                if (score->lindex > 25)
                {
                    score->lindex = 25;
                }
            }

            if(getKeyState(KeyCodes::KEY_UP))
            {
                score->lindex--;
                isButtonPressed = true;
                if (score->lindex < 0)
                {
                    score->lindex = 0;
                }
            }

            if(getKeyState(KeyCodes::KEY_RETURN))
            {
                letterState++;
                scoreList.push_back(score->letters[score->lindex]);
                isButtonPressed = true;
            }
        }
        else if(!getKeyState(KeyCodes::KEY_DOWN) && !getKeyState(KeyCodes::KEY_UP) && !getKeyState(KeyCodes::KEY_RETURN))
        {
            isButtonPressed = false;
        }
        break;
    case 2:
        count++;

        button1.buttons->setPosition(400, 400);

        dangers[0].speed = 8.5f * (1 + score->highscore/20000);
        dangers[1].speed = 3.5f * (1 + score->highscore/20000);
        dangers[2].speed = 15.5f * (1 + score->highscore/20000);

        player.Update(deltaTime);
        enemy.Update(deltaTime);
        health.Update(deltaTime);
        score->update(deltaTime);
        notDanger.Update(deltaTime);
        apple.Update(deltaTime);
        banana.Update(deltaTime);
        map->update(deltaTime);

        score->highscore += backgrounds[0].boost/10;

        if(player.isHeDead == true)
        {
            if(isPlayerScreamed == false)
            {
                PlayNoo();
            }
        }

        for (size_t i = 0; i < backgrounds.size(); i++)
        {
            backgrounds[i].Update(deltaTime);
        }

        for (size_t i = 0; i < dangers.size(); i++)
        {

            dangers[i].Update(deltaTime);
            //	Collision between player and danger
            if ((player.hitx > dangers[i].hitx - 0.6f && player.hitx < dangers[i].hitx + 0.8f
                    && player.hity > dangers[i].hity - 0.5f
                    && player.hity -1.3f < dangers[i].hity + 0.5f) && player.isHeBlinking == false)
            {
                if(player.isHeDead == false)
                {
                    PlayAuts();
                    //engine->play2D("ouch.wav", false);
                }
                dangers[i].Respawn();
                player.DangerHit();
                player.Blink();

                // spark effect
                spark1.Hit();
                spark1.spark->setPosition((float)dangers[i].hitx,(float)dangers[i].hity);
                // slow effect
                for (int i = 0; i < 6; i++)
                {
                    backgrounds[i].Slow();
                }
                // player slow effect
                player.Slow();
            }

            // Player pickups a bonus
            if (notDanger.danger->collidesTo(player.player))
            {
                PlayNom();
                //engine->play2D("pickup1.wav", false);
                notDanger.Respawn();
                health.Medkit();
                score->strawberry();
            }
            // Player pickups a bonus
            if (banana.danger->collidesTo(player.player))
            {
                PlayNom();
                //engine->play2D("pickup1.wav", false);
                banana.Respawn();
                //health.Medkit();
                score->banaani();
            }
            // Player pickups a bonus
            if (apple.danger->collidesTo(player.player))
            {
                PlayNom();
                //engine->play2D("pickup1.wav", false);
                apple.Respawn();
                //health.Medkit();
                score->omena();
            }
        }
        // Hit hippo
        if (player.hitx <= -6.0f)
        {
            //health.hp = 0;
            //player.Death();
            PlayAuts();
            player.Blink();
            player.HippoHit();
            if(player.isHeDead == true)
            {
                if(isPlayerScreamed == false)
                {
                    PlayNoo();
                }
            }
        }

        if (player.hity >= 40.0f)
        {
            dangers[0].Respawn();
            dangers[1].Respawn();
            dangers[2].Respawn();
            notDanger.Respawn();
            player.die = 0;
            engine->play2D("deathscreen.wav", false);
            health.newGame();
            gameState = 3;
            dead.background->setPosition(0,2);
        }
        break;
    case 3:
        if (isScoresRead == false)
        {
            writeHighScores(ceil(score->highscore));
            sqlite3_exec(db, "select * FROM scores ORDER BY score DESC LIMIT 0, 5;", callback, NULL, NULL);
            isScoresRead = true;
        }

        for (size_t i = 0; i < score->scoreTexts.size(); i++)
        {
            score->scoreTextObjects[i]->setPosition(vec2(7,-4.5f + i*0.5f));
        }

        if(getKeyState(KeyCodes::KEY_R))
        {
            gameState = 2;
            player.player->setPosition(-1,2.5);
            score->highscore = 0;
            isPlayerScreamed = false;
            isScoresRead = false;
            dindex = 0;
            dead.background->setPosition(400,400);

            for (int i = 0; i < 5; i++)
            {
                score->scoreTextObjects[i]->setPosition(vec2(-15,0));
            }
        }
        break;
    }
}
Exemplo n.º 16
0
int main()
{
	// Set display options.
	// DCNT_MODE0 sets mode 0, which provides four tiled backgrounds.
	// DCNT_OBJ enables objects.
	// DCNT_OBJ_1D make object tiles mapped in 1D (which makes life easier).
	REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ;
	
	REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32 | BG_PRIO(0);
	
	REG_BG1CNT = BG_CBB(0) | BG_SBB(29) | BG_8BPP | BG_REG_32x32 | BG_PRIO(1);
	
	REG_BG2CNT = BG_CBB(0) | BG_SBB(25) | BG_8BPP | BG_REG_64x64 | BG_PRIO(2);
	REG_BG2HOFS = 0;
	REG_BG2VOFS = 0;
	
	ClearObjects();
	
	SetPaletteBG(1, RGB(31, 31, 31)); // white
	
	//Load each tile in font_bold into it's corresponding position in charblock 0
	for (int i = 0; i < 128; i++)
	{
		LoadTile8(0, i, font_bold[i]);
	}
	
	DrawText(5, (SCREEN_HEIGHT / 16) - 2, "DECEPTIVE DIMENSIONS");
	DrawText(5, (SCREEN_HEIGHT / 16), "Press start to begin");
	
	Buttons buttons;
	int framecounter = 0;
	
	//Title screen (under construction)
	while (true)
	{
		buttons.Update();
		
		if (buttons.StartJustPressed())
		{
			break;
		}
		
		WaitVSync();	
	}
	
	while (true)
	{
		//Load Custom spritesheet
		LoadPaletteObjData(0, spritesheet4Pal, sizeof spritesheet4Pal);
		LoadPaletteBGData(0, backgroundnewnewPal, sizeof backgroundnewnewPal);
		LoadTileData(4, 0, spritesheet4Tiles, sizeof spritesheet4Tiles);
		LoadTileData(0, 0, backgroundnewnewTiles, sizeof backgroundnewnewTiles);
		
		int levelnumber = 1;
		
		Level level(levelnumber);
		
		for (int screenblock = 21; screenblock < 31; screenblock++)
		{
			level.FillScreenblock(screenblock, 0);
		}
		
		level.DrawBackground(level.curdimension);
		
		bool gamerunning = true;
		
		//Main game loop
		while (gamerunning)
		{
			buttons.Update();
			
			gamerunning = level.CheckIfLevelComplete();
			level.TakeInput(buttons);
			level.MoveObjects();
			level.Draw();
			level.UpdateLevelObjects(framecounter);

			framecounter++;
			
			WaitVSync();
			FlipBuffers();
		}
		
		//Reload each tile in font_bold into it's corresponding position in charblock 0
		for (int i = 0; i < 128; i++)
		{
			LoadTile8(0, i, font_bold[i]);
		}
		
		SetPaletteBG(0, RGB(0, 0, 0)); // black
		SetPaletteBG(1, RGB(31, 31, 31)); // white		
		
		for (int screenblock = 25; screenblock < 31; screenblock++)
		{
			for (int y = 0; y < 32; y++)
			{
				for (int x = 0; x < 32; x++)
				{
					SetTile(screenblock, x, y, 0);
				}
			}
		}
		
		level.player.drawx = SCREEN_WIDTH;
		
		SetObject(level.player.GetObjNum(),
		  ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_HIDE,
		  ATTR1_SIZE(2) | ATTR1_X(level.player.drawx),
		  ATTR2_ID8(0) | ATTR2_PRIO(2));
		
		UpdateObjects();
		
		DrawText(6, (SCREEN_HEIGHT / 16) - 2, "That's all folks!!");
		DrawText(3, (SCREEN_HEIGHT / 16), "Press start to try again");
		
		while (true)
		{
			buttons.Update();
			
			if (buttons.StartJustPressed())
			{
				break;
			}
			
			WaitVSync();
		}
	}
}
Exemplo n.º 17
0
int main(){

//	{
//		const std::string mAlign = "xxx,<><,--x";
//		const int mRepeatRow = 1;
//
//		int row = 0;
//		int ibeg=0, iend=0;
//		for(int i=0; i<mAlign.size(); ++i){
//			if(mAlign[i] == ','){
//				++row;
//				
//			}
//		}
//	}

	#define SET4(x, a,b,c,d) x[0]=a; x[1]=b; x[2]=c; x[3]=d
	#define EQ4(x, a,b,c,d) (x[0]==a && x[1]==b && x[2]==c && x[3]==d)

	// Multidimensional data array
	{
	
		// basics
		{
			const int s1=5, s2=4, s3=3, s4=2;
			Data d(Data::INT, s1,s2,s3,s4);

			assert(d.hasData());
			assert(d.type() == Data::INT);
			assert(d.sizeType() == sizeof(int));
			assert(d.isNumerical());
			assert(d.offset() == 0);
			assert(d.order() == 4);
			assert(d.stride() == 1);

			assert(d.size(0) == s1);
			assert(d.size(1) == s2);
			assert(d.size(2) == s3);
			assert(d.size(3) == s4);
			assert(d.size(0,1) == s1*s2);
			assert(d.size(0,1,2) == s1*s2*s3);
			assert(d.size(0,1,2,3) == d.size());
		
			assert(d.indexFlat(0,0,0,0) ==          0);
			assert(d.indexFlat(1,0,0,0) ==          1);
			assert(d.indexFlat(0,1,0,0) ==       s1*1);
			assert(d.indexFlat(0,2,0,0) ==       s1*2);
			assert(d.indexFlat(0,0,1,0) ==    s2*s1*1);
			assert(d.indexFlat(0,0,2,0) ==    s2*s1*2);
			assert(d.indexFlat(0,0,0,1) == s3*s2*s1*1);
			assert(d.indexFlat(0,0,0,2) == s3*s2*s1*2);
			
			for(int i=0; i<d.size(); ++i){
				int i1,i2,i3,i4;
				d.indexDim(i1,i2,i3,i4, i);
				assert(d.inBounds(i1,i2,i3,i4));
				assert(d.indexFlat(i1,i2,i3,i4) == i);
			}
			
			for(int i=0; i<d.size(); ++i) d.assign(i, i);
			for(int i=0; i<d.size(); ++i) assert(d.elem<int>(i) == i);
			
			// resizing
			{
				Data e(Data::INT, 8);
				int N; // resize change, in bytes

				for(int i=0; i<e.size(); ++i) e.assign(i,i);
				
				N=e.resize(16);			assert(e.sizeType()*8==N);
				
				// old elements should be copied over; extras should be zero
				for(int i=0; i<8 ; ++i) assert(e.at<int>(i) == i);
				for(int i=8; i<16; ++i) assert(e.at<int>(i) == 0);

				N=e.resize(0);			assert(e.sizeType()*-16==N);
				N=e.resize(8);			assert(e.sizeType()*  8==N);
				for(int i=0; i<e.size(); ++i) assert(e.at<int>(i) == 0);
			}
			
			// cloning data
			{
				Data e = d;
				assert(e == d);
				
				e.clone();
				assert(d.elems<int>() != e.elems<int>());
				assert(e == d);
			}
			
			// reversed slice
			{				
				Data e = d.reversed();
				for(int i=0; i<e.size(); ++i)
					assert(d.elem<int>(d.size()-1-i) == e.elem<int>(i));

				e.clone();
				for(int i=0; i<e.size(); ++i)
					assert(d.elem<int>(d.size()-1-i) == e.elem<int>(i));
				
				e += d;
				for(int i=0; i<e.size(); ++i)
					assert(e.elem<int>(i) == e.size()-1);
			}
		}


		// reference counting
		{
			Data d1(Data::INT, 4,4);
			assert(Data::references(d1.elems<int>()) == 1);

			{
				Data d2 = d1;
				assert(d1.elems<int>() == d2.elems<int>());
				assert(Data::references(d1.elems<int>()) == 2);
			}
			assert(Data::references(d1.elems<int>()) == 1);

			{
				Data d2 = d1.slice(1);
				Data d3 = d2.slice(1);
				assert(Data::references(d1.elems<int>()) == 3);
			}
			assert(Data::references(d1.elems<int>()) == 1);
		}
		
	
		const float cf = 10;
		float f = 10;
		std::string s = "hello";
		
		Data d(cf);

		assert(d.hasData());
		assert(d.size() == 1);
		assert(d.type() == Data::FLOAT);
		assert(d.at<float>(0) == cf);
		assert(d.toString() == "10");
		assert(d.at<std::string>(0) == "10");
		
//		d.put(std::string("8"));
//		assert(d.at<float>(0) == 8);

		// Getting/setting values
		d.assign(11.f);
		assert(d.at<float>(0) == 11.f);
		
		d.clone();
		assert(d.hasData());
		assert(d.size() == 1);
		assert(d.type() == Data::FLOAT);

		d.assign(11.f);
		assert(d.at<float>(0) == 11.f);

		d.assign(100);
		assert(d.at<float>(0) == 100);
		
		d.set(f);
		assert(d.elems<float>() == &f);
		assert(d.at<float>(0) == f);
		
		d.set(s);
		assert(d.type() == Data::STRING);
		assert(d.size() == 1);
		assert(d.elems<std::string>() == &s);
		assert(d.at<std::string>(0) == s);
		
		d.clone();
		assert(d.elems<std::string>() != &s);
		assert(d.at<std::string>(0) == s);

		d.set("hello");
		assert(d.type() == Data::STRING);
		assert(d.at<std::string>(0) == "hello");

		{
			std::string s = "d2";
			Data d2(s);
			
			d.set("d");
			d2.assign(d);
			assert(d2.at<std::string>(0) == d.at<std::string>(0));
		}
		
		{
			Data a(Data::FLOAT, 3);
			a.assign(10,0);
			a.assign(20,1);
			a.assign(30,2);
			float b[3];
			a.copyTo(b);
			for(int i=0;i<3;++i) assert(b[i] == a.at<float>(i));
		}
		
		// checking elements
		{
			Data::Type types[] = {Data::BOOL, Data::INT, Data::FLOAT, Data::DOUBLE};
			for(int i=0;i<4;++i){
				Data a(types[i], 8);
				a.assignAll(0);
				assert(a.isZero());
				a.assign(1, 1);
				assert(!a.isZero());
				a.assign(1, 3);
				a.assign(1, 5);
				a.assign(1, 7);
				assert(a.slice(0,4,2).isZero());
			}
		}
		
		// searching
		{
			Data e(Data::STRING, 3);
			std::string s1 = "test1", s2 = "test2", s3 = "test3";
			e.assign(s1, 0);
			e.assign(s2, 1);
			e.assign(s3, 2);
			
			assert(e.indexOf(s1) == 0);
			assert(e.indexOf(s2) == 1);
			assert(e.indexOf(s3) == 2);
			assert(e.indexOf(std::string("invalid")) == Data::npos);
		}
		
		// multiple element assignment
		{
			#define ASSERT_EQUALS(a,b,c,d,e)\
				assert(d1.at<int>(0) == a);\
				assert(d1.at<int>(1) == b);\
				assert(d1.at<int>(2) == c);\
				assert(d1.at<int>(3) == d);\
				assert(d1.at<int>(4) == e)

			Data d1(Data::INT, 5);
			d1.assignAll(-1);
			ASSERT_EQUALS(-1,-1,-1,-1,-1);
			
			d1.assignAll(0);
			ASSERT_EQUALS(0,0,0,0,0);
			
			{
				float t[] = {1,2,3,4,5};
				d1.assignFromArray(t,2);
				ASSERT_EQUALS(1,2,0,0,0);
				
				d1.assignFromArray(t+2,2,1,2);
				ASSERT_EQUALS(1,2,3,4,0);
				
				d1.assignAll(0);
				d1.assignFromArray(t,3, 2);
				ASSERT_EQUALS(1,3,5,0,0);
				
				d1.assignFromArray(t+1,2, 2,3);
				ASSERT_EQUALS(1,3,5,2,4);
			}
			#undef ASSERT_EQUALS
		}
	}


	// stringification
	{	//for(int i=0;i<4;++i) printf("%g\n", f4[i]);
		//printf("%s\n", s1.c_str());
		bool b1;
		float f1;
		double d1;
		std::string s1;
		
		bool b4[4];
		float f4[4];
		double d4[4];
		std::string s4[4];
		
		int N;	// number of elements converted

		N=fromToken(f1, "1e-2");		assert(1==N && f1 == float(1e-2));
		N=fromToken(f1, "1000");		assert(1==N && f1 == float(1000));
		N=fromToken(d1, "1e-2");		assert(1==N && d1 == double(1e-2));
		N=fromToken(d1, "1000");		assert(1==N && d1 == double(1000));
		N=fromToken(b1, "0");			assert(1==N && b1 == 0);
		N=fromToken(b1, "1");			assert(1==N && b1 == 1);
		N=fromToken(s1, "\"test\"");	assert(1==N && s1 == "test");
		
		N=fromToken(b4,4,1, "{1,0,1,1}");				assert(4==N && EQ4(b4, 1,0,1,1));
		N=fromToken(b4,4,1, "{0,  1, 0,0}");			assert(4==N && EQ4(b4, 0,1,0,0));
		N=fromToken(f4,4,1, "{1, -1.2, 1e10, +.1}");	assert(4==N && EQ4(f4, 1.f,-1.2f,1e10f,+.1f));
		N=fromToken(d4,4,1, "{1, -1.2, 1e10, +.1}");	assert(4==N && EQ4(d4, 1,-1.2,1e10,+.1));
		N=fromToken(s4,4,1, "{\"one\", \"two\", \"three\", \"four\"}");
														assert(4==N && EQ4(s4, "one","two","three","four"));

		N=toToken(s1, 1000.f);			assert(1==N && s1 == "1000");
		N=toToken(s1, 2000.0);			assert(1==N && s1 == "2000");
		N=toToken(s1, true);			assert(1==N && s1 == "1");
		N=toToken(s1, false);			assert(1==N && s1 == "0");
		N=toToken(s1, "test");			assert(1==N && s1 == "\"test\"");
		N=toToken(s1, std::string("test"));
										assert(1==N && s1 == "\"test\"");		

		SET4(b4, 1,0,1,1);		N=toToken(s1, b4,4,1);	assert(4==N && s1 == "{1, 0, 1, 1}");
		SET4(f4,-1,0.1,3,1e10);	N=toToken(s1, f4,4,1);	assert(4==N && s1 == "{-1, 0.1, 3, 1e+10}");
		SET4(d4,-1,0.1,3,1e10);	N=toToken(s1, d4,4,1);	assert(4==N && s1 == "{-1, 0.1, 3, 1e+10}");
		SET4(s4,"one","two","three","four"); N=toToken(s1,s4,4,1);
														assert(4==N && s1 == "{\"one\", \"two\", \"three\", \"four\"}");
	}


	// test View linked list implementation
	{
		View n00, n10, n11, n20;

		n00.add(n10);
		n00.add(n11);
		n10.add(n20);
		
		// check all of our links
		assert( n00.child == &n10);
		assert(!n00.parent);
		assert(!n00.sibling);
		assert( n10.parent == &n00);
		assert( n10.sibling == &n11);
		assert( n10.child == &n20);
		assert( n11.parent == &n00);
		assert(!n11.child);
		assert(!n11.sibling);
		assert( n20.parent == &n10);
		assert(!n20.child);
		assert(!n20.sibling);
		
		n10.makeLastSibling();
		assert(!n10.sibling);
		assert(n11.sibling == &n10);
		n11.makeLastSibling();

		n10.remove();
		assert(!n10.parent);
		assert(!n10.sibling);
		assert(!n00.child->sibling);
		
		n11.remove();
		assert(!n00.child);

		assert(n10.child == &n20);
	}

	
	// test View memory management
	{
		View * v0d = new View;
		View v1s;
		View * v1d = new View;
		
		assert(v0d->dynamicAlloc());
		assert(!v1s.dynamicAlloc());

		*v0d << v1s << v1d;
		
		delete v0d;
	}



	// Notifications	
	{
		bool bv1=false, bv2=false, bf=false;
		Notifier n;
	
		assert(n.numObservers(Update::Value) == 0);

		n.attach(ntSetBool1, Update::Value, &bv1);
		n.attach(ntSetBool2, Update::Value, &bv2);
		n.attach(ntSetBool1, Update::Focus, &bf);

		assert(n.numObservers(Update::Value) == 2);
		assert(n.numObservers(Update::Focus) == 1);

		n.notify(Update::Value);
		assert(bv1);
		assert(bv2);
		assert(!bf);

		n.notify(Update::Focus);
		assert(bf);
		
		bv1=bv2=false;
		n.detach(ntSetBool1, Update::Value, &bv1);
		n.notify(Update::Value);
		assert(!bv1);
		assert(bv2);

		bv1=bv2=false;
		n.detach(ntSetBool2, Update::Value, &bv2);
		n.notify(Update::Value);
		assert(!bv1);
		assert(!bv2);
	}
	
	{
		bool b=false;
		Button w;
		w.attach(ntValue, Update::Value, &b);
		w.setValue(true);
		assert(b);
		assert(w.getValue() == true);

// Setting to current value should NOT send notification to avoid infinite loops
		b=false;
		w.setValue(w.getValue());
		assert(!b);

// Boolean model variable
		bool v = false;
		w.attachVariable(v);
		w.setValue(true);		assert(v == true);
		w.setValue(false);		assert(v == false);
		
		v = true;
		w.onDataModelSync();		assert(w.getValue() == true);

		w.setValue(true);

		assert(w.data().toToken() == "1");
		w.setValue(false);
		assert(w.data().toToken() == "0");
		w.setDataFromString("0");	assert(w.getValue() == false);
		w.setDataFromString("1");	assert(w.getValue() == true);

		assert(!w.setDataFromString("invalid"));
	}

	{
		Buttons w;
		bool b=false;
		w.attach(ntValue, Update::Value, &b);
		w.setValue(true, 0);
		assert(b);
		assert(w.getValue(0) == true);
		
		w.data().resize(2,2);
		w.data().assignAll(0);

		bool v1 = false;
		bool v2 = false;
		w.attachVariable(v1, 0);
		w.attachVariable(v2, 2);

		w.setValue(true, 0);		assert(v1 == true);
		w.setValue(true, 2);		assert(v2 == true);
		w.setValue(false, 0);		assert(v1 == false);
		w.setValue(false, 2);		assert(v2 == false);

		w.setValue(false, 0);
		w.setValue(false, 1);
		w.setValue(false, 2);
		w.setValue(false, 3);
		assert(w.data().toToken() == "{0, 0, 0, 0}");
		
		v1 = v2 = false;
		w.setDataFromString("{1,1,1,1}");
		assert(w.getValue(0) && w.getValue(1) && w.getValue(2) && w.getValue(3));
		assert(v1 && v2);
	}

	{
		bool b=false;
		Slider w;
		w.attach(ntValue, Update::Value, &b);
		w.setValue(0.99f);
		assert(b);
		assert(w.getValue() == 0.99f);

// Setting to current value should NOT send notification to avoid infinite loops
		b=false;
		w.setValue(w.getValue());
		assert(!b);

		float v;
		w.attachVariable(v);
		w.setValue(0.99);
		assert(v == 0.99f);
		
		v = 0;
		w.onDataModelSync();
		assert(w.getValue() == 0);

		std::string s;
		w.setValue(0.25);
		assert(w.data().toToken() == "0.25");
		w.setDataFromString("0.5");	assert(w.getValue() == 0.5);
									assert(v == 0.5);

		assert(!w.setDataFromString("invalid"));
		assert(w.getValue() == 0.5);
	}

	{
		bool b=false;
		Sliders w(Rect(1), 2,2);
		w.attach(ntValue, Update::Value, &b);
		w.setValue(0.99f, 3);
		assert(b);
		assert(w.getValue(3) == 0.99f);

		float v1, v2;
		w.attachVariable(v1, 0);
		w.attachVariable(v2, 1);

		w.setValue(0.1f, 0); assert(v1 == 0.1f);
		w.setValue(0.2f, 0); assert(v1 == 0.2f);
		
		v1 = 0.8f; v2 = 0.9f;
		w.onDataModelSync();
		assert(w.getValue(0) == 0.8f);
		assert(w.getValue(1) == 0.9f);

		w.setValue(0.1f, 0);
		w.setValue(0.2f, 1);
		w.setValue(0.3f, 2);
		w.setValue(0.4f, 3);
		assert(w.data().toToken() == "{0.1, 0.2, 0.3, 0.4}");
		
		v1=v2=0;
		w.setDataFromString("{0.4,0.3,0.2,0.1}");
		assert(w.getValue(0) == 0.4);
		assert(w.getValue(1) == 0.3);
		assert(w.getValue(2) == 0.2);
		assert(w.getValue(3) == 0.1);
		assert(v1 == (float)w.getValue(0) && v2 == (float)w.getValue(1));
		
//		double vs[4] = {0.11, 0.22, 0.33, 0.44};
//		w.attachVariable(vs,4);
//		w.onDataModelSync();
//		for(int i=0; i<4; ++i) printf("%f\n", w.values()[i]);
//		
//		w.getValue(0.44, 0);
//		w.getValue(0.33, 0);
//		w.getValue(0.22, 0);
//		w.getValue(0.11, 0);
//		for(int i=0; i<4; ++i) printf("%f\n", vs[i]);
	}

	{
		bool b=false;
		Slider2D w;
		w.attach(ntSetBool1, Update::Value, &b);
		w.setValue(0.01f, 0);
		assert(b);
		assert(w.getValue(0) == 0.01f);

// Setting to current value should NOT send notification to avoid infinite loops
		b=false;
		w.setValue(0.01f, 0);
		assert(!b);
		
		b=false;
		w.setValue(0.00f, 0);
		w.setValue(0.01f, 1);
		assert(b);
		assert(w.getValue(1) == 0.01f);
		
		b=false;
		w.setValueMax();
		assert(b);
		assert(w.getValue(0) == 1.f);
		assert(w.getValue(1) == 1.f);
		
		float v1, v2;
		w.attachVariable(v1, 0);
		w.attachVariable(v2, 1);
		
		w.setValue(0.5f, 0);	assert(v1 == 0.5f);
		w.setValue(0.6f, 1);	assert(v2 == 0.6f);
		
		v1 = 0.1;
		v2 = 0.2;
		
		w.onDataModelSync();
		assert(w.getValue(0) == v1);
		assert(w.getValue(1) == v2);
	
		w.setValue(0.2, 0);
		w.setValue(0.3, 1);
		assert(w.data().toToken() == "{0.2, 0.3}");
		
		v1 = v2 = 0;
		w.setDataFromString("{0.7, 0.8}");
		assert(w.getValue(0)==0.7 && w.getValue(1)==0.8);
		assert(v1==(float)w.getValue(0) && v2==(float)w.getValue(1));
	}

	{
		bool b=false;
		SliderGrid<4> w;
		w.attach(ntValue, Update::Value, &b);
		w.setValue(0.01f, 0);
		assert(b);
		assert(w.getValue(0) == 0.01f);

		float v1, v2;
		w.attachVariable(v1, 0);
		w.attachVariable(v2, 1);

		w.setValue(0.1f, 0); assert(v1 == 0.1f);
		w.setValue(0.2f, 0); assert(v1 == 0.2f);
		
		v1 = 0.8f; v2 = 0.9f;
		w.onDataModelSync();
		assert(w.getValue(0) == 0.8f);
		assert(w.getValue(1) == 0.9f);

		w.setValue(0.1f, 0);
		w.setValue(0.2f, 1);
		w.setValue(0.3f, 2);
		w.setValue(0.4f, 3);
		assert(w.data().toToken() == "{0.1, 0.2, 0.3, 0.4}");
		
		v1=v2=0;
		w.setDataFromString("{0.4,0.3,0.2,0.1}");
		assert(w.getValue(0) == 0.4);
		assert(w.getValue(1) == 0.3);
		assert(w.getValue(2) == 0.2);
		assert(w.getValue(3) == 0.1);
		assert(v1 == (float)w.getValue(0) && v2 == (float)w.getValue(1));
	}
	
	{
		bool b=false;
		SliderRange w;
		w.attach(ntValue, Update::Value, &b);
		w.setValue(0.01f, 0);
		w.setValue(0.02f, 1);
		assert(b);
		assert(w.getValue(0) == 0.01f);
		assert(w.getValue(1) == 0.02f);
		assert(w.center() == 0.015f);
		assert(w.range() == 0.01f);
		
		w.endpoints(0,1);
		assert(w.getValue(0) == 0);
		assert(w.getValue(1) == 1);
		
		w.centerRange(0.5, 0.25);
		assert(w.getValue(0) == (0.5-0.25/2));
		assert(w.getValue(1) == (0.5+0.25/2));

		float v1,v2;
		w.attachVariable(v1, 0);
		w.attachVariable(v2, 1);

		w.setValue(0.2, 0);
		w.setValue(0.3, 1);
		assert(w.data().toToken() == "{0.2, 0.3}");
		
		v1 = v2 = 0;
		w.setDataFromString("{0.7, 0.8}");
		assert(w.getValue(0)==0.7 && w.getValue(1)==0.8);
		assert(v1==(float)w.getValue(0) && v2==(float)w.getValue(1));
	}

	{
		bool b=false;
		Label w;

		w.attach(ntValue, Update::Value, &b);
		w.setValue("test");
		assert(b);
		assert(w.getValue() == "test");
		
		assert(w.data().toToken() == "\"test\"");
		
		w.setValue("");
		w.setDataFromString("\"test\"");	assert(w.getValue() == "test");
	}

	{

//		{
//			double val = 1e14;
//			double inc = 1;
//			printf("%f\n", val + inc*1);
//			printf("%f\n", val + inc*2);
//			printf("%f\n", val + inc*3);
//			printf("%f\n", val + inc*4);
//		}

		bool b=false;
		NumberDialer w(1,2,1,0);
		w.attach(ntValue, Update::Value, &b);
		w.setValue(0.75);
		assert(b);
		assert(w.getValue() == 0.75);

// Setting to current value should NOT send notification to avoid infinite loops
		b=false;
		w.setValue(w.getValue());
		assert(!b);

		double v=0;
		w.attachVariable(v);
		w.setValue(0.5);	assert(v == 0.5);
		
		v = 0.25;
		w.onDataModelSync();
		assert(w.getValue() == v);

		w.setValue(0.2);
		assert(w.data().toToken() == "0.2");
		
		v = 0;
		w.setDataFromString("0.8");
		assert(w.getValue()==0.8 && w.getValue()==v);
	}

	{
		bool b=false;
		TextView w;
		w.attach(ntValue, Update::Value, &b);
		w.setValue("hello");
		assert(b);
		assert(w.getValue() == "hello");
		
		assert(w.data().toToken() == "\"hello\"");

		std::string v = "test";
		w.attachVariable(v);
		
		w.onDataModelSync();
		assert(w.getValue() == "test");

		w.setDataFromString("\"world\"");
		assert(w.getValue() == "world");
		assert(v == "world");
	}



	// model to string conversion
	{
		Label l;
		TextView tv;
		Button b;
		Buttons bs(Rect(), 2, 2);
		Slider s;
		Sliders ss(Rect(), 1, 4);
		Slider2D s2D;
		NumberDialer nd(1,4,1,-1);
		std::string strings[] = {"test1", "test2", "test3"};
	
		l.setValue("Hello Label!").name("l");
		tv.setValue("Hello TextView!").name("tv");
		b.setValue(true).name("b");
		bs.setValue(true, 0,1).name("bs");
		s.setValue(0.5).name("s");
		ss.setValue(0.4, 1).name("ss");
		s2D.setValue(0.5, 0).setValue(0.1, 1).name("s2D");
		nd.setValue(-0.54941).name("nd");

		const View * views[] = {&l, &tv, &b, &bs, &s, &ss, &s2D, &nd};
		for(unsigned i=0; i<sizeof(views)/sizeof(View *); ++i){
			//const Data& d = views[i]->data();
			//printf("%p: %s\n", &d, d.toString().c_str());
			//views[i]->model().print(); printf("\n");
		}

		View top;
		top << l << tv << b << bs << s << ss << s2D << nd;
	
		std::string str1, str2;
//		top.modelToString(str1, "test model");		
//		printf("%s\n", str1.c_str());
//
//		l.setValue("changed...");
//		top.modelFromString(str1);
//		top.modelToString(str2);
//		printf("%s\n", str2.c_str());
//		assert(str1 == str2);

		ModelManager mm;
		
		mm.add("l", l);
		mm.add("tv", tv);
		mm.add("b", b);
		mm.add("bs", bs);
		mm.add("s" , s);
		mm.add("ss", ss);
		mm.add("s2D",s2D);
		mm.add("nd", nd);
		
		Data dat(strings, 3);
		//Data dat(10);
		//dat.print();
		//mm.add("strings", dat);
		//mm.add("strings", *new Data(strings, 3));
		
//		mm.toToken(str1, "test");
//		printf("%s\n", str1.c_str());
//		
//		mm.fromToken(str1);
//		mm.toToken(str2, "test");
//		printf("%s\n", str2.c_str());

		std::string snapshotString1 =
"[\"test 1\"] = {\n\
	l = \"Label 1\",\n\
	tv = \"TextView 1\",\n\
	b = 0,\n\
	bs = {0,0,0,0},\n\
}";

		std::string snapshotString2 =
"[\"test 2\"] = {\n\
	l = \"Label 2\",\n\
	tv = \"TextView 2\",\n\
	b = 1,\n\
	bs = {1,1,1,1},\n\
	s = 1,\n\
	ss = {1,1,1,1},\n\
	s2D = {1,1},\n\
	nd = 1,\n\
}";
		
		mm.snapshotsFromString("{" + snapshotString1 + ",\r\n" + snapshotString2 + "}");

//		mm.snapshots()["test 1"]["l"].print();
//		mm.snapshots()["test 1"]["b"].print();
//		mm.snapshots()["test 1"]["bs"].print();
//		mm.snapshots()["test 1"]["s"].print();
//		mm.snapshots()["test 1"]["ss"].print();
//		mm.snapshots()["test 1"]["s2D"].print();
//		mm.snapshots()["test 1"]["nd"].print();
//		mm.snapshots()["test 2"]["l"].print();
//		mm.snapshots()["test 2"]["b"].print();
//		mm.snapshots()["test 2"]["bs"].print();
//		mm.snapshots()["test 2"]["s"].print();
//		mm.snapshots()["test 2"]["ss"].print();
//		mm.snapshots()["test 2"]["s2D"].print();
//		mm.snapshots()["test 2"]["nd"].print();
//
//		mm.snapshotsToFile("snapshots.txt");
//		
//		mm.clearSnapshots();
//		mm.snapshotsFromFile("snapshots.txt");
//
//		str1.clear();
//		mm.snapshotsToString(str1);
//		printf("%s\n", str1.c_str());
	}

//	{
//		std::string str( "a bc ab ca ab" );
//		std::string searchString("ab"); 
//		std::string replaceString("hello");
//
//		std::string::size_type pos = 0;
//		while((pos = str.find(searchString, pos)) != std::string::npos){
//			str.replace(pos++, searchString.size(), replaceString);
//		}
//		printf("%s\n", str.c_str());
//	}

//	printf("sizeof(Notifier): %d\n", sizeof(Notifier));
//	printf("sizeof(View): %d\n", sizeof(View));
//	printf("sizeof(Data): %d\n", sizeof(Data));
//	printf("sizeof(Model): %d\n", sizeof(Model));
//	printf("sizeof(ModelManager): %d\n", sizeof(ModelManager));

	return 0;
}
Exemplo n.º 18
0
void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPointer& pickResult) {
    // TODO: avatars/HUD?
    auto pointerManager = DependencyManager::get<PointerManager>();

    // NOTE: After this loop: _prevButtons = buttons that were removed
    // If switching to disabled or should stop triggering, release all buttons
    Buttons buttons;
    Buttons newButtons;
    Buttons sameButtons;
    if (_enabled && shouldTrigger(pickResult)) {
        buttons = getPressedButtons(pickResult);
        for (const std::string& button : buttons) {
            if (_prevButtons.find(button) == _prevButtons.end()) {
                newButtons.insert(button);
            } else {
                sameButtons.insert(button);
                _prevButtons.erase(button);
            }
        }
    }

    // Hover events
    bool doHover = shouldHover(pickResult);
    Pointer::PickedObject hoveredObject = getHoveredObject(pickResult);
    PointerEvent hoveredEvent = buildPointerEvent(hoveredObject, pickResult);
    hoveredEvent.setType(PointerEvent::Move);
    hoveredEvent.setID(pointerID);
    bool moveOnHoverLeave = (!_enabled && _prevEnabled) || (!doHover && _prevDoHover);
    hoveredEvent.setMoveOnHoverLeave(moveOnHoverLeave);

    // if shouldHover && !_prevDoHover, only send hoverBegin
    if (_enabled && _hover && doHover && !_prevDoHover) {
        if (hoveredObject.type == ENTITY) {
            emit pointerManager->hoverBeginEntity(hoveredObject.objectID, hoveredEvent);
        } else if (hoveredObject.type == LOCAL_ENTITY) {
            emit pointerManager->hoverBeginOverlay(hoveredObject.objectID, hoveredEvent);
        } else if (hoveredObject.type == HUD) {
            emit pointerManager->hoverBeginHUD(hoveredEvent);
        }
    } else if (_enabled && _hover && doHover) {
        if (hoveredObject.type == LOCAL_ENTITY) {
            if (_prevHoveredObject.type == LOCAL_ENTITY) {
                if (hoveredObject.objectID == _prevHoveredObject.objectID) {
                    emit pointerManager->hoverContinueOverlay(hoveredObject.objectID, hoveredEvent);
                } else {
                    PointerEvent prevHoveredEvent = buildPointerEvent(_prevHoveredObject, pickResult);
                    prevHoveredEvent.setID(pointerID);
                    prevHoveredEvent.setMoveOnHoverLeave(moveOnHoverLeave);
                    emit pointerManager->hoverEndOverlay(_prevHoveredObject.objectID, prevHoveredEvent);
                    emit pointerManager->hoverBeginOverlay(hoveredObject.objectID, hoveredEvent);
                }
            } else {
                emit pointerManager->hoverBeginOverlay(hoveredObject.objectID, hoveredEvent);
                if (_prevHoveredObject.type == ENTITY) {
                    emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, hoveredEvent);
                } else if (_prevHoveredObject.type == HUD) {
                    emit pointerManager->hoverEndHUD(hoveredEvent);
                }
            }
        }

        // TODO: this is basically repeated code.  is there a way to clean it up?
        if (hoveredObject.type == ENTITY) {
            if (_prevHoveredObject.type == ENTITY) {
                if (hoveredObject.objectID == _prevHoveredObject.objectID) {
                    emit pointerManager->hoverContinueEntity(hoveredObject.objectID, hoveredEvent);
                } else {
                    PointerEvent prevHoveredEvent = buildPointerEvent(_prevHoveredObject, pickResult);
                    prevHoveredEvent.setID(pointerID);
                    prevHoveredEvent.setMoveOnHoverLeave(moveOnHoverLeave);
                    emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, prevHoveredEvent);
                    emit pointerManager->hoverBeginEntity(hoveredObject.objectID, hoveredEvent);
                }
            } else {
                emit pointerManager->hoverBeginEntity(hoveredObject.objectID, hoveredEvent);
                if (_prevHoveredObject.type == LOCAL_ENTITY) {
                    emit pointerManager->hoverEndOverlay(_prevHoveredObject.objectID, hoveredEvent);
                } else if (_prevHoveredObject.type == HUD) {
                    emit pointerManager->hoverEndHUD(hoveredEvent);
                }
            }
        }

        if (hoveredObject.type == HUD) {
            if (_prevHoveredObject.type == HUD) {
                // There's only one HUD
                emit pointerManager->hoverContinueHUD(hoveredEvent);
            } else {
                emit pointerManager->hoverBeginHUD(hoveredEvent);
                if (_prevHoveredObject.type == ENTITY) {
                    emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, hoveredEvent);
                } else if (_prevHoveredObject.type == LOCAL_ENTITY) {
                    emit pointerManager->hoverEndOverlay(_prevHoveredObject.objectID, hoveredEvent);
                }
            }
        }

        if (hoveredObject.type == NONE) {
            if (_prevHoveredObject.type == ENTITY) {
                emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, hoveredEvent);
            } else if (_prevHoveredObject.type == LOCAL_ENTITY) {
                emit pointerManager->hoverEndOverlay(_prevHoveredObject.objectID, hoveredEvent);
            } else if (_prevHoveredObject.type == HUD) {
                emit pointerManager->hoverEndHUD(hoveredEvent);
            }
        }
    }

    // Trigger begin
    const std::string SHOULD_FOCUS_BUTTON = "Focus";
    for (const std::string& button : newButtons) {
        hoveredEvent.setType(PointerEvent::Press);
        hoveredEvent.setButton(chooseButton(button));
        hoveredEvent.setShouldFocus(button == SHOULD_FOCUS_BUTTON);
        if (hoveredObject.type == ENTITY) {
            emit pointerManager->triggerBeginEntity(hoveredObject.objectID, hoveredEvent);
        } else if (hoveredObject.type == LOCAL_ENTITY) {
            emit pointerManager->triggerBeginOverlay(hoveredObject.objectID, hoveredEvent);
        } else if (hoveredObject.type == HUD) {
            emit pointerManager->triggerBeginHUD(hoveredEvent);
        }
        _triggeredObjects[button] = hoveredObject;
    }

    // Trigger continue
    for (const std::string& button : sameButtons) {
        PointerEvent triggeredEvent = buildPointerEvent(_triggeredObjects[button], pickResult, button, false);
        triggeredEvent.setID(pointerID);
        triggeredEvent.setType(PointerEvent::Move);
        triggeredEvent.setButton(chooseButton(button));
        if (_triggeredObjects[button].type == ENTITY) {
            emit pointerManager->triggerContinueEntity(_triggeredObjects[button].objectID, triggeredEvent);
        } else if (_triggeredObjects[button].type == LOCAL_ENTITY) {
            emit pointerManager->triggerContinueOverlay(_triggeredObjects[button].objectID, triggeredEvent);
        } else if (_triggeredObjects[button].type == HUD) {
            emit pointerManager->triggerContinueHUD(triggeredEvent);
        }
    }

    // Trigger end
    for (const std::string& button : _prevButtons) {
        PointerEvent triggeredEvent = buildPointerEvent(_triggeredObjects[button], pickResult, button, false);
        triggeredEvent.setID(pointerID);
        triggeredEvent.setType(PointerEvent::Release);
        triggeredEvent.setButton(chooseButton(button));
        if (_triggeredObjects[button].type == ENTITY) {
            emit pointerManager->triggerEndEntity(_triggeredObjects[button].objectID, triggeredEvent);
        } else if (_triggeredObjects[button].type == LOCAL_ENTITY) {
            emit pointerManager->triggerEndOverlay(_triggeredObjects[button].objectID, triggeredEvent);
        } else if (_triggeredObjects[button].type == HUD) {
            emit pointerManager->triggerEndHUD(triggeredEvent);
        }
        _triggeredObjects.erase(button);
    }

    // if we disable the pointer or disable hovering, send hoverEnd events after triggerEnd
    if (_hover && ((!_enabled && _prevEnabled) || (!doHover && _prevDoHover))) {
        if (_prevHoveredObject.type == ENTITY) {
            emit pointerManager->hoverEndEntity(_prevHoveredObject.objectID, hoveredEvent);
        } else if (_prevHoveredObject.type == LOCAL_ENTITY) {
            emit pointerManager->hoverEndOverlay(_prevHoveredObject.objectID, hoveredEvent);
        } else if (_prevHoveredObject.type == HUD) {
            emit pointerManager->hoverEndHUD(hoveredEvent);
        }
    }

    _prevHoveredObject = hoveredObject;
    _prevButtons = buttons;
    _prevEnabled = _enabled;
    _prevDoHover = doHover;
}
Exemplo n.º 19
0
 static void log(bool isCaught, Buttons buttons, int dx, int dy) {
   IOLOG_DEBUG_POINTING("RelativePointerEventCallBack [%7s]: buttons: 0x%08x, dx: %3d, dy: %3d\n",
                        isCaught ? "caught" : "sending",
                        buttons.get(), dx, dy);
 }
Exemplo n.º 20
0
int main(void)
{
	// Enable watchdog (restart avr if program hangs for 2 seconds)
	wdt_enable(WDTO_2S);
	
	Buttons buttons;
	DHT22sensor sensor;
	
	//uart_init(UART_BAUD_SELECT(USART_BAUDRATE, F_CPU));
	extConnector.Init();
	
	// Initialize all connected devices
	//alarm.Init(OnAlarmStarted, OnAlarmEnded);
	alarm.ClearAllFlags();
	sevSegMenu.Init();
	ledIndicators.Init();
	buttons.Init();
	
	sensor.Init();
	sensorRefreshTimer.Init();
	sensorRefreshTimer.SetCounterTop(DHT22_REFRESHTIME);
	
	timerHum.Init();
	timerTemp.Init();
	
	speaker.InitSpeaker();
	speaker.PlayTone();
	
	//sensorResultAverageTemperature.Init();
	//sensorResultAverageHumidity.Init();
	
	MULTIPLEX_Setup();
	Timer_Setup();
	
	//ReadDefaultSettings(); done in readsettings if needed
	ReadSettings();
	
	triacTemp.InitPorts(&TRIAC_TEMP_PORT, &TRIAC_TEMP_DDR, TRIAC_TEMP_PIN, &regSettingsTemp.normallyClosed.variable);
	triacHum.InitPorts(&TRIAC_HUM_PORT, &TRIAC_HUM_DDR, TRIAC_HUM_PIN, &regSettingsHum.normallyClosed.variable);
	
	DHT22result sensorResult = {0,0};
	
	sei();
	//alarm.SetAlarmFlag(AlarmType_SOFTWARE_FAIL);
	//DHT22result tempResult = {0,0};
	while (1)
	{
		wdt_reset();
		uint8_t sendSensorDataOverUart = 0;
		
		if (!sensorRefreshTimer.IsRunning())
		{
			SensorResult sr = sensor.ReadSensor(&sensorResult);
			switch(sr)
			{
				case SensorOK:
				alarm.ClearAlarmFlag(AlarmType_SENSOR_FAILURE);
				bootCompleted = 1; // Enable regulation updates
				sendSensorDataOverUart = 1;
				sensorRefreshTimer.ResetCounter();
				//sensorAverage.ProcessValue(&sensorResult);
				break;
				
				default:
				alarm.SetAlarmFlag(AlarmType_SENSOR_FAILURE);
				
				sprintf_P(buffor, PSTR("E%u"), sr); // Newline gets added in SendAlarmInfo
				extConnector.uPuts(buffor); //uart_puts
				SendAlarmInfo();
				
				case SensorBusy:
				sensorRefreshTimer.AddTicks(20); // Reduce the error flood
				break;
			}
		}
		
		// If alarm is because of bad regulation, show normal menu instead of error code
		sevSegMenu.SetAlarm(alarm.GetActiveCriticalFlags());
		
		// Beep the speaker if buttons are pressed
		ButtonEvent currentButtonEvent = buttons.ProcessInputs();
		
		if (currentButtonEvent > BUTTON_MULTIPLE && currentButtonEvent < BUTTON_LEFT_RAPID )
		{
			speaker.PlayTone();
		}
		
		sevSegMenu.MainMenuUpdate(currentButtonEvent, &sensorResult);
		
		//////////////////////////////////////////////////////////////////////////
		// Regulation
		//_delay_ms(1);
		RegulationResult resTemp, resHum;
		
		resTemp = RegulationUpdate(AlarmType_TEMPERATURE_REGULATION, &sensorResult);
		resHum = RegulationUpdate(AlarmType_HUMIDITY_REGULATION, &sensorResult);
		
		//////////////////////////////////////////////////////////////////////////
		// Repaint LEDs
		sevSegMenu.TurnOnMenuLeds();
		
		if (alarm.GetActiveFlags())
		{
			ledIndicators.TurnOn(LED_Alarm);
		}
		
		if (triacTemp.GetState() || triacHum.GetState())
		{
			ledIndicators.TurnOn(LED_Praca);
		}
		ledIndicators.PushChanges();
		
		//////////////////////////////////////////////////////////////////////////
		// Update UART
		if (sendSensorDataOverUart)
		{
			//snprintf_P(buffor, UART_BUFFER_SIZE, PSTR("T%.3u.%u H%.3u.%u "),
			//extConnector.uPuts(buffor);
			
			//snprintf_P(buffor, UART_BUFFER_SIZE, PSTR("T%.3u.%u H%.3u.%u G%u N%u\r\n"),
			
			int8_t tempRemainder = sensorResult.temperature % 10;
			if (tempRemainder < 0)
			{
				tempRemainder *= -1;
			}
			
			sprintf_P(buffor, PSTR("T%i.%i H%u.%u G%u N%u"), // Newline at the end is added in SendAlarmInfo
				sensorResult.temperature / 10, tempRemainder,
				sensorResult.humidity / 10, sensorResult.humidity % 10,
				resTemp, resHum);
			extConnector.uPuts(buffor);
			SendAlarmInfo();
		}
		
		ProcessUartInput();
		
		if (saveSettingsQueued)
		{
			saveSettingsQueued = 0;
			SaveSettings();
		}
	}
}
Exemplo n.º 21
0
  // ----------------------------------------------------------------------
  void
  EventInputQueue::push_RelativePointerEventCallback(OSObject* target,
                                                     int buttons_raw,
                                                     int dx,
                                                     int dy,
                                                     AbsoluteTime ts,
                                                     OSObject* sender,
                                                     void* refcon)
  {
    IOLockWrapper::ScopedLock lk_eventlock(CommonData::getEventLock());
    if (! lk_eventlock) return;
    IOLockWrapper::ScopedLock lk(timer_.getlock());
    if (! lk) return;

    // ------------------------------------------------------------
    Buttons buttons(buttons_raw);
    Buttons justPressed;
    Buttons justReleased;

    DeviceVendor deviceVendor(0);
    DeviceProduct deviceProduct(0);
    {
      IOLockWrapper::ScopedLock lk_device(ListHookedKeyboard::instance().getListLock());
      if (! lk_device) return;

      IOHIPointing* device = OSDynamicCast(IOHIPointing, sender);
      if (! device) return;

      ListHookedPointing::Item* item = static_cast<ListHookedPointing::Item*>(ListHookedPointing::instance().get_nolock(device));
      if (! item) return;

      // ------------------------------------------------------------
      CommonData::setcurrent_ts(ts);
      deviceVendor = item->getVendor();
      deviceProduct = item->getProduct();

      // ------------------------------------------------------------
      justPressed = buttons.justPressed(item->get_previousbuttons());
      justReleased = buttons.justReleased(item->get_previousbuttons());
      item->set_previousbuttons(buttons);
    }

    // ------------------------------------------------------------
    // divide an event into button and cursormove events.
    for (int i = 0; i < ButtonStatus::MAXNUM; ++i) {
      PointingButton btn(1 << i);
      if (justPressed.isOn(btn)) {
        Params_RelativePointerEventCallback::auto_ptr ptr(Params_RelativePointerEventCallback::alloc(buttons, 0, 0, btn, true));
        if (! ptr) return;
        bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
        enqueue_(*ptr, retainFlagStatusTemporaryCount, deviceVendor, deviceProduct);
      }
      if (justReleased.isOn(btn)) {
        Params_RelativePointerEventCallback::auto_ptr ptr(Params_RelativePointerEventCallback::alloc(buttons, 0, 0, btn, false));
        if (! ptr) return;
        bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
        enqueue_(*ptr, retainFlagStatusTemporaryCount, deviceVendor, deviceProduct);
      }
    }
    Params_RelativePointerEventCallback::auto_ptr ptr(Params_RelativePointerEventCallback::alloc(buttons, dx, dy, PointingButton::NONE, false));
    if (! ptr) return;
    bool retainFlagStatusTemporaryCount = true;
    enqueue_(*ptr, retainFlagStatusTemporaryCount, deviceVendor, deviceProduct);

    setTimer();
  }
Exemplo n.º 22
0
 Buttons operator|(Buttons other) const { return value_ | other.get(); }
Exemplo n.º 23
0
 bool operator==(Buttons other) const { return value_ == other.get(); }