Skip to content
Snippets Groups Projects
Commit 08b25030 authored by Horváth Kata's avatar Horváth Kata
Browse files

szovegbeviteli mezo javitva

parent 7c572e5e
No related branches found
No related tags found
No related merge requests found
......@@ -56,9 +56,6 @@ bool GameLogic::makeMove( int col){
bool GameLogic::validMove(int col) const{
return col >= 0 && col < COLS && !ColumnFull(col) && !gameover;
......
......@@ -44,6 +44,9 @@ private:
start_button = new Button(this, 350, 360, 100, 40, "START");
menu_widgets.push_back(start_button);
registerWidget(start_button);
// gout << move_to(270, 280) << text("Jtkos 1");
// gout << move_to(490, 280) << text("Jtkos 2");
}
......@@ -188,10 +191,19 @@ private:
void showGameStatus(){
if(_game.getWinner()==GameLogic::EMPTY){
std::cout << "dontetlen";
std::cout << "dontetlen :(";
}
else{
std::cout << _game.getWinner() << " jatekos nyert! \n";
//std::cout << _game.getWinner();
if (_game.getWinner()==1){
std::cout << player1_name << " nyert :)";
}
else if (_game.getWinner()==2){
std::cout << player2_name << "nyert :)";
}
}
}
......
#include "statictext.hpp"
#include "graphics.hpp"
using namespace genv;
StaticText::StaticText(int x, int y, int sx, int sy, const std::string& s)
: Widget(x, y, sx, sy), _text(s), _cursor_pos(0), _show_cursor(false), _editable(false) {}
void StaticText::draw() {
gout << move_to(_x, _y) << color(255, 255, 255) << box(_size_x, _size_y);
gout.load_font("LiberationMono-Regular.ttf", 15);
gout << move_to(_x+2 + 2, _y+10) << color(0, 0, 0);
std::string visible_text = _text;
int text_width = gout.twidth(visible_text);
while (text_width > _size_x - 4 && !visible_text.empty()) {
visible_text.pop_back();
text_width = gout.twidth(visible_text);
}
gout << text(visible_text);
if (_editable && _show_cursor) {
std::string before_cursor = _text.substr(0, _cursor_pos);
int cursor_x = _x + 2 + gout.twidth(before_cursor);
if (cursor_x < _x + _size_x - 2) {
gout << move_to(cursor_x+2, _y + _size_y/4) << color(0, 0, 0)
<< line(0, gout.cascent() + gout.cdescent());
}
}
}
void StaticText::handle(event ev) {
if (ev.type == ev_mouse && ev.button == btn_left) {
_editable = is_selected(ev.pos_x, ev.pos_y);
_show_cursor = _editable;
if (_editable) {
int click_x = ev.pos_x - _x - 2;
std::string temp;
_cursor_pos = 0;
for (size_t i = 0; i < _text.length(); i++) {
temp += _text[i];
if (gout.twidth(temp) > click_x) {
break;
}
_cursor_pos = i + 1;
}
}
}
if (!_editable) return;
if (ev.type == ev_key) {
_show_cursor = true;
if (ev.keycode == key_left && _cursor_pos > 0) {
_cursor_pos--;
} else if (ev.keycode == key_right && _cursor_pos < _text.length()) {
_cursor_pos++;
} else if (ev.keycode == key_backspace && _cursor_pos > 0) {
_text.erase(_cursor_pos - 1, 1);
_cursor_pos--;
} else if (ev.keycode == key_delete && _cursor_pos < _text.length()) {
_text.erase(_cursor_pos, 1);
} else if (ev.keycode >= 32 && ev.keycode < 256) {
std::string temp_text = _text;
temp_text.insert(_cursor_pos, 1, ev.keycode);
if (gout.twidth(temp_text) <= _size_x - 4) {
_text.insert(_cursor_pos, 1, ev.keycode);
_cursor_pos++;
}
} else if (ev.keyutf8 != "") {
std::string temp_text = _text;
temp_text.insert(_cursor_pos, ev.keyutf8);
if (gout.twidth(temp_text) <= _size_x - 4) {
_text.insert(_cursor_pos, ev.keyutf8);
_cursor_pos += ev.keyutf8.length();
}
}
}
}
#ifndef STATICTEXT_HPP
#define STATICTEXT_HPP
#include "widgets.hpp"
#include <string>
class StaticText : public Widget {
protected:
std::string _text;
size_t _cursor_pos;
bool _show_cursor;
bool _editable;
public:
StaticText(int x, int y, int sx, int sy, const std::string& s);
virtual void draw() override;
virtual void handle(genv::event ev) override;
};
#endif
......@@ -60,7 +60,7 @@ void Textbox::handle_event(event ev){
int click_x=ev.pos_x-_x - 2;
std::string temp;
_cursor_pos=0;
//_cursor_pos=0;
for (int i=0; i<_text.length(); i++){
temp+=_text[i];
......
#include "textedit.hpp"
TextEdit::TextEdit(int x, int y, int sx, int sy, std::string s)
: Widget(x,y,sx,sy), _text(s)
{}
using namespace genv;
void TextEdit::draw()
{
gout.load_font("LiberationMono-BoldItalic.ttf", 20);
gout <<move_to(_x, _y) << color(255,255,255) << box(_size_x, _size_y) << color(0, 0, 0) << move_to(_x+5, _y+5) << text(_text);
}
void TextEdit::handle(event ev)
{
if(ev.type == ev_key)
{
if(ev.keycode==key_backspace)
{
_text=_text.substr(0,_text.size()-1);
}
else
{
_text+=ev.keyutf8;
}
}
}
#ifndef TEXTEDIT_HPP
#define TEXTEDIT_HPP
#include "widgets.hpp"
class TextEdit : public Widget
{
protected:
std::string _text;
public:
TextEdit(int, int, int, int, std::string);
virtual void draw() override;
virtual void handle(genv::event) override;
};
#endif // TEXTEDIT_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment