void TreeInspectorPreview::init(spActor item)
    {
        //_item = item;
        STDRenderer r(&_videoCache);
        RenderState rs;
        rs.renderer = &r;
        rs.transform = item->getTransform();
        r.begin(0);
        //r.setTransform(rs.transform);
        item->doRender(rs);
        r.end();
        r.drawBatch();

        setSize(30, 30);

        RectF itemRect = _videoCache._bounds;
        if (itemRect.isEmpty())
        {
            itemRect = item->getDestRect();
            if (itemRect.isEmpty())
                itemRect.setSize(Vector2(10, 4));
        }

        Vector2 ns = fitSize(Vector2(50.0f, 50.0f), itemRect.size);
        float scale = ns.x / itemRect.size.x;

        _cacheTransform.identity();

        _cacheTransform.scale(Vector2(scale, scale));
        _cacheTransform.translate(-itemRect.pos);



        AnimationFrame fr = _tree->_resSystem->getResAnim("checker")->getFrame(0, 0);
        //Point itemSize(30, 30);// = _getItemRect().size;

        RectF srcRect = fr.getSrcRect();
        const Diffuse& df = fr.getDiffuse();
        srcRect.size.x = ns.x / (float)df.base->getWidth();
        srcRect.size.y = ns.y / (float)df.base->getHeight();
        RectF destRect = fr.getDestRect();
        destRect.size = ns;

        AnimationFrame cfr;
        cfr.init(0, df, srcRect, destRect, ns);

        setAnimFrame(cfr);


        /*
        spEventHandler bh = new EventHandler();

        bh->setCallbackEnter(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        bh->setCallbackExit(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        bh->setCallbackPressDown(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        bh->setCallbackPressUp(CLOSURE(this, &TreeInspectorPreview::_onEvent));
        addEventHandler(bh);
        */
    }
Exemplo n.º 2
0
        void init()
        {
            _touchBlocker = new Actor;
            _touchBlocker->setName("Scene::_touchBlocker");
            _touchBlocker->setPosition(-10000, -10000);
            _touchBlocker->setSize(20000, 20000);
            _touchBlocker->setPriority(10000);
            _touchBlocker->setName("touchBlocker");

            Flow::instance.init();
        }
Exemplo n.º 3
0
			clickWait(spActor button, timeMS timeOut):_clicked(false), _timeOut(timeOut)
			{
				spClock clock = getStage()->getClock();
				timeMS start = clock->getTime();
				button->addEventListener(TouchEvent::CLICK, CLOSURE(this, &clickWait::click));
				do
				{
					yield();
					if (timeOut > 0 && (clock->getTime() - start > timeOut))					
						break;
				} while (!_clicked);

				button->removeEventListeners(this);
			}
Exemplo n.º 4
0
    float push(spActor s)
    {
        spActor last = _line->getLastChild();
        if (last)
            s->setY(last->getY() + getHeight());
        else
            s->setY(0.0f);

        s->setX(getWidth() / 2 - s->getWidth() / 2);

        _line->addChild(s);

        return last ? last->getHeight() : getHeight();
    }
Exemplo n.º 5
0
    void SlidingActor::setContent(spActor content)
    {
        if (_content)
        {
            _drag.destroy();
            _content->detach();
        }

        _downTime = 0;

        _current = 0;
        _lastIterTime = 0;
        _sliding = false;

        //_prev[0].pos = _content->getPosition();
        //_prev[0].tm = tm;

        for (int i = 0; i < NUM; ++i)
            _prev[i].tm = 0;

        _holded = 0; //event->target;
        //_downPos = te->localPosition;
        //_downTime = tm;
        _finger = 0;


        _speed = Vector2(0, 0);

        _content = content;
        _drag.init(content.get());

        _clip->addChild(_content);

        updateDragBounds();
    }
Exemplo n.º 6
0
	void getDescendants(spActor actor, std::vector<spActor> &actors)
	{
		actors.push_back(actor);
		spActor child = actor->getFirstChild();
		while (child)
		{
			getDescendants(child, actors);
			child = child->getNextSibling();
		}
		//actor->removeChildren();
	}
Exemplo n.º 7
0
	void ThreadLoading::start(spActor parent)
	{
		{
			MutexAutoLock k(_m);
			_threadDone = false;
		}		

		parent->addChild(this);
		pthread_create(&_thread, 0, _staticThreadFunc, this);
		//_thread = s3eThreadCreate(_staticThreadFunc, this);
	}
    void TreeInspectorLine::init(TreeInspectorPage* page, spActor item)
    {
        setSize(Vector2(0, 0));
        setCull(true);

        _page = page;
        _item = new TreeInspectorPreview(page->getTreeInspector());
        _item->init(item);
        addChild(_item);


        spTextField tb = new TextField();
        tb->setTouchEnabled(false);
        tb->setColor(Color::Black);

        const float minWidth = 300.0f;

        TextStyle style;
        style.font = _page->getTreeInspector()->_resSystem->getResFont("system")->getFont();
        style.multiline = true;
        style.vAlign = TextStyle::VALIGN_TOP;
        tb->setStyle(style);
        tb->setSize(Vector2(minWidth, 0.0f));



        std::string desc = item->dump(0);

        tb->setHtmlText(desc);
        Vector2 ts = tb->getTextRect().size.cast<Vector2>();
        if (ts.x < minWidth)
            ts.x = minWidth;

        tb->setSize(ts);


        tb->setX(50.0f + 5);

        addChild(tb);

        setSize(0, 0);
        setSize(TreeInspector::calcBounds(this).size);
    }
