wyActionTestLayer() {
            m_Sprite = wySprite::make(wyTexture2D::make(RES("R.drawable.grossini")));
            m_Sprite->retain();
            addChildLocked(m_Sprite, 2);
            m_Sprite->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight/ 2);
			m_Sprite->setScale(4);

        	wySprite* bg = wySprite::make(wyTexture2D::make(RES("R.drawable.background")));
        	bg->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight / 2);
        	addChildLocked(bg, -1);
        }
	wyCreateDatabaseTestLayer() {
		// value label
		m_value = wyLabel::make("value is");
		m_value->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight * 3 / 4);
		addChildLocked(m_value);

		// create buttons
		createButton("Create Database", this, wyDevice::winWidth / 2, wyDevice::winHeight / 2 + DP(40),
				wyTargetSelector::make(this, SEL(wyCreateDatabaseTestLayer::onCreate)));
		createButton("Delete Database", this, wyDevice::winWidth / 2, wyDevice::winHeight / 2 - DP(40),
				wyTargetSelector::make(this, SEL(wyCreateDatabaseTestLayer::onDelete)));

        // if database exist, update hint label now
		const char* path = "/sdcard/WiEngine/create_database_test.db";
		if(wyUtils::isPathExistent(path)) {
			// create database and open it
			wyDatabase* db = wyDatabase::make(path);
			db->open();

			// query the value inserted
			wyResultSet* rs = db->executeQuery("SELECT * FROM test");
			if(rs != NULL && rs->next()) {
				int value = rs->intForColumn("test_column");
				char buf[64];
				sprintf(buf, "value is %d", value);
				m_value->setText(buf);
			}
		}
	}
Exemple #3
0
wyMotionStreak::wyMotionStreak(float fade, wyTexture2D* tex, wyColor4B color, wyMotionStreakStyle style) :
		m_segThreshold(3),
		m_lastLocation(wyp(-1, -1)),
		m_currentLocation(wyp(-1, -1)),
		m_paused(false) {
	// init member
	m_pendingPoints = WYNEW vector<PendingPoint>();
	m_pendingPoints->reserve(10);

	// create ribbon by style
	switch(style) {
		case MS_STYLE_STRIP:
			m_ribbon = wyStripRibbon::make(tex, color, fade);
			break;
		case MS_STYLE_SPOT:
			m_ribbon = wySpotRibbon::make(tex, color, fade);
			break;
		case MS_STYLE_BLADE:
			m_ribbon = wyBladeRibbon::make(tex, color, fade);
			break;
		case MS_STYLE_LINE:
			m_ribbon = wyLineRibbon::make(tex, color);
			break;
	}

	// add ribbon to motion streak
    addChildLocked(m_ribbon);

    // update ribbon position
    wyTargetSelector* ts = wyTargetSelector::make(this, SEL(wyMotionStreak::update));
    wyTimer* timer = wyTimer::make(ts);
    scheduleLocked(timer);
}
	wyTransactionTestLayer() : m_db(NULL) {
		const char* path = "/sdcard/WiEngine/transaction_test.db";

		// value label
		m_hint = wyLabel::make("row count: 0");
		m_hint->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight * 3 / 4);
		addChildLocked(m_hint);

		// create buttons
		createButton("Insert One Row", this, wyDevice::winWidth / 2, wyDevice::winHeight / 2,
				wyTargetSelector::make(this, SEL(wyTransactionTestLayer::onInsert)));
		createButton("Commit", this, wyDevice::winWidth / 2, wyDevice::winHeight / 2 - DP(60),
				wyTargetSelector::make(this, SEL(wyTransactionTestLayer::onCommit)));
		createButton("Rollback", this, wyDevice::winWidth / 2, wyDevice::winHeight / 2 - DP(120),
				wyTargetSelector::make(this, SEL(wyTransactionTestLayer::onRollback)));

		// open database, if it is not there, will create it
		m_db = wyDatabase::make(path);
		m_db->open();
		m_db->retain();

		// if no test table, create it
		if(!m_db->tableExists("test"))
			m_db->executeUpdate("CREATE TABLE test (_id INTEGER PRIMARY KEY autoincrement, test_column INTEGER)");

		// query the value inserted
		int rowCount = m_db->intForQuery("SELECT count() FROM test");
		char buf[64];
		sprintf(buf, "row count: %d", rowCount);
		m_hint->setText(buf);
	}
