示例#1
0
void CapturedString::draw() {

	string temp_str;
	if (getBorder()) {
		temp_str = (" " + getViewString() + " ");
	}
	else {
		temp_str = (getViewString());
	}

	//Draw centered at position
	Position pos = worldToView(getPosition());
	GraphicsManager &graphicsmanager = GraphicsManager::getInstance();
	graphicsmanager.drawString(pos, temp_str, CENTER_JUSTIFIED, getColor());

	if (getBorder()) {
		string top_border = "";
		char side_border = '|';
		for (int i = 0; i < temp_str.length(); i++) {
			top_border += "-";
		}
		Position bottom_pos = Position(pos.getX(), pos.getY() + 1);
		Position top_pos = Position(pos.getX(), pos.getY() - 1);
		Position left_border = Position(pos.getX() - temp_str.length()/2 - 1, pos.getY());
		Position right_border = Position(pos.getX() + temp_str.length()/2 + 1, pos.getY());
		graphicsmanager.drawString(top_pos, top_border, CENTER_JUSTIFIED, getColor());
		graphicsmanager.drawString(bottom_pos, top_border, CENTER_JUSTIFIED, getColor());
		graphicsmanager.drawCh(left_border, side_border, getColor());
		graphicsmanager.drawCh(right_border, side_border, getColor());

	}
}
示例#2
0
bool HSBackport::isBackportActive() {

	// Backport Detection
	cv::Rect bar(backPortDetectionX, backPortDetectionY, backPortDetectionW, backPortDetectionH);
	backPortMat = Mat4b(*getScreenshotMat(), bar);

	// ImageFilterMat::whiteToDarkPixel(backPortMat, 150);
	
	ImageFilterMat::saturation(backPortMat, 50, 255, 2);
	ImageFilterMat::colorReduce(backPortMat, 128);
	ImageFilterMat::killDarkPixel(backPortMat, 65);

	Vec3b borderColor1(64, 192, 192);
	Vec3b borderColor2(64, 64, 192);
	bool isBackporting = ImageFilterMat::hasPixelBorder(backPortMat, 1, 1, 1, 1, borderColor1, borderColor2);

	if (isBackporting) {
		cv::Rect barFill(getBorder()+2, getBorder()+1, backPortDetectionW - (getBorder()+1)*2, backPortDetectionH - (getBorder()+1)*2);
		backPortMeasureMat = Mat(backPortMat, barFill);
		backportFinishedReleaseFrames = 0;
	}
	
	return isBackporting;
	

}
	void CloudAtlasControlWindow::initWindow(osgWidget::WindowManager* wm, TemperatureProbeLayer* tLayer, WindowThemeSettings wts)
	{
		setZRange(1.0f);
		_obWM = wm;
		getBackground()->setColor(osgWidget::Color(0, 0, 0, 0));
		getBackground()->setEventMask(osgWidget::EVENT_NONE);
		_wts = wts;
		osgWidget::Table* centerTable = new osgWidget::Table("CenterTable", 2, 1);
		centerTable->getBackground()->setColor(osgWidget::Color(0, 0, 0, 0));
		_centerWidget = new CenterWidget("CloudAtlasCenterWidget", _windowWidth);
		float centerHeight = _centerWidget->buildCenterWidget(tLayer);
		osgWidget::point_type cw = wts._left;
		osgWidget::point_type ch = wts._bottom;
		osgWidget::point_type w = _windowWidth - cw - wts._right;
		osgWidget::point_type h = centerHeight + wts._topTitleHeight;
		osgWidget::Window::EmbeddedWindow* centerEW = new osgWidget::Window::EmbeddedWindow("CenterTableEmbedded", _windowWidth, h);
		centerEW->setCanFill(true);
		centerEW->setLayer(osgWidget::Widget::LAYER_MIDDLE);
		centerEW->setEventMask(osgWidget::EVENT_ALL);
		centerEW->setColor(1, 1, 1, 1);
		centerEW->setImage(wts._bgImage, true);
		addWidget(centerEW, 1, 1);

		osgWidget::Window::EmbeddedWindow* centerWidget = _centerWidget->embed("CenterEmbeddedWindow");
		centerWidget->setEventMask(osgWidget::EVENT_ALL);
		centerWidget->setColor(0, 0, 0, 0);
		centerTable->addWidget(centerWidget, 0, 0);
		_topTitleWidget = new VirtualDataSceneWidget::TopTitleWidget("TopTitle", _windowWidth, wts._topTitleHeight, wts._topTitleImage, wts._topCloseButtonImage);
		osgWidget::Window::EmbeddedWindow* topBorderWidget = _topTitleWidget->embed("TopTitleEmbedded");
		topBorderWidget->setColor(0, 0, 0, 0);
		topBorderWidget->setEventMask(osgWidget::EVENT_ALL);
		centerTable->addWidget(topBorderWidget, 1, 0);
		centerTable->resize(_windowWidth, h);
		setWindow(centerTable);

		//init left bottom right border and corner
		addWidget(new osgWidget::Frame::Corner(osgWidget::Frame::CORNER_LOWER_LEFT, cw, ch), 0, 0);
		addWidget(new osgWidget::Frame::Border(osgWidget::Frame::BORDER_BOTTOM, w, ch), 0, 1);
		addWidget(new osgWidget::Frame::Corner(osgWidget::Frame::CORNER_LOWER_RIGHT, cw, ch), 0, 2);
		addWidget(new osgWidget::Frame::Border(osgWidget::Frame::BORDER_LEFT, cw, h), 1, 0);
		addWidget(new osgWidget::Frame::Border(osgWidget::Frame::BORDER_RIGHT, cw, wts._right), 1, 2);
		addWidget(new osgWidget::Frame::Corner(osgWidget::Frame::CORNER_UPPER_LEFT, cw, wts._top), 2, 0);
		addWidget(new osgWidget::Frame::Border(osgWidget::Frame::BORDER_TOP, w, wts._top), 2, 1);
		addWidget(new osgWidget::Frame::Corner(osgWidget::Frame::CORNER_UPPER_RIGHT, cw, wts._top), 2, 2);

		getCorner(CORNER_UPPER_LEFT)->setImage(wts._leftTopImage, true);
		getBorder(BORDER_TOP)->setImage(wts._topImage, true);
		getCorner(CORNER_UPPER_RIGHT)->setImage(wts._rightTopImage, true);
		getBorder(BORDER_LEFT)->setImage(wts._leftImage, true);
		getBorder(BORDER_RIGHT)->setImage(wts._rightImage, true);
		getCorner(CORNER_LOWER_LEFT)->setImage(wts._leftBottomImage, true);
		getBorder(BORDER_BOTTOM)->setImage(wts._bottomImage, true);
		getCorner(CORNER_LOWER_RIGHT)->setImage(wts._rightBottomImage, true);

		_topTitleWidget->setCloseButtonClickCallback(&CloudAtlasControlWindow::closeButtonClicked, this);
		_topTitleWidget->setDragCallback(&CloudAtlasControlWindow::dragEventCallback, this);
		osgWidget::point_type allHeight = h + ch + wts._top;
		resize(_windowWidth, allHeight);
	}