Exemplo n.º 9
0
    namespace flow
    {
        spActor _touchBlocker;

        Vector2 _blockedTouchPosition(0, 0);
        bool _wasTouchBlocked = false;
        bool _wasBackBlocked = false;


        Flow Flow::instance;




        void init()
        {
            _touchBlocker = new Actor;
            _touchBlocker->setName("Scene::_touchBlocker");
            _touchBlocker->setPosition(-10000, -10000);
            _touchBlocker->setSize(20000, 20000);
            _touchBlocker->setPriority(10000);
            _touchBlocker->setName("touchBlocker");

            Flow::instance.init();
        }

        void free()
        {
            _touchBlocker = 0;
            Flow::instance.free();
        }


        Flow::Flow()
        {
            _transition = false;
            _back = false;
        }

        void Flow::init()
        {
            spScene first = new Scene;
            first->_holder->attachTo(getStage());
            scenes.push_back(first);
        }

        void Flow::free()
        {
            _trans = 0;
            _current = 0;
            _next = 0;
            scenes.clear();
            scenes2show.clear();
        }

        void Flow::show(spScene scene, const resultCallback& cb)
        {
            auto p = std::find(scenes.begin(), scenes.end(), scene);
            if (p != scenes.end())
                log::error("you can't show scene '%s', it is already in the list", scene->getName().c_str());

            OX_ASSERT(p == scenes.end());
            scene->_resultCB = cb;
            scenes2show.push_back(scene);

            checkShow();
        }

        void Flow::blockedTouch(Event* ev)
        {
            TouchEvent* event = safeCast<TouchEvent*>(ev);
            _blockedTouchPosition = event->getPointer()->getPosition();
            _wasTouchBlocked = true;
        }

        void Flow::phaseBegin(spScene current, spScene next, bool back)
        {
            _back = back;
            _current = current;
            _next = next;

            _transition = true;


            if (next && !_back)
                next->entering();

            if (!_back || !current->_dialog)
                next->preShowing();

            if ((next->_dialog && _back) || !next->_dialog)
                current->preHiding();

            if (!back)
                current->sceneShown(next);

            _trans = next->runTransition(this, current, back);

            getStage()->addChild(_touchBlocker);
            _wasTouchBlocked = false;
            _wasBackBlocked = false;
            getStage()->addEventListener(TouchEvent::CLICK, CLOSURE(this, &Flow::blockedTouch));
        }

        void Flow::phaseEnd()
        {
            _transition = false;

            spScene current = _current;
            spScene next = _next;

            _current = 0;
            _next = 0;

            if ((next->_dialog && _back) || !next->_dialog)
            {
                current->_holder->detach();
                current->postHiding();
            }

            getStage()->insertChildBefore(_touchBlocker, next->getHolder());

            if (!_back || !current->_dialog)
                next->postShowing();

            if (_back)
                next->sceneHidden(current);

            getStage()->removeEventListener(TouchEvent::CLICK, CLOSURE(this, &Flow::blockedTouch));

            if (current->_done)
            {
                current->leaving();
                if (current->_resultCB)
                {
                    current->_resultCB(&current->_finishEvent);
                    current->_resultCB = resultCallback();
                }
            }

            if (current->_remove)
            {
                OX_ASSERT(next->_dialog == false);
                std::vector<spScene>::iterator i = std::find(scenes.begin(), scenes.end(), current);
                OX_ASSERT(i != scenes.end());
                scenes.erase(i);
            }


            if (_wasTouchBlocked)
            {
                log::messageln("send  blocked touch");
                TouchEvent click(TouchEvent::CLICK, true, _blockedTouchPosition);
                getStage()->handleEvent(&click);
                _wasTouchBlocked = false;
            }
        }

        void Flow::checkDone()
        {
            spScene current = scenes.back();
            if (current->_done)
            {
                scenes.pop_back();
                spScene prev = scenes.back();

                phaseBegin(current, prev, true);
            }
        }

        void Flow::checkShow()
        {
            if (scenes.back()->_done)
                return;

            if (_transition)
                return;


            spScene next = scenes2show.front();
            scenes2show.erase(scenes2show.begin());

            spScene current = scenes.back();

            if (current->_dialog)
            {
                OX_ASSERT(next->_dialog && "you can't show fullscreen scene on top of dialog");
                OX_ASSERT(!current->_remove && "you can't remove dialog from flow");
            }

            scenes.push_back(next);
            phaseBegin(current, next, false);

        }

        void Flow::update()
        {
            if (DebugActor::instance)
            {
                std::string str;
                for (size_t i = 1; i < scenes.size(); ++i)
                {
                    str += scenes[i]->getName();
                    str += "->";
                }
                if (!str.empty())
                {
                    str.pop_back();
                    str.pop_back();
                    str += "\n";
                    DebugActor::addDebugString(str.c_str());
                }
            }

            bool quit = checkQuit();
            static bool quitLast = false;
            if (quit && !quitLast)
            {
                _wasBackBlocked = true;
            }
            quitLast = quit;

            if (_transition)
            {
                if (_current->_transitionDone || (_trans && _trans->_done))
                    phaseEnd();

                return;
            }

            checkDone();
            if (!scenes2show.empty())
                checkShow();

            if (_transition)
                return;

            if (_wasBackBlocked && !scenes.empty())
            {
                _wasBackBlocked = false;
                spScene current = scenes.back();

                Event ev(Scene::EVENT_BACK);
                current->dispatchEvent(&ev);
                checkDone();
            }
        }

        void update()
        {
            Flow::instance.update();
        }

        void show(spScene s, const resultCallback& cb, Flow* f)
        {
            if (!f)
                f = &Flow::instance;

            f->show(s, cb);
        }
    }