Exemple #5
0
void wyToast::addBackground() {
	// basic check
	if(!m_bg || m_bg->getParent())
		return;

	// add it with max z order
	addChildLocked(m_bg);
}
Exemple #6
0
void wyToast::addContent() {
	// basic check
	if(!m_content || m_content->getParent())
		return;

	// add it
	addChildLocked(m_content, 1);
}
Exemple #7
0
wyVirtualJoystick::wyVirtualJoystick(wyNode* bg, wyNode* rocker) :
		m_eventStyle(VJS_FIVE_DIRECTIONS),
		m_autoReset(true),
		m_navigating(false),
		m_pid(0),
		m_rockerRangeRadius(0),
		m_degree(VJD_CENTER),
		m_direction(VJD_CENTER),
		m_rockerX(0),
		m_rockerY(0),
		m_data(NULL),
#if ANDROID
		m_jCallback(NULL),
#endif
		m_bg(bg),
		m_rocker(rocker) {
	// init callback
	memset(&m_callback, 0, sizeof(wyVirtualJoystickCallback));

	// add bg and rocker
	if(m_bg)
		addChildLocked(m_bg);
	if(m_rocker)
		addChildLocked(m_rocker);
	wySize s = getFitSize();
	setContentSize(s.width, s.height);

	// set rocker range radius
	m_rockerRangeRadius = MIN(s.width, s.height) / 2;

	// adjust position
	if(m_bg) {
		m_bg->setAnchor(0.5f, 0.5f);
		m_bg->setRelativeAnchorPoint(true);
		m_bg->setPosition(m_width / 2, m_height / 2);
	}
	if(m_rocker) {
		m_rocker->setAnchor(0.5f, 0.5f);
		m_rocker->setRelativeAnchorPoint(true);
		m_rocker->setPosition(m_width / 2, m_height / 2);
	}

	// enable touch
	setTouchEnabled(true);
}
Exemple #8
0
void wyPageControl::setPageIndicator(wyPageIndicator* indicator) {
	if(m_indicator != indicator) {
		if(m_indicator)
			removeChildLocked(m_indicator, true);
		m_indicator = indicator;
		if(m_indicator) {
			addChildLocked(m_indicator, 0, 10000);
			m_indicator->initWithPages(m_pages->num, getBestIndex());
		}
	}
}
	wyPreferenceTestLayer() {
		// label for text box
		wyLabel* label = wyLabel::make("", SP(18), BOLD, WY_DEFAULT_FONT);
		label->setColor(wyc3bBlack);

        // create state sprite for text box
		wyNinePatchSprite* normal = wyNinePatchSprite::make(wyTexture2D::makePNG(RES("R.drawable.textbox_normal")), wyr(DP(13), DP(18), DP(1), DP(1)));
		wyNinePatchSprite* pressed = wyNinePatchSprite::make(wyTexture2D::makePNG(RES("R.drawable.textbox_pressed")), wyr(DP(13), DP(18), DP(1), DP(1)));
		wyNinePatchSprite* focused = wyNinePatchSprite::make(wyTexture2D::makePNG(RES("R.drawable.textbox_focused")), wyr(DP(13), DP(18), DP(1), DP(1)));
		normal->setContentSize(DP(280), DP(32));
		pressed->setContentSize(DP(280), DP(32));
		focused->setContentSize(DP(280), DP(32));

		// create text box
        wyTextBox* box = wyTextBox::make(normal, pressed, NULL, focused, label);
        box->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight / 2);
        box->setTitle("Input something!");
        box->setMessage("Hint message for input dialog");
        box->setPositiveButton("Modify");
        box->setNegativeButton("Oh No!");
        box->setPadding(DP(10), DP(3), DP(10), DP(6));
        static wyTextBoxCallback callback = {
        		NULL,
        		NULL,
        		onEndEditing
        };
        box->setCallback(&callback, this);
        addChildLocked(box);

        // label of hint
        wyLabel* hint = wyLabel::make("Input number and \nit will be saved", SP(18), BOLD, WY_DEFAULT_FONT);
        hint->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight / 2 + DP(44));
        addChildLocked(hint);

        // load value from preference, default value is -1
        char buf[32];
        int v = wyPrefs::getInt("test.int.pref", -1);
		sprintf(buf, "%d", v);
        box->setText(buf);
	}
Exemple #10
0
void wyTMXTileMap::setDebugDrawObjects(bool flag) {
	if(m_debugDrawObjects != flag) {
		m_debugDrawObjects = flag;

		// add object layer or remove it
		if(m_debugDrawObjects) {
			wyTMXObjectLayer* l = wyTMXObjectLayer::make(this);
			addChildLocked(l, TAG_OBJECT_LAYER, MAX_INT);
		} else {
			removeChildByTagLocked(TAG_OBJECT_LAYER, true);
		}
	}
}
Exemple #11
0
	wyBox2DTestLayer() :
			wyLayer(),
			m_mouseJoint(NULL),
			m_stepCount(0) {
		m_box2d = new wyBox2D();
		m_box2d->setDebugDraw(true);
		addChildLocked(m_box2d);

		b2BodyDef bodyDef;
		m_groundBody = m_box2d->getWorld()->CreateBody(&bodyDef);

		setTouchEnabled(true);
	}
Exemple #12
0
void wyScrollableLayer::setVerticalThumb(wyNode* thumb) {
	// remove old thumb
	if(m_verticalThumb) {
		removeChildLocked(m_verticalThumb, true);
		m_verticalThumb = NULL;
	}

	// set new thumb
	if(thumb) {
		m_verticalThumb = thumb;
		thumb->setAnchor(1, 1);
		addChildLocked(thumb);
		updateThumbSize();
		updateOffset();
	}
}
Exemple #13
0
void wySkeletalSprite::createBoneNodes(wyBone* bone) {
    // this node is root bone node, so need skip root bone
    wyBone::State& state = bone->getState(this);
    wyNode* boneNode = wyNode::make();
    state.node = boneNode;
    if(bone->getParent()) {
        wyBone::State& parentState = bone->getParent()->getState(this);
        parentState.node->addChildLocked(boneNode);
    } else {
        addChildLocked(boneNode);
    }

    wyBone::BonePtrList& children = bone->getChildren();
    for(wyBone::BonePtrList::iterator iter = children.begin(); iter != children.end(); iter++) {
        createBoneNodes(*iter);
    }
}
Exemple #14
0
void wyTMXTileMap::init(wyMapInfo* map, wyArray* textures) {
	// set anchor percent
	setAnchor(0.f, 0.f);

	// save info
	m_tileWidth = map->tileWidth;
	m_tileHeight = map->tileHeight;
	m_mapWidth = map->mapWidth;
	m_mapHeight = map->mapHeight;
    m_mapInfo = map;
    
    // check textures
    if(textures->num != map->tilesets->num)
        LOGE("wyTMXTileMap::init: tileset count is not same as texture count!");
    
    // append texture to tileset and set tileset size
    for(int i = 0; i < textures->num; i++) {
        wyTileSetInfo* tileset = (wyTileSetInfo*)wyArrayGet(map->tilesets, i);
        if(tileset) {
            tileset->texture = (wyTexture2D*)wyArrayGet(textures, i);
            tileset->texture->retain();
            tileset->imageWidth = tileset->texture->getPreciseWidth();
            tileset->imageHeight = tileset->texture->getPreciseHeight();
        }
    }

	// create tmx layer
	int idx = 0;
	for(int i = 0; i < map->layers->num; i++) {
        // create layer
		wyTMXLayer* layer = wyTMXLayer::make(idx, map);

		// check null
		if(layer == NULL)
			continue;

		// add
		addChildLocked(layer, idx, idx);
		idx++;

		// set my size
		setContentSize(MAX(layer->getWidth(), m_width),
				MAX(layer->getHeight(), m_height));
	}
}
Exemple #15
0
wyScrollableLayer::wyScrollableLayer(wyColor4B color) :
		wyColorLayer(color),
		m_vertical(false),
		m_horizontal(false),
		m_scrolling(false),
		m_flinging(false),
		m_childTouchCancelled(false),
		m_lastX(0),
		m_lastY(0),
		m_firstX(0),
		m_firstY(0),
		m_leftMargin(0),
		m_rightMargin(0),
		m_topMargin(0),
		m_bottomMargin(0),
		m_leftBorder(0),
		m_rightBorder(0),
		m_topBorder(0),
		m_bottomBorder(0),
		m_xExtent(0),
		m_yExtent(0),
		m_horizontalThumb(NULL),
		m_verticalThumb(NULL),
		m_fadeOutTime(0),
		m_noScrollTime(0),
		m_fadeingOut(false),
		m_callback(NULL),
#if ANDROID
		m_jCallback(NULL),
