Пример #1
0
TEST(ViewUnitTest, CheckConstructor)
{
    View * v = new View;
    EXPECT_TRUE(v->flag_.focusable);
    EXPECT_TRUE(v->flag_.mouseable);
    EXPECT_TRUE(v->flag_.visible);
    EXPECT_EQ(0, v->children_count_);
    EXPECT_EQ(-1, v->group_id_);
    EXPECT_EQ(1.0f, v->opacity_);
    v->release();
}
Пример #2
0
SceneSample1::SceneSample1(ApplicationController *controller) : Scene(controller) {
    LayoutInflater *inflater = controller->getLayoutInflater();
    
    View *root = inflater->inflate("layout/main.xml");
    inflater->release();
    
    Button *button = (Button*)root->findViewByID(3);
    button->setOnButtonClickListener(this);
    
    Layer2D *layer = new Layer2D(controller);
    layer->setContentView(root);
    root->release();
    addLayer(1, layer);
}
Пример #3
0
void SpriteTests::testHierarchyIntersect()
{
  AutoreleasePool::begin();

  vector<Shape*> sprites;
  
  View* view = new MockView;
  for (int i=0; i<5; ++i) {
    Sprite* sp = new Sprite(view);
    sp->setPosition(Vector2(4.0f*i, 4.0f*i));
    sprites.push_back(sp);
  }
  
  ShapeGroup* group = new ShapeGroup(sprites.begin(), sprites.end());
  
  // To test that bounding box is correct
  Rect2 r1(Vector2(-1.0f, -1.0f), Vector2(17.0f, 17.0f));    
  
  TestCmd cmd;
  
  Sprite* sprite = new Sprite(view);
  cmd.expectedMe = sprites[4];
  cmd.expectedOther = sprite;
  
  sprite->setPosition(Vector2(16.5f, 15.5f));  
  CPTAssert(group->collide(sprite, t, dt, &cmd)); 
  sprite->setPosition(Vector2(19.0f, 19.0f));
  CPTAssert(!group->collide(sprite, t, dt));      
  CPTAssert(group->boundingBox() == r1);
  
  sprite->release();
  group->release();
  view->release();

  AutoreleasePool::end();  
}
Пример #4
0
TEST(ViewUnitTest, Completeness)
{
    View * v = new View;
    auto r = new Root;
    r->attachChildToBack(v);
    EXPECT_EQ(r, v->getRoot());

    v->setOpacity(0.5f);
    EXPECT_EQ(0.5f, v->getOpacity());

    v->setLoc(1, 2);
    EXPECT_EQ(1, v->getLoc().x());
    EXPECT_EQ(2, v->getLoc().y());
    EXPECT_EQ(1, v->getLeft());
    EXPECT_EQ(2, v->getTop());
    v->setSize(5, 6);
    EXPECT_EQ(5, v->getSize().width());
    EXPECT_EQ(6, v->getSize().height());
    EXPECT_EQ(5, v->getWidth());
    EXPECT_EQ(6, v->getHeight());
    Rect bounds;
    v->getLocalBounds(bounds);
    EXPECT_EQ(0, bounds.left());
    EXPECT_EQ(0, bounds.top());
    EXPECT_EQ(5, bounds.right());
    EXPECT_EQ(6, bounds.bottom());
    v->getGlobalBounds(bounds);
    EXPECT_EQ(1, bounds.left());
    EXPECT_EQ(2, bounds.top());
    EXPECT_EQ(6, bounds.right());
    EXPECT_EQ(8, bounds.bottom());
    
    EXPECT_EQ(6, v->mapToGlobal(Point::Make(5, 5)).x());
    EXPECT_EQ(7, v->mapToGlobal(Point::Make(5, 5)).y());
    EXPECT_EQ(4, v->mapToLocal(Point::Make(5, 5)).x());
    EXPECT_EQ(3, v->mapToLocal(Point::Make(5, 5)).y());

    v->setLoc(Point::Make(3, 4));
    EXPECT_EQ(3, v->getLeft());
    EXPECT_EQ(4, v->getTop());
    v->setSize(Size::Make(7, 8));
    EXPECT_EQ(7, v->getWidth());
    EXPECT_EQ(8, v->getHeight());
    v->setLeft(0);
    EXPECT_EQ(0, v->getLeft());
    v->setTop(0);
    EXPECT_EQ(0, v->getTop());
    v->setWidth(0);
    EXPECT_EQ(0, v->getWidth());
    v->setHeight(0);
    EXPECT_EQ(0, v->getHeight());


    v->setMouseable(false);
    EXPECT_FALSE(v->mouseable());
    v->setFocusable(false);
    EXPECT_FALSE(v->focusable());
    v->setVisible(false);
    EXPECT_FALSE(v->visible());

    v->setMouseable(true);
    EXPECT_TRUE(v->mouseable());
    EXPECT_FALSE(v->isMouseable());
    v->setFocusable(true);
    EXPECT_TRUE(v->focusable());
    EXPECT_FALSE(v->isFocusable());
    v->setVisible(true);
    EXPECT_TRUE(v->isFocusable());
    EXPECT_TRUE(v->isMouseable());

    r->recursiveDetachChildren();
    v->release();
    r->release();
}