Exemplo n.º 10
0
	void DeveloperMenu::init(const Vector2 &size, const char *text, spActor data, const Color &color)
	{
		const float BORDER = 3;

		float offset = 24;

		setSize(size);
		setWidth(data->getWidth() + BORDER * 2);
		setHeight(size.y + offset);
		//setSize(data->getSize() + Point(0, offset));

		spColorRectSprite top = new ColorRectSprite();
		top->setWidth(getWidth());
		top->setSize(size);


		_topDrag.init(top.get());
		_topDrag.setDragClient(this);
		
		addChild(top);

		

		top->setColor(windowColor);
		top->setSize(Vector2(getWidth(), offset));
		top->setPriority(100);

		spColorRectSprite body = new ColorRectSprite();
		body->setColor(color);
		addChild(body);

		

		body->setSize(Vector2(getWidth() - BORDER * 2, getHeight()));
		body->setX(BORDER);
		body->setY((float)offset);


		_body = body;	


		TextStyle style;
		style.font = _resSystem->getResFont("system")->getFont();
		style.vAlign = TextStyle::VALIGN_TOP;

		spButton close = initActor(new Button,
			arg_y = offset/2,
			arg_x = offset/2,
			arg_anchor = Vector2(0.5f, 0.5f),
			arg_resAnim = _resSystem->getResAnim("remove"),
			arg_attachTo = top);
		close->addEventListener(TouchEvent::CLICK, CLOSURE(this, &DeveloperMenu::close));


		spTextField title = initActor(new TextField,
			arg_style = style,
			arg_hAlign = TextStyle::HALIGN_MIDDLE,
			arg_vAlign = TextStyle::VALIGN_MIDDLE,
			arg_text = text,
			arg_width = top->getWidth(),
			arg_height = top->getHeight(),
			arg_input = false,
			arg_attachTo = top);

		//title->setSize(close->getTextRect().size);
		title->addEventListener(TouchEvent::CLICK, CLOSURE(this, &DeveloperMenu::close));

		data->attachTo(body);
	}
Exemplo n.º 11
0
	void TreeInspectorPage::init(spActor item)
	{
		OX_ASSERT(item);


		setSize(Vector2(0,0));
		_line = new TreeInspectorLine();
		_line->setPosition(Vector2(5, 5));
		_line->init(this, item);
		addChild(_line); 

		float y = _line->getHeight() + _line->getY() + 5.0f;

		if (item->getFirstChild())
		{
			spButton button;

			
			if (_parentPage)// && item->getFirstChild() != item->getLastChild())
			{
				button = new Button();
				button->setResAnim(_tree->_resSystem->getResAnim("checkbox"));
				button->setPosition(Vector2(15.0f, y));
				button->addEventListener(TouchEvent::CLICK, CLOSURE(this, &TreeInspectorPage::_onMinMaxClick));

				addChild(button);
			}

			_pages = new Actor();
			_pages->setInputEnabled(false);
			_pages->setX(-15);
			_pages->setY((float)y);


			spActor child = item->getFirstChild();
			while (child)
			{
				if (!child->isName("tree_inspector") && !child->isName("debug_actor"))
				{					
					spTreeInspectorPage page = new TreeInspectorPage(_tree, this);				
					page->init(child);
					_pages->addChild(page);
				}

				child = child->getNextSibling();
			}

			if (item->getVisible())
			{
				addChild(_pages);
				if (button)
					button->setRow(1);
			}
			else
			{
				if (button)
					button->setRow(0);
			}
		}

		updateInternalSize();
	}
Exemplo n.º 12
0
 void setActor(int n, spActor a)
 {
     _sprites[n] = a;
     a->setUserData((void*)n);
 }