/******************************************************************************
* Updates the text of the connected text box after the spinner's value has changed.
******************************************************************************/
void SpinnerWidget::updateTextBox()
{
	if(textBox()) {
		if(unit())
			_originalText = unit()->formatValue(unit()->nativeToUser(floatValue()));
		else
			_originalText = QString::number(floatValue());
		textBox()->setText(_originalText);
	}
}
void KoOdtFrameReportTextBox::createBody(KoXmlWriter *bodyWriter) const
{
    bodyWriter->startElement("draw:frame");
    bodyWriter->addAttribute("draw:id", itemName());
    bodyWriter->addAttribute("xml:id", itemName());
    bodyWriter->addAttribute("draw:name", itemName());
    bodyWriter->addAttribute("text:anchor-type", "page");
    bodyWriter->addAttribute("text:anchor-page-number", pageNumber());
    bodyWriter->addAttribute("draw:style-name", m_frameStyleName);

    commonAttributes(bodyWriter);

    bodyWriter->startElement("draw:text-box");

    bodyWriter->startElement("text:p");
    bodyWriter->addAttribute("text:style-name", m_paragraphStyleName);
    bodyWriter->startElement("text:span");
    bodyWriter->addAttribute("text:style-name", m_textStyleName);
    bodyWriter->addTextNode(textBox()->text());

    bodyWriter->endElement(); // text:span
    bodyWriter->endElement(); // text:p
    bodyWriter->endElement(); // draw:text-box
    bodyWriter->endElement(); // draw:frame
}
Beispiel #3
0
ListBox::ListBox(int x, int y, const Color &textColor, const std::vector<std::string> &elements,
	const Font &font, int maxDisplayed, Renderer &renderer)
	: textColor(textColor), point(x, y), font(font)
{
	assert(maxDisplayed > 0);

	this->scrollIndex = 0;

	// Make text boxes for getting list box dimensions now and drawing later.
	// It's okay for there to be zero elements. Just be blank, then!
	for (const auto &element : elements)
	{
		// Remove any new lines.
		std::string trimmedElement = String::trimLines(element);

		// Store the text box for later.
		std::unique_ptr<TextBox> textBox(new TextBox(0, 0, textColor, 
			trimmedElement, font, TextAlignment::Left, renderer));
		this->textBoxes.push_back(std::move(textBox));
	}

	// Calculate the dimensions of the displayed list box area.
	const int width = [this]()
	{
		int maxWidth = 0;
		for (const auto &textBox : this->textBoxes)
		{
			int textBoxWidth;
			SDL_QueryTexture(textBox->getTexture(), nullptr, nullptr, &textBoxWidth, nullptr);

			if (textBoxWidth > maxWidth)
			{
				maxWidth = textBoxWidth;
			}
		}

		return maxWidth;
	}();

	const int height = font.getCharacterHeight() * maxDisplayed;

	// Create the clear surface. This exists because the text box surfaces can't
	// currently have an arbitrary size (otherwise they could extend to the end of 
	// each row), and because SDL_UpdateTexture requires pixels (so this avoids an 
	// allocation each time the update method is called).
	this->clearSurface = Surface::createSurfaceWithFormat(width, height,
		Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT);
	SDL_FillRect(this->clearSurface, nullptr, 
		SDL_MapRGBA(clearSurface->format, 0, 0, 0, 0));

	// Create the visible texture. This will be updated when scrolling the list box.
	this->texture = renderer.createTexture(Renderer::DEFAULT_PIXELFORMAT,
		SDL_TEXTUREACCESS_STREAMING, width, height);
	SDL_SetTextureBlendMode(this->texture, SDL_BLENDMODE_BLEND);

	// Draw the text boxes to the texture.
	this->updateDisplay();
}
void KoOdtFrameReportTextBox::createStyle(KoGenStyles *coll)
{
    QFont font = textBox()->textStyle().font;

    KoGenStyle ps(KoGenStyle::ParagraphStyle, "paragraph");
    m_paragraphStyleName = coll->insert(ps, "P");

    // text style
    KoGenStyle ts(KoGenStyle::TextStyle, "text");
    ts.addProperty("fo:font-family", font.family());
    ts.addPropertyPt("fo:font-size", font.pointSizeF());
    ts.addProperty("fo:font-weight", font.weight() * 10);
    ts.addProperty("fo:color", textBox()->textStyle().foregroundColor.name());
    QString fs;
    switch (font.style()) {
        case QFont::StyleNormal: fs = "normal"; break;
        case QFont::StyleItalic: fs = "italic"; break;
        case QFont::StyleOblique: fs = "oblique"; break;
    }
    ts.addProperty("fo:font-style", fs);
    m_textStyleName = coll->insert(ts, "T");

    KoGenStyle gs(KoGenStyle::GraphicStyle, "graphic");
    QPen pen;
    pen.setColor(textBox()->lineStyle().lineColor);
    pen.setWidthF(textBox()->lineStyle().weight);
    pen.setStyle(textBox()->lineStyle().style);
    KoOdfGraphicStyles::saveOdfStrokeStyle(gs, coll, pen);
    gs.addProperty("style:horizontal-pos", "from-left");
    gs.addProperty("style:horizontal-rel", "page");
    gs.addProperty("style:vertical-pos", "from-top");
    gs.addProperty("style:vertical-rel", "page");
    gs.addProperty("fo:background-color", textBox()->textStyle().backgroundColor.name());
    m_frameStyleName = coll->insert(gs, "F");
}
/******************************************************************************
* Connects this spinner with the given textbox control.
******************************************************************************/
void SpinnerWidget::setTextBox(QLineEdit* box)
{
	if(box == textBox()) return;
	if(_textBox.isNull() == false) {
		disconnect(_textBox.data(), &QLineEdit::editingFinished, this, &SpinnerWidget::onTextChanged);
	}
	_textBox = box;
	if(_textBox.isNull() == false) {
		connect(box, &QLineEdit::editingFinished, this, &SpinnerWidget::onTextChanged);
		box->setEnabled(isEnabled());
		updateTextBox();
	}
}
/******************************************************************************
* Will be called when the user has entered a new text into the text box.
* The text will be parsed and taken as the new value of the spinner.
******************************************************************************/
void SpinnerWidget::onTextChanged()
{
	OVITO_CHECK_POINTER(textBox());
    
	FloatType newValue;
	try {
		if(textBox()->text() == _originalText) return;
		if(unit()) {
			newValue = unit()->parseString(textBox()->text());
			setFloatValue(unit()->userToNative(newValue), true);
		}
		else {
			bool ok;
			newValue = textBox()->text().toDouble(&ok);
			if(!ok)
				throw Exception(tr("Invalid floating-point value: %1").arg(textBox()->text()));
			setFloatValue(newValue, true);
		}
	}
	catch(const Exception&) {
		// Ignore invalid value and restore old text content.
		updateTextBox();
	}	
}
Beispiel #7
0
void VcardForm::addHtmlField( const char *ns1, const char *ns2, const char *description, int flags ) {
    std::string value;
    if (vcard) {
        JabberDataBlockRef vcardTemp=vcard->findChildNamespace("vCard", "vcard-temp");      
        if (vcardTemp) {
            JabberDataBlockRef field=vcardTemp->getChildByName(ns1);     
            if (field) {
                if (ns2) field=field->getChildByName(ns2);
            }
            if (field) value=XMLStringPrep(field->getText());
        }
    }

    if (!editForm) if (value.length()==0) return;

    std::string name(ns1);
    if (ns2) {
        name+="#";
        name+=ns2;
    }
    const std::wstring wname=utf8::utf8_wchar(name);

    if (editForm) {
        if (flags==TXT) flags=TEXTBOX;
        if (flags==URL) flags=TEXTBOX;
    } else {
        if (flags==MULTILINE) flags=TXT;
    }

    if (flags & TEXTBOX) {
        textBox(name.c_str(), std::string(description), value);
        return;
    }
    if (flags & MULTILINE) {
        textML(name.c_str(), std::string(description), value);
        return;
    }

    if (flags & URL)   {
        url(std::string(description), value);
        return;
    }

    if (!editForm) if (value.length()==0) return;

    textConst(std::string(description), value);
}
Beispiel #8
0
void Button::Draw(std::weak_ptr<Camera> camera){
	Rectf pos = mPhysics->Box();
	if (!mUiElement && !camera.expired()){
		pos = Math::FromSceneSpace(camera, pos);
    }
	//Apply appropriate clip for button's state
	Recti clip;
	if (!mClicked)
		clip = mImage.Clip(0);
	else
		clip = mImage.Clip(1);
	Window::Draw(&mImage, pos, &clip);

	//Draw the text
    Recti textBox((pos.pos.x + pos.w / 2) - mText.W() / 2, (pos.pos.y + pos.h  / 2) - mText.H() / 2,
        mText.W(), mText.H());
	Window::Draw(&mText, textBox);
}
NS_IMETHODIMP nsXULTextFieldAccessible::GetValue(nsAString& aValue)
{
  PRUint32 state;
  nsresult rv = GetStateInternal(&state, nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  if (state & nsIAccessibleStates::STATE_PROTECTED)    // Don't return password text!
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDOMXULTextBoxElement> textBox(do_QueryInterface(mContent));
  if (textBox) {
    return textBox->GetValue(aValue);
  }
  nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
  if (menuList) {
    return menuList->GetLabel(aValue);
  }
  return NS_ERROR_FAILURE;
}
void SizePreview::paintEvent( QPaintEvent * )
{
  int displayedWidth, displayedHeight;

  // Figure the width and height of the displayed page. Tricky.
  if (orientation == 0) {
    displayedWidth  = (int)(height() * (_width/_height) + 0.5);
    displayedHeight = (int)(width() * (_height/_width) + 0.5);
  } else {
    displayedHeight  = (int)(height() * (_width/_height) + 0.5);
    displayedWidth = (int)(width() * (_height/_width) + 0.5);
  }
  if (displayedWidth <= width()) 
    displayedHeight = height();
  else
    displayedWidth = width();

  int hOffset = (width()-displayedWidth)/2;
  int vOffset = (height()-displayedHeight)/2;


  // Now draw the graphics
  pixmap.resize(width(), height());

  QPainter p(&pixmap);
  p.fillRect(rect(), colorGroup().background());
  p.setPen(Qt::black);
  p.setBrush(Qt::white);
  p.drawRect(hOffset, vOffset, displayedWidth, displayedHeight);

  // mark the textbox; we assume 25mm margin
  int margin = (int)(25.0*displayedWidth/_width + 0.5);
  QRect textBox(hOffset+margin, vOffset+margin, displayedWidth-2*margin, displayedHeight-2*margin);
  p.setPen(Qt::lightGray);
  p.drawRect(textBox);

  // Draw some dummy "text", represented by black lines
  int lineSpacing    = (int)(7.0*displayedWidth/_width + 0.5); // equiv. 7 mm
  if (lineSpacing <= 3)
    lineSpacing = 3;
  int interWordSpace = (int)(4.0*displayedWidth/_width + 0.5); // equiv. 4 mm
  if (interWordSpace <= 1)
    interWordSpace = 2;

  KRandomSequence rnd(1); // to generate word widths

  p.setClipRect(textBox);
  p.setPen(Qt::black);
  int count = 1; // Counts lines
  for (int y = vOffset+margin+lineSpacing; y <= vOffset+displayedHeight-margin; y += lineSpacing) {
    // We start each line with its own seed.
    // This means that the random sequence for each line is always the same, and this
    // results in a more steady picture when the widget is resized.
    rnd.setSeed(count);

    // Every 10th line the end of a paragraph
    int endParagraph;
    if (count++ % 10 == 0)
      endParagraph = (int)(50.0*displayedWidth/_width + 0.5);
    else
      endParagraph = 0;
    for(int x = hOffset+margin; x <= hOffset+displayedWidth-margin-endParagraph; ) {
      double wordWidthMM = rnd.getDouble()*30.0+10.0;
      int wordWidth = (int)(wordWidthMM*displayedWidth/_width + 0.5); 
      p.drawLine(x, y, x+wordWidth, y);
      x += wordWidth+interWordSpace+1;
    }
  }

  p.end();

  // Copy the pixmap onto the widget
  bitBlt(this, rect().topLeft(), &pixmap, rect(), CopyROP);
  return;
}
void PlaylistItemDelegate::paintBody( QPainter* painter,
                                      const QStyleOptionViewItem& option,
                                      const QModelIndex& index ) const {
    painter->save();
    painter->translate( option.rect.topLeft() );

    QRect line(0, 0, option.rect.width(), option.rect.height());
    if (downloadInfo) line.setWidth(line.width() / 2);

    const bool isActive = index.data( ActiveTrackRole ).toBool();
    const bool isSelected = option.state & QStyle::State_Selected;

    // draw the "current track" highlight underneath the text
    if (isActive && !isSelected)
        paintActiveOverlay(painter, line);

    // get the video metadata
    const VideoPointer videoPointer = index.data( VideoRole ).value<VideoPointer>();
    const Video *video = videoPointer.data();

    // thumb
    painter->drawPixmap(0, 0, video->thumbnail());

    // play icon overlayed on the thumb
    if (isActive)
        painter->drawPixmap(playIcon.rect(), playIcon);

    // time
    if (video->duration() > 0)
        drawTime(painter, video->formattedDuration(), line);

    // separator
    painter->setPen(option.palette.color(QPalette::Midlight));
    painter->drawLine(THUMB_WIDTH, THUMB_HEIGHT, option.rect.width(), THUMB_HEIGHT);
    if (!video->thumbnail().isNull())
        painter->setPen(Qt::black);
    painter->drawLine(0, THUMB_HEIGHT, THUMB_WIDTH-1, THUMB_HEIGHT);

    if (line.width() > THUMB_WIDTH + 60) {

        // if (isActive) painter->setFont(boldFont);

        // text color
        if (isSelected)
            painter->setPen(QPen(option.palette.highlightedText(), 0));
        else
            painter->setPen(QPen(option.palette.text(), 0));

        // title
        QString videoTitle = video->title();
        QString v = videoTitle;
        const int flags = Qt::AlignTop | Qt::TextWordWrap;
        QRect textBox = line.adjusted(PADDING+THUMB_WIDTH, PADDING, 0, 0);
        textBox = painter->boundingRect(textBox, flags, v);
        while (textBox.height() > 55 && v.length() > 10) {
            videoTitle.truncate(videoTitle.length() - 1);
            v = videoTitle;
            v = v.trimmed().append("...");
            textBox = painter->boundingRect(textBox, flags, v);
        }
        painter->drawText(textBox, flags, v);

        painter->setFont(smallerFont);

        // published date
        QString publishedString = video->published().date().toString(Qt::DefaultLocaleShortDate);
        QSize stringSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, publishedString ) );
        QPoint textLoc(PADDING+THUMB_WIDTH, PADDING*2 + textBox.height());
        QRect publishedTextBox(textLoc , stringSize);
        painter->drawText(publishedTextBox, Qt::AlignLeft | Qt::AlignTop, publishedString);

        if (line.width() > publishedTextBox.x() + publishedTextBox.width()*2) {

            // author
            bool authorHovered = false;
            bool authorPressed = false;
            const bool isHovered = index.data(HoveredItemRole).toBool();
            if (isHovered) {
                authorHovered = index.data(AuthorHoveredRole).toBool();
                authorPressed = index.data(AuthorPressedRole).toBool();
            }

            painter->save();
            painter->setFont(smallerBoldFont);
            if (!isSelected) {
                if (authorHovered)
                    painter->setPen(QPen(option.palette.brush(QPalette::Highlight), 0));
                else
                    painter->setOpacity(.5);
            }
            QString authorString = video->channelTitle();
            textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
            stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, authorString ) );
            QRect authorTextBox(textLoc , stringSize);
            authorRects.insert(index.row(), authorTextBox);
            painter->drawText(authorTextBox, Qt::AlignLeft | Qt::AlignTop, authorString);
            painter->restore();

            if (line.width() > authorTextBox.x() + 50) {

                // view count
                if (video->viewCount() >= 0) {
                    QLocale locale;
                    QString viewCountString = tr("%1 views").arg(locale.toString(video->viewCount()));
                    textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
                    stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, viewCountString ) );
                    QRect viewCountTextBox(textLoc , stringSize);
                    painter->drawText(viewCountTextBox, Qt::AlignLeft | Qt::AlignBottom, viewCountString);
                }

                if (downloadInfo) {
                    const QString definitionString = VideoDefinition::getDefinitionFor(video->getDefinitionCode()).getName();
                    textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
                    stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, definitionString ) );
                    QRect viewCountTextBox(textLoc , stringSize);
                    painter->drawText(viewCountTextBox, Qt::AlignLeft | Qt::AlignBottom, definitionString);
                }

            }

        }

    } else {

        const bool isHovered = index.data(HoveredItemRole).toBool();
        if (!isActive && isHovered) {
            painter->setFont(smallerFont);
            painter->setPen(Qt::white);
            QString videoTitle = video->title();
            QString v = videoTitle;
            const int flags = Qt::AlignTop | Qt::TextWordWrap;
            QRect textBox(PADDING, PADDING, THUMB_WIDTH - PADDING*2, THUMB_HEIGHT - PADDING*2);
            textBox = painter->boundingRect(textBox, flags, v);
            while (textBox.height() > THUMB_HEIGHT && v.length() > 10) {
                videoTitle.truncate(videoTitle.length() - 1);
                v = videoTitle;
                v = v.trimmed().append("...");
                textBox = painter->boundingRect(textBox, flags, v);
            }
            painter->fillRect(QRect(0, 0, THUMB_WIDTH, textBox.height() + PADDING*2), QColor(0, 0, 0, 128));
            painter->drawText(textBox, flags, v);
        }

    }

    painter->restore();

    if (downloadInfo) paintDownloadInfo(painter, option, index);

}
Beispiel #12
0
//MAIN GAME LOOP
void Game::GameLoop()
{
    //check time of last frame
    float frameTime = frameClock.getElapsedTime().asSeconds();
    frameClock.restart();



    //event loop
    sf::Event currentEvent;
    while(mainWindow.pollEvent(currentEvent))
    {
        //gotta handle resize things here
        if(currentEvent.type == sf::Event::Resized)
        {
            //std::cerr << "resized" << std::endl;
            float aspectRatio = float(currentEvent.size.width)/float(currentEvent.size.height);
            float newHeight = (1024.f*currentEvent.size.height)/currentEvent.size.width;
            float newWidth = (768.f*currentEvent.size.width)/currentEvent.size.height;
            if(aspectRatio > (4.f/3.f))
            {
                float displace = (newWidth - 1024.f)/(-2.f);
                View = sf::View(sf::FloatRect(displace, 0, newWidth, 768));
            }
            else if(aspectRatio < (4.f/3.f))
            {
                float displace = (newHeight - 768.f)/(-2.f);
                View = sf::View(sf::FloatRect(0, displace, 1024, newHeight));
            }
            mainWindow.setView(View);
        }
        //broken fullscreen stuff, do not touch
        else if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::F))
        {
            //mainWindow.close();
            //std::vector<sf::VideoMode> FullscreenModes = sf::VideoMode::getFullscreenModes();
            //mainWindow.create(FullscreenModes[0],"SHMUP Super Alpha", sf::Style::Fullscreen);
        }

        switch(gameState)
        {
        case GameOver:
        {
            if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::Return))
            {
                scoreboard.clear();
                gameState = Uninitialized;
            }
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            break;
        }
        case Playing:
        {
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::P))
            {
                sounds[2].play();
                gameState = Paused;
            }
            break;
        }
        case Paused:
        {
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::P))
            {
                sounds[2].play();
                gameState = Playing;
            }
            break;
        }
	case Intro:
	{
	    if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::Return))
            {
		storyScreen++;
		sounds[1].play();
		unsigned pos = 0;
		for(int i = 0; i < 10; i++)
		{
			pos = story.find_first_of('\n',pos+1);
		}
		buffer.assign(story,0,pos);
		story.erase(0,pos);

            }
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            break;

	}

	}
        }

    //non event-triggered state stuff (every frame updates)
    switch(gameState)
    {
    case Uninitialized:
    {
        mainWindow.clear();

        background0.Load("images/acespacebg0.png");
        background1.Load("images/acespacebg1.png");
        background0.sprite.setTextureRect(sf::Rect<int>(0,(2500-768),576,768));
        background1.sprite.setTextureRect(sf::Rect<int>(0,(2500-768),576,768));
        bgMove0 = 0;
        bgMove1 = 0;

        player1.Load("images/Player.png");
        player1.SetPosition(576/2,700);
        player1.revive();

        scoreboard.updatePower(0);
        scoreboard.updateLives(0);
        scoreboard.updateScore(-1);
	scoreboard.updateTargetHP(0,0);

        scoreboard.updateFont(&datagoth);
        scoreboard.clear();
    }
    case ShowingSplash:
    {
        if(!ShowSplashScreen())
            gameState = Exiting;
        else
        {
           gameState = Intro;
		unsigned pos = 0;
		for(int i = 0; i < 10; i++)
		{
			pos = story.find_first_of('\n',pos+1);
		}
		buffer.assign(story,0,pos);
		story.erase(0,pos);
	}
        break;
    }
    case Intro:
    {

	    if(storyScreen == 5) 
	    {
                music[0].stop();
		music[1].play();    
		gameState = Playing;

		scoreboard.updateLives(1);
		scoreboard.updatePower(5);
		scoreboard.updateScore(000000);
		scoreboard.updateTargetHP(0,0);

		//intial wave to seed the enemy list
		Enemy* newEnemy2 = new Enemy(2, 0, -100);
		newEnemy2->setDestination(200, 300);
		enemyList.push_front(*newEnemy2);

		Enemy* newEnemy3 = new Enemy(2, 576, -100);
		newEnemy3->setDestination(350, 300);
		enemyList.push_front(*newEnemy3);

		Enemy* newEnemy4 = new Enemy(2, 60, -100);
		newEnemy4->setDestination(200, 300);
		enemyList.push_front(*newEnemy4);

		Enemy* newEnemy5 = new Enemy(2, 536, -100);
		newEnemy5->setDestination(350, 300);
		enemyList.push_front(*newEnemy5);

		frameClock.restart();
	    }
    }
    case Playing:
    {
        //check movement
        CheckMovement(5, frameTime);
        if(player1.destroyCheck())
        {
            enemyList.clear();
            mainWindow.clear();
            player1.clearProjectiles();
            music[1].stop();
            sounds[4].play();
            scoreboard.updateLives(-1);
            gameState = GameOver;
            break;
        }

        UpdateProj();
        UpdateEnemies();

        //update paralaxed backgrounds
        if(bgMove0 > (2500-768))
            bgMove0 = 0;
        bgMove0 += 1;
        background0.sprite.setTextureRect(sf::Rect<int>(0,(2500-768)-bgMove0,576,768));
        break;
    }
    }

    if(bgMove1 > (2500-768))
        bgMove1 = 0;
    bgMove1 += 3;
    background1.sprite.setTextureRect(sf::Rect<int>(0,(2500-768)-bgMove1,576,768));

    //clean up sprites to be deleted
    CleanUp();

    //draw game
    mainWindow.clear(sf::Color(0,0,0));
    mainWindow.draw(wholeArea);
    background0.Draw(mainWindow);

    char fps[60];
    sprintf(fps,"%.2f\nESC to Quit\nP to Pause\nSPACE to Fire\nWASD to Move",(float(1)/frameTime));
    sf::String fpsString(fps);
    sf::Text text(fpsString, datagoth);
    text.setCharacterSize(20);
    text.setColor(sf::Color::White);
    text.setPosition(596, 650);

    sf::String sidebar(buffer+"\n\nPress Enter");
    sf::Text textBox(sidebar,datagoth);

    if(gameState == GameOver)
    {
        sf::String gameOver("GAME OVER");
        sf::Text endingMessage(gameOver, datagoth);
        endingMessage.setCharacterSize(50);
        //endingMessage.setStyle(sf::Text::Bold);
        endingMessage.setColor(sf::Color::Red);
        endingMessage.setPosition(288-(endingMessage.getGlobalBounds().width/2), 300);

        sf::String authors("Developed by:\nJohn New\nDevon Gardner\nJon Forcht\nDanny Krulick\n\n\n\n\n\n\nPress Enter to Restart");
        sf::Text credits(authors, datagoth);
        credits.setCharacterSize(20);
        credits.setColor(sf::Color::White);
        credits.setPosition(288-(credits.getGlobalBounds().width/2), 500);
        mainWindow.draw(credits);
        mainWindow.draw(endingMessage);
    }

    DrawProj();
    DrawEnemies();

    if(player1.destroyCheck() == false)
        player1.Draw(mainWindow);

    background1.Draw(mainWindow);

    mainWindow.draw(spawnArea);
    mainWindow.draw(rightBound);
    mainWindow.draw(leftBound);
    mainWindow.draw(bottomBound);
    mainWindow.draw(text);
    if(gameState == Intro && storyScreen < 5)
    {
    	textBox.setCharacterSize(20);
    	textBox.setColor(sf::Color::White);
    	textBox.setPosition(596, 250);
	mainWindow.draw(textBox);
    }
    scoreboard.drawScoreboard(mainWindow, player1.sprite);

    //finally, render the frame
    mainWindow.display();
}
Beispiel #13
0
//文字を描画
void DrawImpl::normalTextBox(const Vector2& pos, const std::string &str){
	textBox(pos, 0xFFFFFF, textDrawLog.fontHandle, str, 255, HorizontalPlace::left, VerticalPlace::top, Vector2(8, 8), 0x000000, 128);
}
Beispiel #14
0
void AddM2Click(UIFrame* f, int i)
{
	UITextBox::Ptr textBox(static_cast<UITextBox::Ptr>(f));
	(static_cast<UIDoodadSpawner *>(textBox->parent()))->AddM2(textBox->value());
}
/******************************************************************************
* Returns the natural size of the spinner widget.
******************************************************************************/
QSize SpinnerWidget::sizeHint() const
{
	if(textBox() == nullptr) return QSize(16, 30);
	else return QSize(16, textBox()->sizeHint().height());	
}
Beispiel #16
0
int main(int argc, char *argv[])
{
    Q_UNUSED(argc)
    Q_UNUSED(argv)

    //////////////////////////////////////////////////////////////////
    /// Init GraphicSystem singleton
    GraphicSystem::initialize("GraphicSystemTest", "data/fonts/DejaVuSans.ttf");
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Get pointers of GraphicSystem
    sf::RenderWindow *window;
    window = GraphicSystem::instance()->getWindow();

    tgui::Gui *gui;
    gui = GraphicSystem::instance()->getGUI();
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Create widgets
    tgui::Picture::Ptr picture((*gui));
    picture->load("data/others/Linux.jpg");

    tgui::Button::Ptr button((*gui));
    button->load(THEME_CONFIG_FILE);
    button->setPosition(40, 25);
    button->setText("Quit");
    button->setCallbackId(1);
    button->bindCallback(tgui::Button::LeftMouseClicked);
    button->setSize(300, 40);

    tgui::ChatBox::Ptr chatbox((*gui));
    chatbox->load(THEME_CONFIG_FILE);
    chatbox->setSize(200, 100);
    chatbox->setTextSize(20);
    chatbox->setPosition(400, 25);
    chatbox->addLine("Line 1", sf::Color::Red);
    chatbox->addLine("Line 2", sf::Color::Blue);
    chatbox->addLine("Line 3", sf::Color::Green);
    chatbox->addLine("Line 4", sf::Color::Yellow);
    chatbox->addLine("Line 5", sf::Color::Cyan);
    chatbox->addLine("Line 6", sf::Color::Magenta);

    tgui::Checkbox::Ptr checkbox((*gui));
    checkbox->load(THEME_CONFIG_FILE);
    checkbox->setPosition(40, 80);
    checkbox->setText("Checkbox");
    checkbox->setSize(32, 32);

    tgui::ChildWindow::Ptr child((*gui));
    child->load(THEME_CONFIG_FILE);
    child->setSize(200, 100);
    child->setBackgroundColor(sf::Color(80, 80, 80));
    child->setPosition(400, 460);
    child->setTitle("Child window");
    child->setIcon("data/others/icon.jpg");

    tgui::ComboBox::Ptr comboBox((*gui));
    comboBox->load(THEME_CONFIG_FILE);
    comboBox->setSize(120, 21);
    comboBox->setPosition(210, 440);
    comboBox->addItem("Item 1");
    comboBox->addItem("Item 2");
    comboBox->addItem("Item 3");
    comboBox->setSelectedItem("Item 2");

    tgui::EditBox::Ptr editBox((*gui));
    editBox->load(THEME_CONFIG_FILE);
    editBox->setPosition(40, 200);
    editBox->setSize(300, 30);

    tgui::Label::Ptr label((*gui));
    label->load(THEME_CONFIG_FILE);
    label->setText("Label");
    label->setPosition(40, 160);
    label->setTextColor(sf::Color(200, 200, 200));
    label->setTextSize(24);

    tgui::ListBox::Ptr listBox((*gui));
    listBox->load(THEME_CONFIG_FILE);
    listBox->setSize(150, 120);
    listBox->setItemHeight(20);
    listBox->setPosition(40, 440);
    listBox->addItem("Item 1");
    listBox->addItem("Item 2");
    listBox->addItem("Item 3");

    tgui::LoadingBar::Ptr loadingbar((*gui));
    loadingbar->load(THEME_CONFIG_FILE);
    loadingbar->setPosition(40, 330);
    loadingbar->setSize(300, 30);
    loadingbar->setValue(35);

    tgui::MenuBar::Ptr menu((*gui));
    menu->load(THEME_CONFIG_FILE);
    menu->setSize(window->getSize().x, 20);
    menu->addMenu("File");
    menu->addMenuItem("File", "Load");
    menu->addMenuItem("File", "Save");
    menu->addMenuItem("File", "Exit");
    menu->bindCallback(tgui::MenuBar::MenuItemClicked);
    menu->setCallbackId(2);

    sf::Texture texture;
    texture.loadFromFile("data/others/ThinkLinux.jpg");

    tgui::Panel::Ptr panel((*gui));
    panel->setSize(200, 140);
    panel->setPosition(400, 150);
    panel->setBackgroundTexture(&texture);

    tgui::RadioButton::Ptr radioButton((*gui));
    radioButton->load(THEME_CONFIG_FILE);
    radioButton->setPosition(40, 120);
    radioButton->setText("Radio Button");
    radioButton->setSize(32, 32);

    tgui::Slider::Ptr slider((*gui));
    slider->load(THEME_CONFIG_FILE);
    slider->setVerticalScroll(false);
    slider->setPosition(40, 250);
    slider->setSize(300, 25);
    slider->setValue(2);

    tgui::Scrollbar::Ptr scrollbar((*gui));
    scrollbar->load(THEME_CONFIG_FILE);
    scrollbar->setVerticalScroll(false);
    scrollbar->setPosition(40, 290);
    scrollbar->setSize(300, 25);
    scrollbar->setMaximum(5);
    scrollbar->setLowValue(3);

    tgui::Slider2d::Ptr slider2d((*gui));
    slider2d->load("data/widgets/Slider2d/Black.conf");
    slider2d->setPosition(400, 300);
    slider2d->setSize(200, 150);

    tgui::SpinButton::Ptr spinButton((*gui));
    spinButton->load(THEME_CONFIG_FILE);
    spinButton->setPosition(40, 410);
    spinButton->setVerticalScroll(false);
    spinButton->setSize(40, 20);

    tgui::SpriteSheet::Ptr spritesheet((*gui));
    spritesheet->load("data/others/ThinkLinux.jpg");
    spritesheet->setCells(4, 4);
    spritesheet->setVisibleCell(2, 3);
    spritesheet->setSize(160, 120);
    spritesheet->setPosition(620, 25);

    tgui::Tab::Ptr tab((*gui));
    tab->load(THEME_CONFIG_FILE);
    tab->setPosition(40, 370);
    tab->add("Item 1");
    tab->add("Item 2");
    tab->add("Item 3");

    tgui::TextBox::Ptr textBox((*gui));
    textBox->load(THEME_CONFIG_FILE);
    textBox->setPosition(210, 470);
    textBox->setSize(180, 120);
    textBox->setTextSize(16);

    comboBox->moveToFront();
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Start main loop
    while(window->isOpen())
    {
        GraphicSystem::instance()->injectPreUpdate(0);

        sf::Event event;
        while(GraphicSystem::instance()->pollWindowEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window->close();

            GraphicSystem::instance()->handleGUIEvent(event);
        }

        tgui::Callback callback;
        while(GraphicSystem::instance()->pollGUICallback(callback))
        {
            if(callback.id == 1)
                window->close();

            else if(callback.id == 2)
            {
                if(callback.text == "Exit")
                    window->close();
            }
        }

        GraphicSystem::instance()->injectPostUpdate(0);
    }
    //////////////////////////////////////////////////////////////////



    //////////////////////////////////////////////////////////////////
    /// Destroy GraphicSystem
    GraphicSystem::shutdown();
    //////////////////////////////////////////////////////////////////

    return 0;
}
void PlaylistItemDelegate::paintBody(QPainter *painter,
                                     const QStyleOptionViewItem &option,
                                     const QModelIndex &index) const {
    const bool isSelected = option.state & QStyle::State_Selected;
    if (isSelected)
        QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);

    painter->save();
    painter->translate(option.rect.topLeft());

    QRect line(0, 0, option.rect.width(), option.rect.height());
    if (downloadInfo) line.setWidth(line.width() / 2);

    const bool isActive = index.data(ActiveTrackRole).toBool();

    // get the video metadata
    const Video *video = index.data(VideoRole).value<VideoPointer>().data();

    // draw the "current track" highlight underneath the text
    if (isActive && !isSelected) paintActiveOverlay(painter, option, line);

    // thumb
    const QPixmap &thumb = video->getThumbnail();
    if (!thumb.isNull()) {
        painter->drawPixmap(0, 0, thumb);
        if (video->getDuration() > 0) drawTime(painter, video->getFormattedDuration(), line);
    }

    const bool thumbsOnly = line.width() <= thumbWidth + 60;
    const bool isHovered = index.data(HoveredItemRole).toBool();

    // play icon overlayed on the thumb
    bool needPlayIcon = isActive;
    if (thumbsOnly) needPlayIcon = needPlayIcon && !isHovered;
    if (needPlayIcon) painter->drawPixmap(0, 0, playIcon);

    if (!thumbsOnly) {
        // text color
        if (isSelected)
            painter->setPen(QPen(option.palette.highlightedText(), 0));
        else
            painter->setPen(QPen(option.palette.text(), 0));

        // title
        QStringRef title(&video->getTitle());
        QString elidedTitle = video->getTitle();
        static const int titleFlags = Qt::AlignTop | Qt::TextWordWrap;
        QRect textBox = line.adjusted(padding + thumbWidth, padding, -padding, 0);
        textBox = painter->boundingRect(textBox, titleFlags, elidedTitle);
        while (textBox.height() > 55 && elidedTitle.length() > 10) {
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
            title = title.left(title.length() - 1);
#elif QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
            title.truncate(title.length() - 1);
#else
            title.chop(1);
#endif
            elidedTitle = title.trimmed() + QStringLiteral("…");
            textBox = painter->boundingRect(textBox, titleFlags, elidedTitle);
        }
        painter->drawText(textBox, titleFlags, elidedTitle);

        painter->setFont(smallerFont);
        painter->setOpacity(.5);
        QFontMetrics fontMetrics = painter->fontMetrics();
        static const int flags = Qt::AlignLeft | Qt::AlignTop;

        // published date
        const QString &published = video->getFormattedPublished();
        QSize textSize(fontMetrics.size(Qt::TextSingleLine, published));
        QPoint textPoint(padding + thumbWidth, padding * 2 + textBox.height());
        textBox = QRect(textPoint, textSize);
        painter->drawText(textBox, flags, published);

        bool elided = false;

        // author
        if (!listView || listView->isClickableAuthors()) {
            bool authorHovered = isHovered && index.data(AuthorHoveredRole).toBool();

            painter->save();
            painter->setFont(smallerBoldFont);
            if (!isSelected) {
                if (authorHovered)
                    painter->setPen(QPen(option.palette.brush(QPalette::Highlight), 0));
            }
            const QString &author = video->getChannelTitle();
            textPoint.setX(textBox.right() + padding);
            textSize = QSize(painter->fontMetrics().size(Qt::TextSingleLine, author));
            textBox = QRect(textPoint, textSize);
            authorRects.insert(index.row(), textBox);
            if (textBox.right() > line.width() - padding) {
                textBox.setRight(line.width());
                elided = drawElidedText(painter, textBox, flags, author);
            } else {
                painter->drawText(textBox, flags, author);
            }
            painter->restore();
        }

        // view count
        if (video->getViewCount() > 0) {
            const QString &viewCount = video->getFormattedViewCount();
            textPoint.setX(textBox.right() + padding);
            textSize = QSize(fontMetrics.size(Qt::TextSingleLine, viewCount));
            if (elided || textPoint.x() + textSize.width() > line.width() - padding) {
                textPoint.setX(thumbWidth + padding);
                textPoint.setY(textPoint.y() + textSize.height() + padding);
            }
            textBox = QRect(textPoint, textSize);
            if (textBox.bottom() <= line.height()) {
                painter->drawText(textBox, flags, viewCount);
            }
        }

        if (downloadInfo) {
            const QString &def = VideoDefinition::forCode(video->getDefinitionCode()).getName();
            textPoint.setX(textBox.right() + padding);
            textSize = QSize(fontMetrics.size(Qt::TextSingleLine, def));
            textBox = QRect(textPoint, textSize);
            painter->drawText(textBox, flags, def);
        }

    } else {
        // thumbs only
        if (isHovered) {
            painter->setFont(smallerFont);
            painter->setPen(Qt::white);
            QStringRef title(&video->getTitle());
            QString elidedTitle = video->getTitle();
            static const int titleFlags = Qt::AlignTop | Qt::TextWordWrap;
            QRect textBox(padding, padding, thumbWidth - padding * 2, thumbHeight - padding * 2);
            textBox = painter->boundingRect(textBox, titleFlags, elidedTitle);
            while (textBox.height() > 55 && elidedTitle.length() > 10) {
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
                title = title.left(title.length() - 1);
#elif QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
                title.truncate(title.length() - 1);
#else
                title.chop(1);
#endif
                elidedTitle = title.trimmed() + QStringLiteral("…");
                textBox = painter->boundingRect(textBox, titleFlags, elidedTitle);
            }
            painter->fillRect(QRect(0, 0, thumbWidth, textBox.height() + padding * 2),
                              QColor(0, 0, 0, 128));
            painter->drawText(textBox, titleFlags, elidedTitle);
        }
    }

    painter->restore();

    if (downloadInfo) paintDownloadInfo(painter, option, index);
}