void Component::getInsideBorderBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) const
{
    Real32 TopInset(0), LeftInset(0), BottomInset(0), RightInset(0);

    if(getBorder() != NULL)
    {
        //Get Border Insets
        getBorder()->getInsets(LeftInset,RightInset,TopInset,BottomInset);
    }
    TopLeft.setValues(LeftInset, TopInset);
    BottomRight.setValues(TopLeft.x()+getSize().x()-(LeftInset + RightInset), TopLeft.y()+getSize().y()-(TopInset + BottomInset));
}
示例#5
0
文件: Frame.cpp 项目: nusus/osg
bool Frame::resizeFrame(point_type w, point_type h) {
    Border* left   = getBorder(BORDER_LEFT);
    Border* right  = getBorder(BORDER_RIGHT);
    Border* top    = getBorder(BORDER_TOP);
    Border* bottom = getBorder(BORDER_BOTTOM);

    if(!left || !right || !top || !bottom) return false;

    return resize(
               left->getWidth() + right->getWidth() + w,
               top->getHeight() + bottom->getHeight() + h
           );
}
示例#6
0
void ViewObject::draw(){
	GraphicsManager &graphics_manager = GraphicsManager::getInstance();
	string temp_str;

	if(getBorder() == true){
		temp_str = " " + getViewString() + " " + intToString(value) + " ";
	} else {
		temp_str = getViewString() + " " + intToString(value);
	}

	//Draw centered at position
	Position pos = viewToWorld(getPosition());
	graphics_manager.drawString(pos, temp_str, CENTER_JUSTIFIED, getColor());

	//Draw box around display
	if (getBorder() == true){
		int boxLength = strlen(getViewString().c_str()) + 4;
		int boxHeight = 3;
		int boxOffset = boxLength/2;
		bool odd = false;

		if (boxLength % 2){
			odd = true;
		}

		for (int i = 0; i < boxLength; i++){
			Position new_pos(pos.getX() + i - boxOffset, pos.getY()-1);
			graphics_manager.drawCh(new_pos, '-', getColor());
		}

		//Bottom
		for (int i = 0; i < boxLength; i++){
			Position new_pos(pos.getX() + i - boxOffset, pos.getY()+1);
			graphics_manager.drawCh(new_pos, '-', getColor());
		}

		//Left
		Position left_pos(pos.getX()-boxOffset-1, pos.getY());
		graphics_manager.drawCh(left_pos, '|', getColor());

		//Right
		if (!odd){
			Position right_pos(pos.getX()+boxOffset, pos.getY());
			graphics_manager.drawCh(right_pos, '|', getColor());
		} else {
			Position right_pos(pos.getX()+boxOffset+1, pos.getY());
			graphics_manager.drawCh(right_pos, '|', getColor());
		}
	}
}
/*------------------------------------------------------------------------*/
int getCompoundBorder(void* _pvCtx, int _iVar, int* _piParent, int _iPos, int _iObjUID)
{
    SciErr sciErr;
    int* piAddrList = NULL;
    char* pstFieldList[] = {"CompoundBorder", "outer", "inner"};
    int iChildBorderOut = 0;
    int* piChildBorderOut = &iChildBorderOut;
    int iChildBorderIn = 0;
    int* piChildBorderIn = &iChildBorderIn;
    int iListSize = 3;

    getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_OUT_BORDER__, jni_int, (void **)&piChildBorderOut);
    getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_IN_BORDER__, jni_int, (void **)&piChildBorderIn);

    if (piChildBorderOut == NULL || piChildBorderIn == NULL)
    {
        iListSize = 1;
    }

    if (_piParent)
    {
        sciErr = createTListInList(_pvCtx, _iVar, _piParent, _iPos, iListSize, &piAddrList);
    }
    else
    {
        sciErr = createTList(_pvCtx, _iVar, iListSize, &piAddrList);
    }

    sciErr = createMatrixOfStringInList(_pvCtx, _iVar, piAddrList, 1, 1, iListSize, pstFieldList);
    if (sciErr.iErr)
    {
        return -1;
    }

    if (iListSize > 1)
    {
        //get child information and fill current list
        if (getBorder(_pvCtx, _iVar, piAddrList, 2, iChildBorderOut))
        {
            return -1;
        }

        if (getBorder(_pvCtx, _iVar, piAddrList, 3, iChildBorderIn))
        {
            return -1;
        }
    }

    return 0;
}
示例#8
0
void HydroFlowProducer::init(ptr<GraphProducer> graphs, ptr<TileCache> cache, int displayTileSize, float slipParameter, float searchRadiusFactor, float potentialDelta, int minLevel)
{
    TileProducer::init(cache, false);
    CurveDataFactory::init(graphs);
    this->displayTileSize = displayTileSize;
    this->slipParameter = slipParameter;
    this->graphs = graphs;
    this->searchRadiusFactor = searchRadiusFactor;
    this->potentialDelta = potentialDelta;
    this->minLevel = minLevel;

    float borderFactor = displayTileSize / (displayTileSize - 1.0f - 2.0f * getBorder()) - 1.0f;
    this->graphs->addMargin(new RiverMargin(displayTileSize - 2 * getBorder(), borderFactor));
    swHYDRODATA = new Timer();
}
void BMDSmartViewClient::printStateToSerial()	{
	for(uint8_t monId=0; monId<=1; monId++)	{
		Serial.print(F("Monitor "));
		Serial.println(monId==0?F("A:"):F("B:"));
		
		Serial.print(F("Brightness: "));
		Serial.println(getBrightness(monId));

		Serial.print(F("Contrast: "));
		Serial.println(getContrast(monId));

		Serial.print(F("Saturation: "));
		Serial.println(getSaturation(monId));

		Serial.print(F("Identify: "));
		Serial.println(getIdentify(monId));

		Serial.print(F("Border: "));
		Serial.println(getBorder(monId));

		Serial.print(F("WidescreenSD: "));
		Serial.println(getWidescreenSD(monId));

		Serial.print(F("ScopeMode: "));
		Serial.println(getScopeMode(monId));

		Serial.print(F("AudioChannel: "));
		Serial.println(getAudioChannel(monId));
		
		Serial.println();
	}
}
void RadioButton::updateBounds()
{
    Label::updateBounds();

    Vector2 size;
    if (_selected)
    {
        const Rectangle& selectedRegion = getImageRegion("selected", NORMAL);
        size.set(selectedRegion.width, selectedRegion.height);
    }
    else
    {
        const Rectangle& unselectedRegion = getImageRegion("unselected", NORMAL);
        size.set(unselectedRegion.width, unselectedRegion.height);
    }

    if (_autoSize & AUTO_SIZE_HEIGHT)
    {
        // Text-only width was already measured in Label::update - append image
        const Theme::Border& border = getBorder(NORMAL);
        const Theme::Border& padding = getPadding();
        setHeightInternal(std::max(_bounds.height, size.y + border.top + border.bottom + padding.top + padding.bottom));
    }

    if (_autoSize & AUTO_SIZE_WIDTH)
    {
        // Text-only width was already measured in Label::update - append image
        setWidthInternal(_bounds.height + 5 + _bounds.width);
    }
}
示例#11
0
void PopupWindow::onPreferredSize(PreferredSizeEvent& ev)
{
    ScreenGraphics g;
    g.setFont(getFont());
    Size resultSize(0, 0);

    if (hasText())
        resultSize = g.fitString(getText(),
                                 (getClientBounds() - getBorder()).w,
                                 getAlign());

    resultSize.w += border_width.l + border_width.r;
    resultSize.h += border_width.t + border_width.b;

    if (!getChildren().empty()) {
        Size maxSize(0, 0);
        Size reqSize;

        UI_FOREACH_WIDGET(getChildren(), it) {
            Widget* child = *it;

            reqSize = child->getPreferredSize();

            maxSize.w = MAX(maxSize.w, reqSize.w);
            maxSize.h = MAX(maxSize.h, reqSize.h);
        }
示例#12
0
Border* AbstractWindow::getDrawnBorder(void) const
{
    if(getDrawDecorations())
    {
        if(getEnabled())
        {
            if(getFocused())
            {
                return getFocusedBorder();
            }
            else if(_MouseInComponentLastMouse)
            {
                return getRolloverBorder();
            }
            else
            {
                return getBorder();
            }
        }
        else
        {
            return getDisabledBorder();
        }
    }
    else
    {
        return NULL;
    }
}
示例#13
0
void ViewObject::setLocation(ViewObjectLocation new_location)
{
	auto& worldMgr = WorldManager::getInstance();
	int delta = 0;
	Position p;
	// Set new position based on location.
	if (!getBorder())
	{
		delta = -1;
	}

	switch (new_location)
	{
	case TOP_LEFT:
		p.setXY(worldMgr.getView().getHorizontal() * 1 / 6, 1);
		break;
	case TOP_CENTER:
		p.setXY(worldMgr.getView().getHorizontal() * 3 / 6, 1);
		break;
	case TOP_RIGHT:
		p.setXY(worldMgr.getView().getHorizontal() * 6 / 6, 1);
		break;

	case CENTER_CENTER:
		p.setXY(worldMgr.getView().getHorizontal() * 3 / 6,
			worldMgr.getView().getVertical() * 3 / 6);
		break;
	}

	// Shift, as needed, based on border.
	p.setY(p.getY() + delta);
	// Set position of object to new position.
	setPosition(p);
}
示例#14
0
Border* Button::getDrawnBorder(void) const
{
    if(getEnabled())
    {
        //if(getFocused())
        //{
        //    return getFocusedTextColor();
        //}
        if(getActive())
        {
            return getActiveBorder();
        }
        else if(_MouseInComponentLastMouse)
        {
            return getRolloverBorder();
        }
        else
        {
            return getBorder();
        }
    }
    else
    {
        return getDisabledBorder();
    }
}
示例#15
0
void Slider::updateValue(int x, int y)
{
    State state = getState();

    // Horizontal case.
    const Theme::Border& border = getBorder(state);
    const Theme::Padding& padding = getPadding();
    const Rectangle& minCapRegion = _minImage->getRegion();
    const Rectangle& maxCapRegion = _maxImage->getRegion();
    const Rectangle& markerRegion = _markerImage->getRegion();

    float markerPosition = (x - markerRegion.width * 0.5f) / (_viewportBounds.width - markerRegion.width);
            
    if (markerPosition > 1.0f)
    {
        markerPosition = 1.0f;
    }
    else if (markerPosition < 0.0f)
    {
        markerPosition = 0.0f;
    }

    float value = (markerPosition * (_max - _min)) + _min;
    if (_step > 0.0f)
    {            
        int numSteps = round(value / _step);
        value = _step * numSteps;
    }

    setValue(value);
}
/*------------------------------------------------------------------------*/
void* getCompoundBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
{
    const wchar_t * pstFieldList[] = {L"CompoundBorder", L"outer", L"inner"};
    int iListSize           = 3;

    // properties
    int iChildBorderOut     = 0;
    int* piChildBorderOut   = &iChildBorderOut;
    int iChildBorderIn      = 0;
    int* piChildBorderIn    = &iChildBorderIn;

    getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_OUT_BORDER__, jni_int, (void **)&piChildBorderOut);
    getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_IN_BORDER__, jni_int, (void **)&piChildBorderIn);

    if (piChildBorderOut == NULL || piChildBorderIn == NULL)
    {
        iListSize = 1;
    }

    types::TList* pTL   = new types::TList();
    types::String* pStr = new types::String(1, iListSize, pstFieldList);

    pTL->append(pStr);

    if (iListSize > 1)
    {
        //get child information and fill current list
        if (getBorder(pTL, 2, iChildBorderOut) == NULL)
        {
            return NULL;
        }

        if (getBorder(pTL, 3, iChildBorderIn) == NULL)
        {
            return NULL;
        }
    }

    if (_pITParent)
    {
        types::List* pL = _pITParent->getAs<types::List>();
        pL->set(_iPos - 1, pTL);
    }

    return pTL;
}
    void* get_border_property(void* _pvCtx, int iObjUID)
    {
        int iBorder   = 0;
        int* piBorder = &iBorder;

        getGraphicObjectProperty(iObjUID, __GO_UI_FRAME_BORDER__, jni_int, (void **)&piBorder);
        if (piBorder == NULL)
        {
            Scierror(999, _("'%s' property does not exist for this handle.\n"), "border");
            return NULL;
        }

        return getBorder(NULL, 0, iBorder);
    }
