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.


Topics - starkhorn

Pages: [1] 2 3
1
Help requests / ListBox sounds
« on: 10 June 2016, 06:21:13 »
Hi Texus,

So I have a listbox setup fine but I wanted to play a sound when my mouse hovered over an item and also when an item was selected.
Now I think I can trap the item selected easily enough using the ItemSelected signal but what signal can be used when hovering over an item in a listbox? Is it the widgets MouseEntered ? Does that get triggered each time the mouse enters an item?


2
Help requests / Adding a border around a panel
« on: 31 May 2016, 05:07:49 »
Hi Texus,

I was using Textboxes but I found I could not alter the colour of specific lines of a text and I could not put them into columns. So instead I have created a panel and adding Labels to the panel.

However one thing that I was missing is that the textbox had a nice border around it's panel. Is there an easy way to add this to a panel?

3
Help requests / v0.7 scrollbar within child window
« on: 26 April 2016, 05:46:59 »
I'm having trouble getting a scrollbar to appear when adding it to a child window container.
In drawStartTurnSummarySubMenu, I create the child window with the setupChildWindow method.
I then try to add a scrollbar to the child window using setupScrollBarHorz and passing the child window as a container.
I can see that the number of widgets in the child window increases when I add the scrollbar but it never appears. (Note I put autohide to false).
However if I change the line in setupScrollBarHorz

Code: (cpp) [Select]
container->add(scrollbar, scrollBarName);

To the below, the scollbar appears.
Code: (cpp) [Select]
//gui.add(scrollbar, scrollBarName);

However if I move the childwindow the position of the scrollbar doesn't move. Basically I want the scrollbar to control widgets inside a panel which inside a child window. Here are the methods in question.

Code: (cpp) [Select]

void Test::drawStartTurnSummarySubMenu()
{
sf::Vector2i pos(gameWindow.getSize().x * 0.1, gameWindow.getSize().y * 0);
sf::Vector2i size((gameWindow.getSize().x - (gameWindow.getSize().x * 0.25)), gameWindow.getSize().y * 0.750);

setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, "startTurn");
tgui::Container::Ptr container = gui.get<tgui::Container>("startTurn");

pos = sf::Vector2i(0, 0);
void (Test::*ptrToMember)(const tgui::Callback&) = NULL; // creating function ptr
ptrToMember = &Test::scrollBarHorzSignalFunction; // assigning function ptr to appropraite function

setupScrollBarHorz("regionPanelScrollHorz", ptrToMember, container);

//clear game window
gameWindow.clear();

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

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);
}
}

bool Test::setupScrollBarHorz(string scrollBarName, void (Test::*ptrToMember)(const tgui::Callback&),tgui::Container::Ptr container)
{
if ((container != NULL && container->get(scrollBarName) == NULL) || (container == NULL && gui.get(scrollBarName) == NULL))
{
tgui::Scrollbar::Ptr scrollbar = theme->load("Scrollbar");
scrollbar->setPosition(container->getPosition() + sf::Vector2f(container->getSize().x, 0));
scrollbar->setSize(20, container->getSize().y);
scrollbar->connectEx("ValueChanged", ptrToMember, this);
scrollbar->setAutoHide(false);
container->add(scrollbar, scrollBarName);
//gui.add(scrollbar, scrollBarName);
return true;
}
else
{
return false;
}
}

void Test::scrollBarHorzSignalFunction(const tgui::Callback& callback)
{
int scrollbarMove = callback.value;
}

4
Help requests / table widget
« on: 22 April 2016, 01:04:24 »
Hi Texus,

I was looking at the table.cpp for the new table widget. It looks awesome.

I want to put it into a child window which I can do easily enough but I was wondering if there is a way to get a scroll bar both vertical and horizontal on that?

5
Help requests / Optional custom widget config
« on: 06 April 2016, 00:58:49 »
Hi Texus,

I was wondering if you could advise if any of the below config is optional? As you can see I basically want the RGB and image to be the same for normal, hover and down events. I have alot of these widgets to create in the conf file so I was wondering if there was a way to remove optional parameters? i.e. if HoverImage isn't present will it use the normalImage by default etc?

