Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - starkhorn

#16
arrggh nevermind.

I needed to do this instead, i.e. use *passed_texture instead of passed_texture. Sorry.

Code (cpp) Select

auto picture = std::make_shared<tgui::Picture>(*passed_texture);
#17
Ok thanks. Can I make a create a picture from an existing loaded sf::Texture? I tried the below but I get error

Error   304   error C2664: 'tgui::Picture::Picture(const tgui::Picture &)' : cannot convert argument 1 from 'sf::Texture *' to 'const std::string &'   c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory   932   1   rome_vs2013


Code (cpp) Select

bool drawEngine::setupPicture(sf::Vector2i pos, sf::Vector2i size, string passed_pictureName, sf::Texture *passed_texture, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(passed_pictureName) == NULL) || (container == NULL && gui.get(passed_pictureName) == NULL))
{
auto picture = std::make_shared<tgui::Picture>(passed_texture);
picture->setPosition(pos.x, pos.y);
picture->setSize(size.x, size.y);
if (container == NULL)
{
gui.add(picture, passed_pictureName);
}
else
{
container->add(picture, passed_pictureName);
}

return true;
}

return false;
}

#18
Ok thanks. Driver is already up-to-date. It might be easier for me to avoid using canvas then.

Just to clarify that only canvas uses RenderTexture? So if I convert my SFText to labels then I would not need a canvas as I can draw them directly onto the childwindow container?

Also can childwindows have background image? I don't see that method when I check the methods from the getRenderer() method. Most of the sprites that I am drawing onto the canvas are part of the background image.

Code (cpp) Select

childWin->getRenderer()->
#19
Quote from: texus on 02 April 2016, 23:17:14
There are a few things you could look at:
- What happens if instead of canvases you just create a render texture (call create, clear and display on it)? Does it cause blinking as well?

Ok so I comment out the setupCanvas function and instead I add these lines. I didn't even bother doing a clear or display. The blinking does happen. It is not as pronounced or as bad as when I am doing the setupCanvas but it does happen. (Say a blink of 0.1 seconds as opposed to say 0.4 seconds)

Code (cpp) Select


// create a 500x500 render-texture
sf::RenderTexture renderTexture;
if (!renderTexture.create(500, 500))
{
// error...
}



I haven't tried the other 2 points yet but does the above mean it is an SFML issue?
#20
Quote from: texus on 02 April 2016, 11:42:31
Are you calling canvas->clear() and canvas->display() around your canvas->draw() calls?

I call a canvas->clear() at the beginning.
I then call the below (drawSFTextOnCanvas) multiple times to draw various SFTexts to the canvas.
Then at the end of the method, I call canvas->display.

Code (cpp) Select

void drawEngine::drawSFTextOnCanvas(vector<sf::Text> vectorSFText, tgui::Canvas::Ptr canvas)
{
for (int i = 0; i < vectorSFText.size(); i++)
{
canvas->draw(vectorSFText[i]);
}
}


Now what is strange is if I comment out all drawSFTextOnCanvas, canvas->clear and canvas->display then the issue still happens when all I am doing is creating the canvas. So basically if I just call the below, the blinking happens. It only happens with canvas. Other widgets getting added to the container are fine. I've tried buttons, listboxes and panels.

Code (cpp) Select

//return true if creates new canvas
bool drawEngine::setupCanvas(sf::Vector2i pos, sf::Vector2i size, string passed_canvasName, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(passed_canvasName) == NULL) || (container == NULL && gui.get(passed_canvasName) == NULL))
{
auto canvas = std::make_shared<tgui::Canvas>();
canvas->setPosition(pos.x, pos.y);
canvas->setSize(size.x, size.y);

if (container == NULL)
{
gui.add(canvas, passed_canvasName);
}
else
{
container->add(canvas, passed_canvasName);
}

return true;
}

return false;
}

#21
So I have a strange issue and I am not even sure how to explain it properly. :)

I have code that creates a childwindow. I then want a canvas on the childwindow so I can draw lots of sprite, SFtexts etc.
Now when I reach part of the code that has a childwindow with a canvas (which is virtually all my childwindows), the screen blinks for a split second. It is hard to describe but it looks like the gamewindow is cleared or refreshed or that I quickly pressed alt-tab really quickly (which I did not). As my game relies on lots of childwindows opening and closing frequently then this makes the game all but unplayable.
Note it only seems to happen when in fullscreen mode.

Now when I comment out the line that creates a canvas, the blinking/refreshing does not happen.

First see the code where I call the childwindow and canvas in one of my menu methods. If I comment out the //initSubMenuCanvas method in this function then the blinking does not happen. (obviously I have to comment out all of the lines that are drawing to that canvas as well).

Code (cpp) Select

void drawEngine::drawStartTurnSummarySubMenu(Nation *passed_Nation)
{
sf::Vector2i pos(gameWindow.getSize().x * 0.1, gameWindow.getSize().y * 0);
sf::Vector2i size((gameWindow.getSize().x - (gameWindow.getSize().x * 0.25)), getLowerScreenPos().y);

setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, battleChildWin);

tgui::Container::Ptr container = gui.get<tgui::Container>(battleChildWin);
        initSubMenuCanvas(container);
.....
.....
//lots of draw sprites or sf texts onto the canvas throughout the rest of this method.




So you can see below the functions where I actually create the childwindow and canvas. In the initSubMenuCanvas I have tried removing everything except the setupCanvas call but it makes not difference. I had wanted to provide a full working example but the code is quite long and complex now.

Code (cpp) Select


bool drawEngine::setupChildWindow(sf::Vector2i pos, sf::Vector2i size, string title_text, sf::Color titleText_Color, string passed_childName)
{
if (gui.get(passed_childName) == NULL)
{
tgui::ChildWindow::Ptr childWin = theme->load("ChildWindow");
childWin->setPosition(pos.x, pos.y);
childWin->setSize(size.x, size.y);
childWin->getRenderer()->setTitleColor(titleText_Color);
childWin->setTitle(title_text);
gui.add(childWin, passed_childName);
cout << "creating win " << passed_childName << "\n";
return true;
}

return false;
}

void drawEngine::initSubMenuCanvas(tgui::Container::Ptr container)
{
sf::Sprite subMenuBackGroundSprite(subMenuBackGround);
float childSizeX = container->getSize().x;
float childSizeY = container->getSize().y;
sf::Vector2f scaledValues;

sf::Vector2i pos;
sf::Vector2i size(childSizeX, childSizeY);;

if (setupCanvas(pos, size, "subMenuCanvas", container))
{
scaledValues = calcScale(childSizeX, childSizeY, subMenuBackGround.getSize());
subMenuBackGroundSprite.setScale(scaledValues.x, scaledValues.y);

tgui::Canvas::Ptr canvas = container->get<tgui::Canvas>("subMenuCanvas");
canvas->draw(subMenuBackGroundSprite);
}
}

bool drawEngine::setupCanvas(sf::Vector2i pos, sf::Vector2i size, string passed_canvasName, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(passed_canvasName) == NULL) || (container == NULL && gui.get(passed_canvasName) == NULL))
{
auto canvas = std::make_shared<tgui::Canvas>();
canvas->setPosition(pos.x, pos.y);
canvas->setSize(size.x, size.y);

if (container == NULL)
{
gui.add(canvas, passed_canvasName);
}
else
{
container->add(canvas, passed_canvasName);
}

return true;
}

return false;
}

#22
Help requests / listbox text color
20 October 2015, 02:41:19
Is there a way to have different text color for different items in he same listbox?

I've various strings and I want to color code them differently depending on certain criteria. Now I can get see in the listbox renderer a text color method but it seems to be for all text and not specific to a certain item. Is there a way to do that?
#23
Right again Texus, I thought I was adding the second parameter in the addItem but nope I was not. Thanks again.
#24
So I have visual studio 2013 express so according to the signal tutorial, I need to use the connectEX method.

So when an item is selected in a listbox, is there a way to get the itemID in the callback? I have the below simple signal function but the itemID is always empty.

Code (cpp) Select


void drawEngine::armyUnitListBoxSignalFunction(const tgui::Callback& callback)
{
string item = callback.text;
string itemID = callback.itemId;
}



it is called using the below call

Code (cpp) Select

        tgui::ListBox::Ptr armyUnitListBox = gui.get<tgui::ListBox>(ListBoxID, true);
armyUnitListBox->connectEx("ItemSelected", &drawEngine::armyUnitListBoxSignalFunction, this);
#25
arrrggh you are 100% correct (as usual).

This line

Code (cpp) Select


tgui::ListBox::Ptr regionListBox = testClass.gui.get<tgui::ListBox>(listboxID);



But my listbox was added into the canvas which is in turn was in a childwindow.

Doing this works

Code (cpp) Select

tgui::ListBox::Ptr regionListBox = testClass.gui.get<tgui::ListBox>(listboxID, true);


Thanks again
#26
Help requests / V0.7 alphav0.2 listbox signals
15 October 2015, 22:24:55
Hey,

I'm trying to use the listbox signals but everytime I try to connect a signal to the listbox instance, I get an "Unhandled exception at 0x011611FA in BLAH.exe: 0xC0000005: Access violation reading location 0x000000A4."

When I break, it seems to be stopped in the signalbasewidget.hpp file at the below location

Code (cpp) Select

        template <typename Func, typename... Args>
        unsigned int connect(const std::string& signalNames, Func func, Args... args)
        {
            for (auto& signalName : extractSignalNames(signalNames))
            {
                if (m_signals.find(toLower(signalName)) != m_signals.end())     //<----------STOPS HERE STOPS HERE STOPS HERE
                {
                    try {
                        m_signals[toLower(signalName)]->connect(m_lastId, func, args...);
                        m_lastId++;
                    }
                    catch (const Exception& e) {
                        throw Exception{e.what() + (" The parameters are not valid for the '" + signalName + "' signal.")};
                    }
                }


I've tried ItemSelected, MouseEntered, MousePressed and all the same result. See below a full working exampe of what I am trying to do. Any ideas on what I am doing wrong here?

Code (cpp) Select

#include <TGUI/TGUI.hpp>
#include <string>
#include <math.h>
#define THEME_CONFIG_FILE "E:\\programming\\projects\\rome_vs2013\\rome_vs2013\\Debug\\\\widgets\\rome.txt"
#include "nation.h"

using namespace std;

class Test
{
public:

Test();

sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Callback callback;
tgui::Gui gui;
sf::Texture mainMenuBackGround;
sf::Font font;

tgui::Theme::Ptr theme;

void initFont();
void setThemeConfigFile(string passed_filename);
void setupChildWindow(sf::Vector2i pos, sf::Vector2i size, string title_text, sf::Color titleText_Color, string passed_childName);
void setupCanvas(sf::Vector2i pos, sf::Vector2i size, string passed_canvasName, tgui::Container::Ptr container = NULL);
void initSubMenuCanvas(tgui::Container::Ptr container);
void setupListBox(sf::Vector2i pos, sf::Vector2i size, int passed_TextSize, sf::Color passed_colour, string listBoxID, string passed_themeSection, tgui::Container::Ptr container = NULL);
void addStringItemToListBox(string listBoxID, vector<string> passed_stringItemsToAdd);
void drawCitySubMenu(Nation *passed_Nation, tgui::Canvas::Ptr canvas);

};

Test::Test()
{
desktop = sf::VideoMode::getDesktopMode();
gameWindow.create(sf::VideoMode(desktop.width, desktop.height, desktop.bitsPerPixel), "Test");
gameWindow.setPosition(sf::Vector2i(0, 0));
gui.setWindow(gameWindow);
gui.setFont("E:\\programming\\projects\\rome_vs2013\\rome_vs2013\\Debug\\\\inputfiles\\fonts\\DejaVuSans.ttf");
setThemeConfigFile(THEME_CONFIG_FILE);

}

void Test::initFont()
{
font.loadFromFile("E:\\programming\\projects\\rome_vs2013\\rome_vs2013\\Debug\\inputfiles\\fonts\\DejaVuSans.ttf");
}

void Test::setThemeConfigFile(string passed_filename)
{
// Load the black theme
theme = std::make_shared<tgui::Theme>(passed_filename);
}

void Test::setupChildWindow(sf::Vector2i pos, sf::Vector2i size, string title_text, sf::Color titleText_Color, string passed_childName)
{
if (gui.get(passed_childName) == NULL)
{
tgui::ChildWindow::Ptr childWin = theme->load("ChildWindow");
childWin->setPosition(pos.x, pos.y);
childWin->setSize(size.x, size.y);
childWin->getRenderer()->setTitleColor(titleText_Color);
childWin->setTitle(title_text);
gui.add(childWin, passed_childName);
}
}

void Test::setupCanvas(sf::Vector2i pos, sf::Vector2i size, string passed_canvasName, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(passed_canvasName) == NULL) || (container == NULL && gui.get(passed_canvasName) == NULL))
{
auto canvas = std::make_shared<tgui::Canvas>();
canvas->setPosition(pos.x, pos.y);
canvas->setSize(size.x, size.y);

if (container == NULL)
{
gui.add(canvas, passed_canvasName);
}
else
{
container->add(canvas, passed_canvasName);
}
}
}

void Test::initSubMenuCanvas(tgui::Container::Ptr container)
{
float childSizeX = container->getSize().x;
float childSizeY = container->getSize().y;
sf::Vector2f scaledValues;

sf::Vector2i pos;
sf::Vector2i size(childSizeX, childSizeY);;

setupCanvas(pos, size, "subMenuCanvas", container);

tgui::Canvas::Ptr canvas = container->get<tgui::Canvas>("subMenuCanvas");
canvas->clear();
}