示例#18
0
void ViewObject::setLocation(ViewObjectLocation location){
	WorldManager &world_manager = WorldManager::getInstance();
	Position pos = getPosition();
	int delta = 0;

	switch(location){
	case TOP_LEFT:
		pos.setXY(world_manager.getView().getHorizontal() * 1/6, 1);
		if (getBorder() == false){
			delta = -1;
		}
		break;
	case TOP_CENTER:
		pos.setXY(world_manager.getView().getHorizontal() * 3/6, 1);
		if (getBorder() == false){
			delta = -1;
		}
		break;
	case TOP_RIGHT:
		pos.setXY(world_manager.getView().getHorizontal() * 5/6, 1);
		if(getBorder() == false){
			delta = -1;
		}
		break;
	case BOTTOM_LEFT:
		pos.setXY(world_manager.getView().getHorizontal() * 1/6, world_manager.getView().getVertical()-1);
		if (getBorder() == false){
			delta = 1;
		}
		break;
	case BOTTOM_CENTER:
		pos.setXY(world_manager.getView().getHorizontal() * 3/6, world_manager.getView().getVertical()-1);
		if (getBorder() == false){
			delta = 1;
		}
		break;
	case BOTTOM_RIGHT:
		pos.setXY(world_manager.getView().getHorizontal() * 5/6, world_manager.getView().getVertical()-1);
		if(getBorder() == false){
			delta = 1;
		}
		break;
	}

	pos.setY(pos.getY() + delta);
	setPosition(pos);
}
示例#19
0
Border* Component::getDrawnBorder(void) const
{
    if(getEnabled())
    {
        if(getMouseOver())
        {
            return getRolloverBorder();
        }
        else if(getFocused())
        {
            return getFocusedBorder();
        }
        else
        {
            return getBorder();
        }
    }
    else
    {
        return getDisabledBorder();
    }
}
示例#20
0
void KotORWidget::load(const Aurora::GFFStruct &gff) {
	gff.getVector("COLOR", _r, _g, _b);
	_a = gff.getDouble("ALPHA", 1.0);

	Extend extend = getExtend(gff);

	_width  = extend.w;
	_height = extend.h;

	Widget::setPosition(extend.x, extend.y, 0.0);

	Border border = getBorder(gff);

	_quad = new Graphics::Aurora::GUIQuad(border.fill, 0.0, 0.0, extend.w, extend.h);
	_quad->setPosition(extend.x, extend.y, 0.0);
	_quad->setTag(getTag());
	_quad->setClickable(true);

	if (border.fill.empty())
		_quad->setColor(0.0, 0.0, 0.0, 0.0);

	Text text = getText(gff);

	if (!text.text.empty() && !text.font.empty()) {
		_text = new Graphics::Aurora::Text(FontMan.get(text.font), text.text,
		                                   text.r, text.g, text.b, 1.0);

		const float hspan = extend.w - _text->getWidth();
		const float vspan = extend.h - _text->getHeight();

		const float x = extend.x + text.halign * hspan;
		const float y = extend.y + text.valign * vspan;

		_text->setPosition(x, y, -1.0);
		_text->setTag(getTag());
		_text->setClickable(true);
	}
}
示例#21
0
void RadioButton::updateBounds()
{
    Label::updateBounds();

    const Rectangle& region = _image ? _image->getRegion() : Rectangle(0, 0);
    Vector2 size(region.width, region.height);

    size *= _iconScale;

    if (_autoSize & AUTO_SIZE_HEIGHT)
    {
        // Text-only width was already measured in Label::update - append image
        const Theme::Border& border = getBorder(NORMAL);
        const Theme::Border& padding = getPadding();
        setHeightInternal(std::max(size.y, _bounds.height) + border.top + border.bottom + padding.top + padding.bottom);
    }

    if ((_autoSize & AUTO_SIZE_WIDTH) != 0 && _font)
    {
        // Text-only width was already measured in Label::update - append image
        setWidthInternal(size.x + 5 + _bounds.width);
    }
}
示例#22
0
void Label::updateBounds()
{
    if (_autoSize != AUTO_SIZE_NONE && _font)
    {
        // Measure bounds based only on normal state so that bounds updates are not always required on state changes.
        // This is a trade-off for functionality vs performance, but changing the size of UI controls on hover/focus/etc
        // is a pretty bad practice so we'll prioritize performance here.
        if (_autoSize & AUTO_SIZE_WIDTH)
        {
            float w, h;
            _font->measureText(_text.c_str(), getFontSize(NORMAL), getTextDrawingFlags(NORMAL), &w, &h, getCharacterSpacing(NORMAL), getLineSpacing(NORMAL));
            setWidthInternal(ceilf(w + getBorder(NORMAL).left + getBorder(NORMAL).right + getPadding().left + getPadding().right));
            if (_autoSize & AUTO_SIZE_HEIGHT)
                setHeightInternal(ceilf(h + getBorder(NORMAL).top + getBorder(NORMAL).bottom + getPadding().top + getPadding().bottom));
        }
        else // _autoSize & AUTO_SIZE_HEIGHT
        {
            GP_ASSERT(_autoSize & AUTO_SIZE_HEIGHT);

            // recalculate height due to word wrapping
            float h = getFontSize(NORMAL);
            if (_textBounds.width > 0.0f)
            {
                gameplay::Rectangle clipBounds(_textBounds.width, FLT_MAX);
                gameplay::Rectangle out;
                _font->measureText(_text.c_str(), clipBounds, getFontSize(NORMAL), getTextDrawingFlags(NORMAL), &out, getTextAlignment(NORMAL), 
                    true, true, getCharacterSpacing(NORMAL), getLineSpacing(NORMAL));

                h = out.height;
            }

            setHeightInternal(ceilf(h + getBorder(NORMAL).top + getBorder(NORMAL).bottom + getPadding().top + getPadding().bottom));
        }
    }

    Control::updateBounds();
}
示例#23
0
void Ground::makeHole(b2Vec2 epicenter, float radius)
{
	std::list<b2Vec2>::iterator first,second, firstToDel, lastToDel, circleStart, circleEnd, itr, leftCircleBorder, rightCircleBorder;
	b2Vec2 leftBorder, rightBorder;
	bool leftFound(false), rightFound(false);

	//find left border
	first = this->edges.begin();
	for (second=++(this->edges.begin()); second!=this->edges.end(); first++,second++)
	{
		if (distance(*second, epicenter) <= radius)
		{
			leftBorder = (*first);
			circleStart = first;
			leftFound = true;
			firstToDel = second;
			break;
		}
	}

	//find right border
	first = --(this->edges.end());
	for (second= --(--this->edges.end()); second!=this->edges.begin(); first--,second--)
	{
		if (distance(*second, epicenter) <= radius)
		{
			rightBorder = (*first);
			circleEnd = first;
			rightFound = true;
			lastToDel = second;
			break;
		}
	}

	if ( !(leftFound && rightFound) )
		return;

	leftBorder = getBorder(*circleStart, *firstToDel, epicenter, radius);
	leftCircleBorder = circleStart;
	leftCircleBorder++;
	this->edges.insert(leftCircleBorder,leftBorder);
	leftCircleBorder--;
	

	rightBorder = getBorder(*circleEnd, *lastToDel, epicenter, radius);
	rightCircleBorder = circleEnd;
	this->edges.insert(rightCircleBorder,rightBorder);
	rightCircleBorder--;

	this->edges.erase(firstToDel, ++lastToDel);

	b2Vec2 aVec(leftBorder.x-epicenter.x, leftBorder.y-epicenter.y), bVec(rightBorder.x-epicenter.x, rightBorder.y-epicenter.y);
	positiveAngle ab = getPositiveAngle(aVec,bVec);

	positiveAngle step = 1/57.296;

	b2Vec2 toInsert = rotateVec(aVec, step);
	positiveAngle rotated(step);
	for (itr = ++leftCircleBorder; rotated < ab; rotated+=step)
	{
		this->edges.insert(itr,epicenter + toInsert);
		toInsert = rotateVec(toInsert,step);
	}
}
示例#24
0
文件: Form.cpp 项目: 5guo/GamePlay
void Form::updateBounds()
{   
    _clearBounds.set(_absoluteClipBounds);

    // Calculate the clipped bounds.
    float x = 0;
    float y = 0;
    float width = _bounds.width;
    float height = _bounds.height;

    Rectangle clip(0, 0, _bounds.width, _bounds.height);

    float clipX2 = clip.x + clip.width;
    float x2 = clip.x + x + width;
    if (x2 > clipX2)
        width -= x2 - clipX2;

    float clipY2 = clip.y + clip.height;
    float y2 = clip.y + y + height;
    if (y2 > clipY2)
        height -= y2 - clipY2;

    if (x < 0)
    {
        width += x;
        x = -x;
    }
    else
    {
        x = 0;
    }

    if (y < 0)
    {
        height += y;
        y = -y;
    }
    else
    {
        y = 0;
    }

    _clipBounds.set(x, y, width, height);

    // Calculate the absolute bounds.
    x = 0;
    y = 0;
    _absoluteBounds.set(x, y, _bounds.width, _bounds.height);

    // Calculate the absolute viewport bounds. Absolute bounds minus border and padding.
    const Theme::Border& border = getBorder(_state);
    const Theme::Padding& padding = getPadding();

    x += border.left + padding.left;
    y += border.top + padding.top;
    width = _bounds.width - border.left - padding.left - border.right - padding.right;
    height = _bounds.height - border.top - padding.top - border.bottom - padding.bottom;

    _viewportBounds.set(x, y, width, height);

    // Calculate the clip area. Absolute bounds, minus border and padding, clipped to the parent container's clip area.
    clipX2 = clip.x + clip.width;
    x2 = x + width;
    if (x2 > clipX2)
        width = clipX2 - x;

    clipY2 = clip.y + clip.height;
    y2 = y + height;
    if (y2 > clipY2)
        height = clipY2 - y;

    if (x < clip.x)
    {
        float dx = clip.x - x;
        width -= dx;
        x = clip.x;
    }

    if (y < clip.y)
    {
        float dy = clip.y - y;
        height -= dy;
        y = clip.y;
    }
 
    _viewportClipBounds.set(x, y, width, height);
    _absoluteClipBounds.set(x - border.left - padding.left, y - border.top - padding.top,
                            width + border.left + padding.left + border.right + padding.right,
                            height + border.top + padding.top + border.bottom + padding.bottom);
    if (_clearBounds.isEmpty())
    {
        _clearBounds.set(_absoluteClipBounds);
    }

    // Get scrollbar images and diminish clipping bounds to make room for scrollbars.
    if ((_scroll & SCROLL_HORIZONTAL) == SCROLL_HORIZONTAL)
    {
        _scrollBarLeftCap = getImage("scrollBarLeftCap", _state);
        _scrollBarHorizontal = getImage("horizontalScrollBar", _state);
        _scrollBarRightCap = getImage("scrollBarRightCap", _state);

        _viewportClipBounds.height -= _scrollBarHorizontal->getRegion().height;
    }

    if ((_scroll & SCROLL_VERTICAL) == SCROLL_VERTICAL)
    {
        _scrollBarTopCap = getImage("scrollBarTopCap", _state);
        _scrollBarVertical = getImage("verticalScrollBar", _state);
        _scrollBarBottomCap = getImage("scrollBarBottomCap", _state);
        
        _viewportClipBounds.width -= _scrollBarVertical->getRegion().width;
    }
}
示例#25
0
void InternalWindow::changed(ConstFieldMaskArg whichField, 
                             UInt32            origin,
                             BitVector         details)
{
    if( ((whichField & FocusedFieldMask) ||
         (whichField & TitlebarFieldMask))&&
         getTitlebar() != NULL &&
         getDrawTitlebar() &&
         !getTitlebar()->getEnabled())
    {
        getTitlebar()->setEnabled(getFocused());
    }

    if( (whichField & ActiveToolTipFieldMask) &&
        getActiveToolTip() != NULL)
    {
        getActiveToolTip()->updateClipBounds();
    }

    if( (whichField & ActivePopupMenusFieldMask) &&
        getMFActivePopupMenus()->size() > 0)
    {
        _PopupConnections.clear();
        for(UInt32 i(0) ; i<getMFActivePopupMenus()->size() ; ++i)
        {
            getActivePopupMenus(i)->setParentWindow(this);
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseClicked(boost::bind(&InternalWindow::popupMenuMousePressed, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMousePressed(boost::bind(&InternalWindow::popupMenuMousePressed, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseReleased(boost::bind(&InternalWindow::popupMenuMouseReleased, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectKeyPressed(boost::bind(&InternalWindow::popupMenuKeyPressed, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseMoved(boost::bind(&InternalWindow::popupMenuMouseMoved, this, _1)))));
            _PopupConnections[getActivePopupMenus(i)].push_back(boost::shared_ptr<boost::signals2::scoped_connection>(new boost::signals2::scoped_connection(getParentDrawingSurface()->getEventProducer()->connectMouseDragged(boost::bind(&InternalWindow::popupMenuMouseDragged, this, _1)))));
        }
        setLockInput(true);
    }

    if( (whichField & MenuBarFieldMask) && getMenuBar() != NULL)
    {
        getMenuBar()->setParentWindow(this);
    }

    if( (whichField & MenuBarFieldMask) || (whichField & TitlebarFieldMask))
    {
        updateLayout();
    }

    if( (whichField & TitleFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setTitle(getTitle());
    }

    if( (whichField & TitlebarFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setParentWindow(this);
    }

    if((whichField & TitlebarFieldMask) ||
       (whichField & BorderFieldMask) ||
       (whichField & DisabledBorderFieldMask) ||
       (whichField & FocusedBorderFieldMask) ||
       (whichField & RolloverBorderFieldMask) ||
       (whichField & DrawTitlebarFieldMask))
    {
        TitlebarRefPtr TheTitlebar;
        if(getDrawTitlebar())
        {
            TheTitlebar = getTitlebar();
        }
        else
        {
            TheTitlebar = NULL;
        }

        if(getBorder() != NULL && getBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getBorder())->setTitlebar(TheTitlebar);
        }
        if(getDisabledBorder() != NULL && getDisabledBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getDisabledBorder())->setTitlebar(TheTitlebar);
        }
        if(getFocusedBorder() != NULL && getFocusedBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getFocusedBorder())->setTitlebar(TheTitlebar);
        }
        if(getRolloverBorder() != NULL && getRolloverBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getRolloverBorder())->setTitlebar(TheTitlebar);
        }
    }

    if( whichField & ClipBoundsFieldMask)
    {
        if(getTitlebar() != NULL)
        {
            getTitlebar()->updateClipBounds();
        }
    }

    if( (whichField & TitlebarFieldMask) &&
        getTitlebar() != NULL)
    {
        if(getTitlebar()->getTitleLabel() != NULL)
        {
            _TitleBarMousePressedConnection = getTitlebar()->getTitleLabel()->connectMousePressed(boost::bind(&InternalWindow::titlebarMousePressed, this, _1));
        }
        if(getTitlebar()->getCloseButton() != NULL)
        {
            _CloseButtonActionConnection = getTitlebar()->getCloseButton()->connectActionPerformed(boost::bind(&InternalWindow::closeButtonAction, this, _1));
        }
        if(getTitlebar()->getMaximizeButton() != NULL)
        {
            _MaximizeButtonActionConnection = getTitlebar()->getMaximizeButton()->connectActionPerformed(boost::bind(&InternalWindow::maximizeButtonAction, this, _1));
        }
        if(getTitlebar()->getIconifyButton() != NULL)
        {
            _IconifyButtonActionConnection = getTitlebar()->getIconifyButton()->connectActionPerformed(boost::bind(&InternalWindow::iconifyButtonAction, this, _1));
        }
    }

    if( (whichField & IconableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawIconify(getIconable());
    }
    if( (whichField & MaximizableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawMaximize(getMaximizable());
    }
    if( (whichField & ClosableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawClose(getClosable());
    }

    Inherited::changed(whichField, origin, details);
}
示例#26
0
bool Slider::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    if (!isEnabled())
    {
        return false;
    }

    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        if (_contactIndex != INVALID_CONTACT_INDEX)
            return false;
        _state = Control::ACTIVE;
        _originalX = x;
        _originalValue = _value;
        _originalConsumeInputEvents = _consumeInputEvents;
        _moveCancelled = false;
        
        // Fall through to calculate new value.
    case Touch::TOUCH_MOVE:
    
        if (evt != Touch::TOUCH_PRESS && _contactIndex != (int)contactIndex)
            return false;

        if (_moveCancelled)
        {
            break;
        }
        else if (abs(x - _originalX) > SLIDER_THRESHOLD)
        {
            // Start consuming input events once we've passed the slider's threshold.
            _consumeInputEvents = true;
        }
        else if (_parent->isScrolling())
        {
            // Cancel the change in slider value if we pass the parent container's scrolling threshold.
            float oldValue = _value;
            _value = _originalValue;
            if (_value != oldValue)
            {
                notifyListeners(Listener::VALUE_CHANGED);
            }

            _dirty = true;
            _moveCancelled = true;
            _state = NORMAL;
            _contactIndex = INVALID_CONTACT_INDEX;
            _consumeInputEvents = _originalConsumeInputEvents;
            break;
        }

        if (_state == ACTIVE &&
            x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
            y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
        {
            // Horizontal case.
            const Theme::Border& border = getBorder(_state);
            const Theme::Padding& padding = getPadding();
            const Rectangle& minCapRegion = _minImage->getRegion();
            const Rectangle& maxCapRegion = _maxImage->getRegion();

            float markerPosition = ((float)x - maxCapRegion.width - border.left - padding.left) /
                (_bounds.width - border.left - border.right - padding.left - padding.right - minCapRegion.width - maxCapRegion.width);
            
            if (markerPosition > 1.0f)
            {
                markerPosition = 1.0f;
            }
            else if (markerPosition < 0.0f)
            {
                markerPosition = 0.0f;
            }

            float oldValue = _value;
            _value = (markerPosition * (_max - _min)) + _min;
            if (_step > 0.0f)
            {
                float stepDistance = _step / (_max - _min);
            
                int numSteps = round(_value / _step);
                _value = _step * numSteps;
            }

            // Call the callback if our value changed.
            if (_value != oldValue)
            {
                notifyListeners(Listener::VALUE_CHANGED);
            }

            _dirty = true;
        }
        break;
    case Touch::TOUCH_RELEASE:
        _consumeInputEvents = _originalConsumeInputEvents;

        if (_contactIndex != (int) contactIndex)
            return false;

        _dirty = true;
        _state = FOCUS;
        break;
    }
    
    if (evt == Touch::TOUCH_MOVE)
        return _consumeInputEvents;
    else
        return Control::touchEvent(evt, x, y, contactIndex);
}
示例#27
0
static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
  /** START_GENERATED **/
  css_flex_direction_t mainAxis = getFlexDirection(node);
  css_flex_direction_t crossAxis = mainAxis == CSS_FLEX_DIRECTION_ROW ?
    CSS_FLEX_DIRECTION_COLUMN :
    CSS_FLEX_DIRECTION_ROW;

  // Handle width and height style attributes
  setDimensionFromStyle(node, mainAxis);
  setDimensionFromStyle(node, crossAxis);

  // The position is set by the parent, but we need to complete it with a
  // delta composed of the margin and left/top/right/bottom
  node->layout.position[leading[mainAxis]] += getMargin(node, leading[mainAxis]) +
    getRelativePosition(node, mainAxis);
  node->layout.position[leading[crossAxis]] += getMargin(node, leading[crossAxis]) +
    getRelativePosition(node, crossAxis);

  if (isMeasureDefined(node)) {
    float width = CSS_UNDEFINED;
    if (isDimDefined(node, CSS_FLEX_DIRECTION_ROW)) {
      width = node->style.dimensions[CSS_WIDTH];
    } else if (!isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_ROW]])) {
      width = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_ROW]];
    } else {
      width = parentMaxWidth -
        getMarginAxis(node, CSS_FLEX_DIRECTION_ROW);
    }
    width -= getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_ROW);

    // We only need to give a dimension for the text if we haven't got any
    // for it computed yet. It can either be from the style attribute or because
    // the element is flexible.
    bool isRowUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_ROW) &&
      isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_ROW]]);
    bool isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) &&
      isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]);

    // Let's not measure the text if we already know both dimensions
    if (isRowUndefined || isColumnUndefined) {
      css_dim_t measure_dim = node->measure(
        node->context,
        width
      );
      if (isRowUndefined) {
        node->layout.dimensions[CSS_WIDTH] = measure_dim.dimensions[CSS_WIDTH] +
          getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_ROW);
      }
      if (isColumnUndefined) {
        node->layout.dimensions[CSS_HEIGHT] = measure_dim.dimensions[CSS_HEIGHT] +
          getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
      }
    }
    return;
  }

  // Pre-fill some dimensions straight from the parent
  for (int i = 0; i < node->children_count; ++i) {
    css_node_t* child = node->get_child(node->context, i);
    // Pre-fill cross axis dimensions when the child is using stretch before
    // we call the recursive layout pass
    if (getAlignItem(node, child) == CSS_ALIGN_STRETCH &&
        getPositionType(child) == CSS_POSITION_RELATIVE &&
        !isUndefined(node->layout.dimensions[dim[crossAxis]]) &&
        !isDimDefined(child, crossAxis)) {
      child->layout.dimensions[dim[crossAxis]] = fmaxf(
        node->layout.dimensions[dim[crossAxis]] -
          getPaddingAndBorderAxis(node, crossAxis) -
          getMarginAxis(child, crossAxis),
        // You never want to go smaller than padding
        getPaddingAndBorderAxis(child, crossAxis)
      );
    } else if (getPositionType(child) == CSS_POSITION_ABSOLUTE) {
      // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
      // left and right or top and bottom).
      for (int ii = 0; ii < 2; ii++) {
        css_flex_direction_t axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
        if (!isUndefined(node->layout.dimensions[dim[axis]]) &&
            !isDimDefined(child, axis) &&
            isPosDefined(child, leading[axis]) &&
            isPosDefined(child, trailing[axis])) {
          child->layout.dimensions[dim[axis]] = fmaxf(
            node->layout.dimensions[dim[axis]] -
            getPaddingAndBorderAxis(node, axis) -
            getMarginAxis(child, axis) -
            getPosition(child, leading[axis]) -
            getPosition(child, trailing[axis]),
            // You never want to go smaller than padding
            getPaddingAndBorderAxis(child, axis)
          );
        }
      }
    }
  }

  float definedMainDim = CSS_UNDEFINED;
  if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) {
    definedMainDim = node->layout.dimensions[dim[mainAxis]] -
        getPaddingAndBorderAxis(node, mainAxis);
  }

  // We want to execute the next two loops one per line with flex-wrap
  int startLine = 0;
  int endLine = 0;
  int nextLine = 0;
  // We aggregate the total dimensions of the container in those two variables
  float linesCrossDim = 0;
  float linesMainDim = 0;
  while (endLine != node->children_count) {
    // <Loop A> Layout non flexible children and count children by type

    // mainContentDim is accumulation of the dimensions and margin of all the
    // non flexible children. This will be used in order to either set the
    // dimensions of the node if none already exist, or to compute the
    // remaining space left for the flexible children.
    float mainContentDim = 0;

    // There are three kind of children, non flexible, flexible and absolute.
    // We need to know how many there are in order to distribute the space.
    int flexibleChildrenCount = 0;
    float totalFlexible = 0;
    int nonFlexibleChildrenCount = 0;
    for (int i = startLine; i < node->children_count; ++i) {
      css_node_t* child = node->get_child(node->context, i);
      float nextContentDim = 0;

      // It only makes sense to consider a child flexible if we have a computed
      // dimension for the node->
      if (!isUndefined(node->layout.dimensions[dim[mainAxis]]) && isFlex(child)) {
        flexibleChildrenCount++;
        totalFlexible += getFlex(child);

        // Even if we don't know its exact size yet, we already know the padding,
        // border and margin. We'll use this partial information to compute the
        // remaining space.
        nextContentDim = getPaddingAndBorderAxis(child, mainAxis) +
          getMarginAxis(child, mainAxis);

      } else {
        float maxWidth = CSS_UNDEFINED;
        if (mainAxis == CSS_FLEX_DIRECTION_ROW) {
          // do nothing
        } else if (isDimDefined(node, CSS_FLEX_DIRECTION_ROW)) {
          maxWidth = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] -
            getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_ROW);
        } else {
          maxWidth = parentMaxWidth -
            getMarginAxis(node, CSS_FLEX_DIRECTION_ROW) -
            getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_ROW);
        }

        // This is the main recursive call. We layout non flexible children.
        if (nextLine == 0) {
          layoutNode(child, maxWidth);
        }

        // Absolute positioned elements do not take part of the layout, so we
        // don't use them to compute mainContentDim
        if (getPositionType(child) == CSS_POSITION_RELATIVE) {
          nonFlexibleChildrenCount++;
          // At this point we know the final size and margin of the element.
          nextContentDim = getDimWithMargin(child, mainAxis);
        }
      }

      // The element we are about to add would make us go to the next line
      if (isFlexWrap(node) &&
          !isUndefined(node->layout.dimensions[dim[mainAxis]]) &&
          mainContentDim + nextContentDim > definedMainDim) {
        nextLine = i + 1;
        break;
      }
      nextLine = 0;
      mainContentDim += nextContentDim;
      endLine = i + 1;
    }

    // <Loop B> Layout flexible children and allocate empty space

    // In order to position the elements in the main axis, we have two
    // controls. The space between the beginning and the first element
    // and the space between each two elements.
    float leadingMainDim = 0;
    float betweenMainDim = 0;

    // The remaining available space that needs to be allocated
    float remainingMainDim = 0;
    if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) {
      remainingMainDim = definedMainDim - mainContentDim;
    } else {
      remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;
    }

    // If there are flexible children in the mix, they are going to fill the
    // remaining space
    if (flexibleChildrenCount != 0) {
      float flexibleMainDim = remainingMainDim / totalFlexible;

      // The non flexible children can overflow the container, in this case
      // we should just assume that there is no space available.
      if (flexibleMainDim < 0) {
        flexibleMainDim = 0;
      }
      // We iterate over the full array and only apply the action on flexible
      // children. This is faster than actually allocating a new array that
      // contains only flexible children.
      for (int i = startLine; i < endLine; ++i) {
        css_node_t* child = node->get_child(node->context, i);
        if (isFlex(child)) {
          // At this point we know the final size of the element in the main
          // dimension
          child->layout.dimensions[dim[mainAxis]] = flexibleMainDim * getFlex(child) +
            getPaddingAndBorderAxis(child, mainAxis);

          float maxWidth = CSS_UNDEFINED;
          if (mainAxis == CSS_FLEX_DIRECTION_ROW) {
            // do nothing
          } else if (isDimDefined(node, CSS_FLEX_DIRECTION_ROW)) {
            maxWidth = node->layout.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] -
              getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_ROW);
          } else {
            maxWidth = parentMaxWidth -
              getMarginAxis(node, CSS_FLEX_DIRECTION_ROW) -
              getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_ROW);
          }

          // And we recursively call the layout algorithm for this child
          layoutNode(child, maxWidth);
        }
      }

    // We use justifyContent to figure out how to allocate the remaining
    // space available
    } else {
      css_justify_t justifyContent = getJustifyContent(node);
      if (justifyContent == CSS_JUSTIFY_FLEX_START) {
        // Do nothing
      } else if (justifyContent == CSS_JUSTIFY_CENTER) {
        leadingMainDim = remainingMainDim / 2;
      } else if (justifyContent == CSS_JUSTIFY_FLEX_END) {
        leadingMainDim = remainingMainDim;
      } else if (justifyContent == CSS_JUSTIFY_SPACE_BETWEEN) {
        remainingMainDim = fmaxf(remainingMainDim, 0);
        if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) {
          betweenMainDim = remainingMainDim /
            (flexibleChildrenCount + nonFlexibleChildrenCount - 1);
        } else {
          betweenMainDim = 0;
        }
      } else if (justifyContent == CSS_JUSTIFY_SPACE_AROUND) {
        // Space on the edges is half of the space between elements
        betweenMainDim = remainingMainDim /
          (flexibleChildrenCount + nonFlexibleChildrenCount);
        leadingMainDim = betweenMainDim / 2;
      }
    }

    // <Loop C> Position elements in the main axis and compute dimensions

    // At this point, all the children have their dimensions set. We need to
    // find their position. In order to do that, we accumulate data in
    // variables that are also useful to compute the total dimensions of the
    // container!
    float crossDim = 0;
    float mainDim = leadingMainDim +
      getPaddingAndBorder(node, leading[mainAxis]);

    for (int i = startLine; i < endLine; ++i) {
      css_node_t* child = node->get_child(node->context, i);

      if (getPositionType(child) == CSS_POSITION_ABSOLUTE &&
          isPosDefined(child, leading[mainAxis])) {
        // In case the child is position absolute and has left/top being
        // defined, we override the position to whatever the user said
        // (and margin/border).
        child->layout.position[pos[mainAxis]] = getPosition(child, leading[mainAxis]) +
          getBorder(node, leading[mainAxis]) +
          getMargin(child, leading[mainAxis]);
      } else {
        // If the child is position absolute (without top/left) or relative,
        // we put it at the current accumulated offset.
        child->layout.position[pos[mainAxis]] += mainDim;
      }

      // Now that we placed the element, we need to update the variables
      // We only need to do that for relative elements. Absolute elements
      // do not take part in that phase.
      if (getPositionType(child) == CSS_POSITION_RELATIVE) {
        // The main dimension is the sum of all the elements dimension plus
        // the spacing.
        mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);
        // The cross dimension is the max of the elements dimension since there
        // can only be one element in that cross dimension.
        crossDim = fmaxf(crossDim, getDimWithMargin(child, crossAxis));
      }
    }

    float containerMainAxis = node->layout.dimensions[dim[mainAxis]];
    // If the user didn't specify a width or height, and it has not been set
    // by the container, then we set it via the children.
    if (isUndefined(node->layout.dimensions[dim[mainAxis]])) {
      containerMainAxis = fmaxf(
        // We're missing the last padding at this point to get the final
        // dimension
        mainDim + getPaddingAndBorder(node, trailing[mainAxis]),
        // We can never assign a width smaller than the padding and borders
        getPaddingAndBorderAxis(node, mainAxis)
      );
    }

    float containerCrossAxis = node->layout.dimensions[dim[crossAxis]];
    if (isUndefined(node->layout.dimensions[dim[crossAxis]])) {
      containerCrossAxis = fmaxf(
        // For the cross dim, we add both sides at the end because the value
        // is aggregate via a max function. Intermediate negative values
        // can mess this computation otherwise
        crossDim + getPaddingAndBorderAxis(node, crossAxis),
        getPaddingAndBorderAxis(node, crossAxis)
      );
    }

    // <Loop D> Position elements in the cross axis

    for (int i = startLine; i < endLine; ++i) {
      css_node_t* child = node->get_child(node->context, i);

      if (getPositionType(child) == CSS_POSITION_ABSOLUTE &&
          isPosDefined(child, leading[crossAxis])) {
        // In case the child is absolutely positionned and has a
        // top/left/bottom/right being set, we override all the previously
        // computed positions to set it correctly.
        child->layout.position[pos[crossAxis]] = getPosition(child, leading[crossAxis]) +
          getBorder(node, leading[crossAxis]) +
          getMargin(child, leading[crossAxis]);

      } else {
        float leadingCrossDim = getPaddingAndBorder(node, leading[crossAxis]);

        // For a relative children, we're either using alignItems (parent) or
        // alignSelf (child) in order to determine the position in the cross axis
        if (getPositionType(child) == CSS_POSITION_RELATIVE) {
          css_align_t alignItem = getAlignItem(node, child);
          if (alignItem == CSS_ALIGN_FLEX_START) {
            // Do nothing
          } else if (alignItem == CSS_ALIGN_STRETCH) {
            // You can only stretch if the dimension has not already been set
            // previously.
            if (!isDimDefined(child, crossAxis)) {
              child->layout.dimensions[dim[crossAxis]] = fmaxf(
                containerCrossAxis -
                  getPaddingAndBorderAxis(node, crossAxis) -
                  getMarginAxis(child, crossAxis),
                // You never want to go smaller than padding
                getPaddingAndBorderAxis(child, crossAxis)
              );
            }
          } else {
            // The remaining space between the parent dimensions+padding and child
            // dimensions+margin.
            float remainingCrossDim = containerCrossAxis -
              getPaddingAndBorderAxis(node, crossAxis) -
              getDimWithMargin(child, crossAxis);

            if (alignItem == CSS_ALIGN_CENTER) {
              leadingCrossDim += remainingCrossDim / 2;
            } else { // CSS_ALIGN_FLEX_END
              leadingCrossDim += remainingCrossDim;
            }
          }
        }

        // And we apply the position
        child->layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
      }
    }

    linesCrossDim += crossDim;
    linesMainDim = fmaxf(linesMainDim, mainDim);
    startLine = endLine;
  }

  // If the user didn't specify a width or height, and it has not been set
  // by the container, then we set it via the children.
  if (isUndefined(node->layout.dimensions[dim[mainAxis]])) {
    node->layout.dimensions[dim[mainAxis]] = fmaxf(
      // We're missing the last padding at this point to get the final
      // dimension
      linesMainDim + getPaddingAndBorder(node, trailing[mainAxis]),
      // We can never assign a width smaller than the padding and borders
      getPaddingAndBorderAxis(node, mainAxis)
    );
  }

  if (isUndefined(node->layout.dimensions[dim[crossAxis]])) {
    node->layout.dimensions[dim[crossAxis]] = fmaxf(
      // For the cross dim, we add both sides at the end because the value
      // is aggregate via a max function. Intermediate negative values
      // can mess this computation otherwise
      linesCrossDim + getPaddingAndBorderAxis(node, crossAxis),
      getPaddingAndBorderAxis(node, crossAxis)
    );
  }

  // <Loop E> Calculate dimensions for absolutely positioned elements

  for (int i = 0; i < node->children_count; ++i) {
    css_node_t* child = node->get_child(node->context, i);
    if (getPositionType(child) == CSS_POSITION_ABSOLUTE) {
      // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
      // left and right or top and bottom).
      for (int ii = 0; ii < 2; ii++) {
        css_flex_direction_t axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
        if (!isUndefined(node->layout.dimensions[dim[axis]]) &&
            !isDimDefined(child, axis) &&
            isPosDefined(child, leading[axis]) &&
            isPosDefined(child, trailing[axis])) {
          child->layout.dimensions[dim[axis]] = fmaxf(
            node->layout.dimensions[dim[axis]] -
            getPaddingAndBorderAxis(node, axis) -
            getMarginAxis(child, axis) -
            getPosition(child, leading[axis]) -
            getPosition(child, trailing[axis]),
            // You never want to go smaller than padding
            getPaddingAndBorderAxis(child, axis)
          );
        }
      }
      for (int ii = 0; ii < 2; ii++) {
        css_flex_direction_t axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
        if (isPosDefined(child, trailing[axis]) &&
            !isPosDefined(child, leading[axis])) {
          child->layout.position[leading[axis]] =
            node->layout.dimensions[dim[axis]] -
            child->layout.dimensions[dim[axis]] -
            getPosition(child, trailing[axis]);
        }
      }
    }
  }
  /** END_GENERATED **/
}
示例#28
0
static float getPaddingAndBorder(css_node_t *node, int location) {
  return getPadding(node, location) + getBorder(node, location);
}
void InternalWindow::changed(ConstFieldMaskArg whichField, 
                             UInt32            origin,
                             BitVector         details)
{
    if( ((whichField & FocusedFieldMask) ||
         (whichField & TitlebarFieldMask))&&
        getTitlebar() != NULL)
    {
        getTitlebar()->setEnabled(getFocused());
    }

    if( (whichField & ActiveToolTipFieldMask) &&
        getActiveToolTip() != NULL)
    {
        getActiveToolTip()->updateClipBounds();
    }

    if( (whichField & ActivePopupMenusFieldMask) &&
        getMFActivePopupMenus()->size() > 0)
    {
        for(UInt32 i(0) ; i<getMFActivePopupMenus()->size() ; ++i)
        {
            getActivePopupMenus(i)->setParentContainer(this);
            getActivePopupMenus(i)->setParentWindow(this);
        }

        getDrawingSurface()->getEventProducer()->addMouseListener(&_PopupMenuInteractionListener);
        getDrawingSurface()->getEventProducer()->addMouseMotionListener(&_PopupMenuInteractionListener);
        getDrawingSurface()->getEventProducer()->addKeyListener(&_PopupMenuInteractionListener);
        setLockInput(true);
    }

    if( (whichField & MenuBarFieldMask) && getMenuBar() != NULL)
    {
        getMenuBar()->setParentContainer(this);
        getMenuBar()->setParentWindow(this);
    }

    if( (whichField & MenuBarFieldMask) || (whichField & TitlebarFieldMask))
    {
        updateLayout();
    }

    if( (whichField & TitleFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setTitle(getTitle());
    }

    if( (whichField & TitlebarFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setParentContainer(this);
        getTitlebar()->setParentWindow(this);
    }

    if((whichField & TitlebarFieldMask) ||
       (whichField & BorderFieldMask) ||
       (whichField & DisabledBorderFieldMask) ||
       (whichField & FocusedBorderFieldMask) ||
       (whichField & RolloverBorderFieldMask) ||
       (whichField & DrawTitlebarFieldMask))
    {
        TitlebarRefPtr TheTitlebar;
        if(getDrawTitlebar())
        {
            TheTitlebar = getTitlebar();
        }
        else
        {
            TheTitlebar = NULL;
        }

        if(getBorder() != NULL && getBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getBorder())->setTitlebar(TheTitlebar);
        }
        if(getDisabledBorder() != NULL && getDisabledBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getDisabledBorder())->setTitlebar(TheTitlebar);
        }
        if(getFocusedBorder() != NULL && getFocusedBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getFocusedBorder())->setTitlebar(TheTitlebar);
        }
        if(getRolloverBorder() != NULL && getRolloverBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getRolloverBorder())->setTitlebar(TheTitlebar);
        }
    }

    if( whichField & ClipBoundsFieldMask)
    {
        if(getTitlebar() != NULL)
        {
            getTitlebar()->updateClipBounds();
        }
    }

    if( (whichField & TitlebarFieldMask) &&
        getTitlebar() != NULL)
    {
        if(getTitlebar()->getTitleLabel() != NULL)
        {
            getTitlebar()->getTitleLabel()->addMouseListener(&_TitlebarStartDragListener);
        }
        if(getTitlebar()->getCloseButton() != NULL)
        {
            getTitlebar()->getCloseButton()->addActionListener(&_CloseButtonListener);
        }
        if(getTitlebar()->getMaximizeButton() != NULL)
        {
            getTitlebar()->getMaximizeButton()->addActionListener(&_MaximizeButtonListener);
        }
        if(getTitlebar()->getIconifyButton() != NULL)
        {
            getTitlebar()->getIconifyButton()->addActionListener(&_IconifyButtonListener);
        }
    }

    if( (whichField & IconableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawIconify(getIconable());
    }
    if( (whichField & MaximizableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawMaximize(getMaximizable());
    }
    if( (whichField & ClosableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawClose(getClosable());
    }

    Inherited::changed(whichField, origin, details);
}
示例#30
0
static float getBorderAxis(css_node_t *node, css_flex_direction_t axis) {
  return getBorder(node, leading[axis]) + getBorder(node, trailing[axis]);
}