PDA

View Full Version : Slots Not Triggering



RandomClown
08-31-2014, 11:50 PM
I'm trying to make a simple window that closes. It wont close. It wont trigger any slots I bind.
I've spent hours looking at this with a banana (http://www.rtsoft.com/forums/member.php?141866-BananasGoMoo) but we cant figure out why.

I based this code on the sample. The steps were:

Call the 3 setups
Create the DisplayWindow(desc)
Connect the window.sig_window_close()

I believe thats all for the setup. KeepAlive::process(0) is suppose to raise the events right?




#include <Windows.h>
#include "clanlib.h"

using namespace clan;


enum EngineState{
ES_notready,
ES_ready,
ES_exitrequest,
ES_exitforced,
};


class Engine{
public: // Constructors

Engine(){
state=ES_notready;
}


public: // Public methods

void initengine(){
DisplayWindowDescription desc;
desc.set_title("thing");
desc.set_size(Size(640, 480), true);
desc.set_allow_resize(false);
window=DisplayWindow(desc);

canvas=Canvas(window);
// Because we are using the alpha channel on fonts, we must disable subpixel rendering
FontDescription font_desc;
font_desc.set_typeface_name("tahoma");
font_desc.set_height(16);
font_desc.set_subpixel(false);
Font fall_font(canvas, font_desc);
fall_font=Font(canvas, font_desc);

// sf::Image icon;
// bool good=icon.loadFromFile("Media/Icons/Play 32.png");
// if(good) sfwindow->setIcon(32, 32, icon.getPixelsPtr());

// Connect the Window close event
Slot slot_quit = window.sig_window_close().connect(this, &Engine::onexit);

// Connect a keyboard handler to on_key_up()
Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().conn ect(this, &Engine::onkeyup);


state=ES_ready;
}

// Return the state of the engine
EngineState getstate(){
return state;
}

// Public call to render.
void draw(){
window.flip();
}



private: // Private methods

// Application close request
void onexit(){
state=ES_exitrequest;
}


// What to do when a key is pressed
void onkeyup(const InputEvent &key){
switch(key.id){
case keycode_escape:
state=ES_exitrequest;
break;
}
}

private:

DisplayWindow window;
Canvas canvas;

EngineState state;
};


int main(const std::vector<std::string> &args){
Engine engine;

// Initialize ClanLib base components
SetupCore setup_core;

// Initialize the ClanLib display component
SetupDisplay setup_display;

// Setup display devices
SetupD3D setup_d3d;
SetupGL setup_gl;


engine.initengine();

while(engine.getstate()!=ES_exitrequest && engine.getstate()!=ES_exitforced){
KeepAlive::process(0);
engine.draw();
}

return 0;
}

Application app(&main);

rombust
09-01-2014, 07:12 AM
In "void initengine()"
"Slot slot_quit" is a local variable, thus when the function exits the slot will disconnect.