void Test::setupListBox(sf::Vector2i pos, sf::Vector2i size, int passed_TextSize, sf::Color passed_colour, string listBoxID, string passed_themeSection, tgui::Container::Ptr container)
{
if ((container != NULL && container->get(listBoxID) == NULL) || (container == NULL && gui.get(listBoxID) == NULL))
{
tgui::ListBox::Ptr listbox = theme->load(passed_themeSection);
listbox->setPosition(pos.x, pos.y);
listbox->setSize(size.x, size.y);
listbox->getRenderer()->setTextColor(passed_colour);
listbox->setItemHeight(passed_TextSize);

if (container == NULL)
{
gui.add(listbox, listBoxID);
}
else
{
container->add(listbox, listBoxID);
}
}
}

void Test::addStringItemToListBox(string listBoxID, vector<string> passed_stringItemsToAdd)
{
tgui::ListBox::Ptr listbox = gui.get<tgui::ListBox>(listBoxID, true);

if (listbox != NULL)
{
bool isLineAlreadyAdded = false;
vector<sf::String> itemsList;

for (int i = 0; i < passed_stringItemsToAdd.size(); i++)
{
itemsList = listbox->getItems();
isLineAlreadyAdded = false;
for (int j = 0; j < itemsList.size(); j++)
{
if (itemsList.at(j) == passed_stringItemsToAdd[i])
{
isLineAlreadyAdded = true;
}
}

if (!isLineAlreadyAdded)
{
listbox->addItem(passed_stringItemsToAdd[i]);
}
}

}
}

void Test::drawCitySubMenu(Nation *passed_Nation, tgui::Canvas::Ptr canvas)
{
sf::Text msg("", font);


msg.setCharacterSize(15);
msg.setColor(sf::Color::White);
msg.setPosition(10, 25);
msg.setString("This is draw city sub menu");
canvas->draw(msg);
}


int main()
{
Test testClass;
string themeSection;
string childWinName = "testChild";
string listboxID = "listbox";
Nation passed_Nation;

sf::Vector2i pos(testClass.gameWindow.getSize().x * 0.1, testClass.gameWindow.getSize().y * 0);
sf::Vector2i size((testClass.gameWindow.getSize().x - (testClass.gameWindow.getSize().x * 0.25)), 400);

testClass.setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, childWinName);

tgui::Container::Ptr container = testClass.gui.get<tgui::Container>(childWinName);
testClass.initSubMenuCanvas(container);
tgui::Canvas::Ptr canvas = container->get<tgui::Canvas>("subMenuCanvas");
sf::Vector2f childSize(container->getSize());

pos.x = 0;
pos.y = 10;

testClass.setupListBox(pos, size, 15, sf::Color::Green, listboxID, "Listbox", container);
tgui::ListBox::Ptr regionListBox = testClass.gui.get<tgui::ListBox>(listboxID);
regionListBox->connect("ItemSelected", &Test::drawCitySubMenu, &testClass, &passed_Nation, canvas);
testClass.addStringItemToListBox(listboxID, passed_Nation.getNationListOfRegionsMenuData());

    // Main loop
while (testClass.gameWindow.isOpen())
    {
        sf::Event event;
while (testClass.gameWindow.pollEvent(event))
        {
            // When the window is closed, the application ends
            if (event.type == sf::Event::Closed)
testClass.gameWindow.close();


            // Pass the event to all the widgets
testClass.gui.handleEvent(event);
        }

testClass.gameWindow.clear();
testClass.gui.draw();
testClass.gameWindow.display();
}

return 0;
}

#27
awesome - works a treat. Thank you.
#28
Is it possible to set the position of the text on a button? I have the text size small and I wanted it to be in the top left corner of the button.
#29
Help requests / Re: v0.7 add horizontal ListBox
28 September 2015, 21:12:01
Ok no problem. So to clarify I was going to suggest two new features.

1:- The horizontal scroll-bar on a listbox if the item is longer than the width of the listbox.
2:- Field formatting of items (in my case string items) on a per line basis.

i.e. I want to displaying something like below. So there is a delimiter that can seperate the items into fields/columns and the field/columns width or position can be defined. I know this is probably alot of work but I just thought to suggest it.

Code (cpp) Select


ListBoxCol1Row1 ListBoxCol2Row1 ListBoxCol3Row1
ListBoxCol1Row2 ListBoxCol2Row2 ListBoxCol3Row2

#30
Help requests / Re: v0.7 add horizontal ListBox
23 September 2015, 23:44:58
No worries mate - thanks for checking. Good luck with uni.

Should i post this new feature request somewhere so you can keep track of it when you next look at doing a new version?