1
Graphics / Re: How to control text
« on: May 22, 2018, 12:00:38 pm »
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include <cmath>
#include <ctime>
#include <iostream>
#include <windows.h>
#include <fstream>
#include <sstream>
using namespace std;
using namespace sf;
int entername();
int main()
{
sf::RenderWindow window(sf::VideoMode(1024,768), "Time Enter ");
sf::Vector2f windowCenter = sf::Vector2f(window.getSize().x / 2.0f, window.getSize().y / 2.0f);
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Text hour("Enter Hours :", font);
hour.setCharacterSize(40);
hour.setOrigin(500,200);
hour.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
hour.setStyle(sf::Text::Bold);
hour.setColor(sf::Color::Red);
sf::Text minute("Enter Minutes :", font);
minute.setCharacterSize(40);
minute.setOrigin(500,100);
minute.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
minute.setStyle(sf::Text::Bold);
minute.setColor(sf::Color::Red);
sf::Texture clockBrand;
if (!clockBrand.loadFromFile("rohan.png")){return EXIT_FAILURE;}
sf::Sprite clockBrandSprite;
clockBrandSprite.setTexture(clockBrand);
sf::Texture hour1;
if (!hour1.loadFromFile("enterhours.png")){return EXIT_FAILURE;}
sf::Sprite hours;
hours.setTexture(hour1);
hours.setOrigin(240,200);
hours.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
sf::Texture minute1;
if (!minute1.loadFromFile("enterminutes.png")){return EXIT_FAILURE;}
sf::Sprite minutes;
minutes.setTexture(hour1);
minutes.setOrigin(200,100);
minutes.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
sf::Text a("", font);
a.setCharacterSize(20);
a.setStyle(sf::Text::Bold);
a.setPosition(280,200);
a.setColor(sf::Color::Black);
sf::String c;
sf::Text b("",font);
b.setCharacterSize(20);
b.setStyle(sf::Text::Bold);
b.setPosition(325,300);
b.setColor(sf::Color::Black);
sf::String d;
sf::Texture ba;
if (!ba.loadFromFile("images.jpg")){return EXIT_FAILURE;}
sf::Sprite bac;
bac.setTexture(ba);
bac.setOrigin(513,385);
bac.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
float x;
float y;
float z;
while (window.isOpen()){
sf::Event event;
if ((sf::Mouse::getPosition(window).x >= 314 && sf::Mouse::getPosition(window).x <= 573) &&(sf::Mouse::getPosition(window).y >= 288 && sf::Mouse::getPosition(window).y <= 336)){
if (event.type == sf::Event::TextEntered){
if (event.text.unicode >= 48 && event.text.unicode <= 57){
d = d + static_cast<char>(event.text.unicode);
// d.insert(d.getSize(),event.text.unicode);
b.setString(d);
ofstream out;
out.open("b.txt", std::ofstream::out | std::ofstream::trunc);
out <<"."<<static_cast <char>(event.text.unicode)<<endl;
out.close();}}}
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();}
window.draw(clockBrandSprite);
window.draw(hour);
window.draw(minute);
window.draw(hours);
window.draw(minutes);
window.draw(bac);
window.draw(a);
window.draw(b);
window.display();
}
}
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include <cmath>
#include <ctime>
#include <iostream>
#include <windows.h>
#include <fstream>
#include <sstream>
using namespace std;
using namespace sf;
int entername();
int main()
{
sf::RenderWindow window(sf::VideoMode(1024,768), "Time Enter ");
sf::Vector2f windowCenter = sf::Vector2f(window.getSize().x / 2.0f, window.getSize().y / 2.0f);
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Text hour("Enter Hours :", font);
hour.setCharacterSize(40);
hour.setOrigin(500,200);
hour.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
hour.setStyle(sf::Text::Bold);
hour.setColor(sf::Color::Red);
sf::Text minute("Enter Minutes :", font);
minute.setCharacterSize(40);
minute.setOrigin(500,100);
minute.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
minute.setStyle(sf::Text::Bold);
minute.setColor(sf::Color::Red);
sf::Texture clockBrand;
if (!clockBrand.loadFromFile("rohan.png")){return EXIT_FAILURE;}
sf::Sprite clockBrandSprite;
clockBrandSprite.setTexture(clockBrand);
sf::Texture hour1;
if (!hour1.loadFromFile("enterhours.png")){return EXIT_FAILURE;}
sf::Sprite hours;
hours.setTexture(hour1);
hours.setOrigin(240,200);
hours.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
sf::Texture minute1;
if (!minute1.loadFromFile("enterminutes.png")){return EXIT_FAILURE;}
sf::Sprite minutes;
minutes.setTexture(hour1);
minutes.setOrigin(200,100);
minutes.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
sf::Text a("", font);
a.setCharacterSize(20);
a.setStyle(sf::Text::Bold);
a.setPosition(280,200);
a.setColor(sf::Color::Black);
sf::String c;
sf::Text b("",font);
b.setCharacterSize(20);
b.setStyle(sf::Text::Bold);
b.setPosition(325,300);
b.setColor(sf::Color::Black);
sf::String d;
sf::Texture ba;
if (!ba.loadFromFile("images.jpg")){return EXIT_FAILURE;}
sf::Sprite bac;
bac.setTexture(ba);
bac.setOrigin(513,385);
bac.setPosition(window.getSize().x / 2 + 2, window.getSize().y / 2 + 2);
float x;
float y;
float z;
while (window.isOpen()){
sf::Event event;
if ((sf::Mouse::getPosition(window).x >= 314 && sf::Mouse::getPosition(window).x <= 573) &&(sf::Mouse::getPosition(window).y >= 288 && sf::Mouse::getPosition(window).y <= 336)){
if (event.type == sf::Event::TextEntered){
if (event.text.unicode >= 48 && event.text.unicode <= 57){
d = d + static_cast<char>(event.text.unicode);
// d.insert(d.getSize(),event.text.unicode);
b.setString(d);
ofstream out;
out.open("b.txt", std::ofstream::out | std::ofstream::trunc);
out <<"."<<static_cast <char>(event.text.unicode)<<endl;
out.close();}}}
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();}
window.draw(clockBrandSprite);
window.draw(hour);
window.draw(minute);
window.draw(hours);
window.draw(minutes);
window.draw(bac);
window.draw(a);
window.draw(b);
window.display();
}
}