#endif
		m_scroller(WYNEW wyScroller()) {
	// enable event
	setTouchEnabled(true);
	setGestureEnabled(true);

	// create container
	m_container = wyScrollContainer::make();
	addChildLocked(m_container);

	// schedule fling timer
	wyTargetSelector* ts = wyTargetSelector::make(this, SEL(wyScrollableLayer::updateFling));
	wyTimer* timer = wyTimer::make(ts);
	scheduleLocked(timer);
}
void wyRadialCCWTransition::initScenes() {
	// make screenshot of out scene
	m_outTexture = wyRenderTexture::make();
	m_outTexture->beginRender();
	m_outScene->visit();
	m_outTexture->endRender();

	// create progress timer
	wyTexture2D* tex = m_outTexture->createTexture();
	m_progressTimer = wyProgressTimer::make(tex);
	m_progressTimer->setContentSize(wyDevice::winWidth, wyDevice::winHeight);
	m_progressTimer->setStyle(getRadialType());
	m_progressTimer->setPercentage(100);
	m_progressTimer->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight / 2);
	addChildLocked(m_progressTimer);

	// out scene is save in out texture, dont' need it
	m_outScene->setVisible(false);
}
Exemple #17
0
wyPageControl::wyPageControl() :
		m_pages(wyArrayNew(5)),
		m_container(NULL),
		m_lastX(0),
		m_lastY(0),
		m_scroller(WYNEW wyScroller()),
		m_flinging(false),
		m_scrolling(false),
		m_vertical(false),
		m_initialPageIndex(-1),
		m_indicator(NULL),
		m_data(NULL),
#if ANDROID
		m_jCallback(NULL),
#endif
		m_centerY(-1),
		m_centerX(-1) {
	// set page control properties
	setRelativeAnchorPoint(false);
	setContentSize(wyDevice::winWidth, wyDevice::winHeight);
	memset(&m_callback, 0, sizeof(wyPageControlCallback));

	// create container
	m_container = WYNEW wyLayer();
	m_container->setPosition(0, 0);
	addChildLocked(m_container);
	m_container->release();

	// enable events
	setTouchEnabled(true);
			
	// schedule fling timer
	wyTargetSelector* ts = wyTargetSelector::make(this, SEL(wyPageControl::updateFling));
	wyTimer* timer = wyTimer::make(ts);
	scheduleLocked(timer);
}
Exemple #18
0
        void setup() {
			m_Emitter = createParticleSystem();
			addChildLocked(m_Emitter);
			setEmitterPosition();
			setTouchEnabled(true);
        }
Exemple #19
0
wySlider::wySlider(wySprite* bg, wySprite* bar, wySprite* thumb, bool vertical) :
		m_min(0),
		m_max(100),
		m_value(0),
		m_vertical(vertical),
		m_data(NULL),
#if ANDROID
		m_jCallback(NULL),
#endif
		m_showFullBar(false),
		m_dragging(false) {
	// init callback
	memset(&m_callback, 0, sizeof(wySliderCallback));

	// assign
	m_bg = bg;
	m_progressTimer = wyProgressTimer::make(bar);
	m_thumb = thumb;

	// decide slider size
	int w = 0, h = 0;
	if(m_bg != NULL) {
		w = m_bg->getWidth();
		h = m_bg->getHeight();
	}
	w = MAX(w, m_progressTimer->getWidth());
	h = MAX(h, m_progressTimer->getHeight());
	if(m_thumb != NULL) {
		if(m_vertical) {
			w = MAX(w, thumb->getWidth());
			h = MAX(h, m_progressTimer->getHeight() + m_thumb->getHeight());
		} else {
			w = MAX(w, m_progressTimer->getWidth() + m_thumb->getWidth());
			h = MAX(h, thumb->getHeight());
		}
	}
	setContentSize(w, h);

	// add bg
	if(m_bg != NULL) {
		m_bg->setAnchor(0.5f, 0.5f);
		m_bg->setPosition(w / 2, h / 2);
		addChildLocked(m_bg);
	}

	// add timer
	m_progressTimer->setAnchor(0.5f, 0.5f);
	m_progressTimer->setPosition(w / 2, h / 2);
	m_progressTimer->setStyle(m_vertical ? VERTICAL_BAR_BT : HORIZONTAL_BAR_LR);
	addChildLocked(m_progressTimer);

	// add thumb
	if(m_thumb != NULL) {
		m_thumb->setAnchor(0.5f, 0.5f);
		if(m_vertical)
			m_thumb->setPosition(w / 2, h / 2 - m_progressTimer->getHeight() / 2);
		else
			m_thumb->setPosition(w / 2 - m_progressTimer->getWidth() / 2, h / 2);
		addChildLocked(m_thumb);
	}

	// enable touch default
	setTouchEnabled(true);
}
 wyEaseTestLayer(){
     m_Sprite = wySprite::make(wyTexture2D::makePNG(RES("R.drawable.grossini")));
     m_Sprite->retain();
     addChildLocked(m_Sprite);
     m_Sprite->setPosition(60, wyDevice::winHeight/ 2);
 };
Exemple #21
0
FirstScene::FirstScene() {    
    wyLabel* label = wyLabel::make("Welcome to WiEngine", SP(20), BOLD, WY_DEFAULT_FONT);
    label->setPosition(wyDevice::winWidth / 2, wyDevice::winHeight / 2);
    addChildLocked(label);
}