Exemplo n.º 1
0
	void TextField::draw(const Graphic& graphic, double deltaTime) {
		Component::draw(graphic, deltaTime);

		Dimension dim = getSize();
		float x = 0.0;
		// Text should 
		switch (alignment_) {
			case Alignment::LEFT:
				x = 2;
				break;
			case Alignment::CENTER:
				x = dim.width_ * 0.5f - (text_.getWidth() - 2) * 0.5f;
				break;
			case Alignment::RIGHT:
				x = dim.width_ - text_.getWidth() - 2;
				break;
		}

		graphic.setColor(textColor_);
		graphic.drawText(text_, x, 0);
		if (editable_) {
			if (hasFocus()) {
				markerDeltaTime_ += deltaTime;
				if (markerDeltaTime_ < 0.5) {
					graphic.drawSquare(markerWidth_ + x, 1, 1, text_.getCharacterSize());
				} else if (markerDeltaTime_ > 1.0) {
					markerDeltaTime_ = 0;
				}
			} else {
				markerDeltaTime_ = 0;
			}
		}
	}
Exemplo n.º 2
0
	void Component::draw(const Graphic& graphic, double deltaTime) {
		// Draw panel background.
		graphic.setColor(backgroundColor_);
		graphic.drawSquare(0, 0, dimension_.width_, dimension_.height_);
		graphic.drawSprite(background_, 0, 0, dimension_.width_, dimension_.height_);
		graphic.setColor(borderColor_);
		graphic.drawBorder(0, 0, dimension_.width_, dimension_.height_);
	}