Code: (cpp) [Select]
Button.CustomButtonNonClickRomeHI {
    NormalImage  : "..\images\icons\romeNationIcon_v3.png" Part(  56,  0,  48, 64);
    HoverImage   : "..\images\icons\romeNationIcon_v3.png" Part(  56,  0,  48, 64);
    DownImage    : "..\images\icons\romeNationIcon_v3.png" Part(  56,  0,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(190, 190, 190);
    TextColorDown   : rgb(190, 190, 190);
}

6
Help requests / v0.7 using the tgui::picture
« on: 05 April 2016, 08:46:32 »
Hey Texus,

So I want to setup a picture using a texture. However I only want to set the picture to have the picture defined in a sf::IntRect.
Basically I have a sprite that has it's setTextureRect to a subset of a larger texture, and I want the tgui::picture to only display this subset/IntRect.

I don't see a setTextureRect method in tgui::picture so I was wondering if there was a way to do it? Again this is me trying to get around using canvas due to the blinking issue with my graphics card. So instead of sprites, I am trying to use tgui::pictures.

7
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;
}


8
Help requests / listbox text color
« on: 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?

9
Help requests / listbox using connectEx signal method
« on: 16 October 2015, 02:53:15 »
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);

10
Help requests / V0.7 alphav0.2 listbox signals
« on: 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;
}


11
Help requests / v0.7 alphav2 - text position on a button
« on: 02 October 2015, 02:08:47 »
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.

12
Help requests / v0.7 add horizontal ListBox
« on: 21 September 2015, 03:24:48 »
Hi Texus,

Is it possible to add a horizontal scrollbar to a listbox? I have some string items that are too long to display on a single line and I would like users to be able to scroll horizontally so they are see the end of each line.

Or is there a way to display a single item over multiple lines?


13
Help requests / v0.7 listbox auto scrolling
« on: 12 September 2015, 04:00:03 »
Hi Texus,

In a chatbox, when I add a new line, if it is larger than the size of the chatbox, it automatically scrolls down.
However in a listbox, I do not get the same behaviour when I add a new item. I get the scrollbar fine and I can manually scroll up and down which is great.
Basically I want to use the listbox functionality of being able to select each line and call functions when a particular line is clicked. However I also want the chatbox functionality of autoscrolling when a new item is added.

Is there any flag on a listbox to enable this same behaviour?

14
Help requests / v0.7 listbox textsize
« on: 12 September 2015, 03:06:38 »
Hi Texus,

I cannot seem to locate a setTextSize method for a listbox - (i.e. chatbox has such a method so I was looking for something similiar).

I see there is a setItemHeight method but in the documents is says "This size is always a little big greater than the text size."

So is this what actually determines the text size in a listbox?

15
Help requests / v0.7 widget.conf syntax
« on: 07 September 2015, 09:28:46 »
Sorry for all of the v0.7 questions lately - I really do appreciate your help.

In v0.69 I had a button conf like below

Code: (cpp) [Select]

Button:
    NormalImage  = "../../images/icons/romeNationIcon_v2.png" (  56,  0,  48, 64)
    HoverImage   = "../../images/icons/romeNationIcon_v2.png" (  56,  65,  48, 64)
    DownImage    = "../../images/icons/romeNationIcon_v2.png" (  56,  129,  48, 64)
   
    TextColor          = (200, 200, 200)
    SeparateHoverImage = true

So in v0.7, I created a new section as below

Code: (cpp) [Select]

CustomButtonRomeAR {
    NormalImage  : "../../images/icons/romeNationIcon_v2.png" (  248,  0,  48, 64);
    HoverImage   : "../../images/icons/romeNationIcon_v2.png" (  248,  65,  48, 64);
    DownImage    : "../../images/icons/romeNationIcon_v2.png" (  248,  129,  48, 64);
    TextColorNormal : rgb(190, 190, 190);
    TextColorHover  : rgb(250, 250, 250);
    TextColorDown   : rgb(250, 250, 250);
}

however whenever I try to create a button with this section, it throws an error

Code: (cpp) [Select]
tgui::Button::Ptr button = theme->load(passed_themeSection);

where passed_themeSection = "CustomButtonRomeHI"

I am assuming I've gotten the syntax incorrect here?

Sorry error is:

"tgui::Exception at memory location 0x0014CF08."

It breaks into WidgetConverter.hpp at line 65

Code: (cpp) [Select]

      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// @brief Cast the widget to the required type
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        template <class T>
        operator std::shared_ptr<T>()
        {
            std::shared_ptr<T> result = std::dynamic_pointer_cast<T>(m_widget);

            if (result == nullptr)
                throw Exception{"Value returned by Theme::load must match type of variable!"};

            return result;
        }


Pages: [1] 2 3