#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>

class Player {
    Fl_Box *status;

public:
    Player(Fl_Box *a_status) : status(a_status) {}

    void play()  { status->label("Playing"); }
    void pause() { status->label("Paused"); }
    void stop()  { status->label("Stopped"); }
};

// Pointer to any Player method returning void
// and taking no arguments.
typedef void (Player::*Action)();

struct Command {
    Player *player;
    Action action;
};

// One callback handles all three buttons.
void button_cb(Fl_Widget *, void *data)
{
    Command *cmd = static_cast<Command*>(data);
    (cmd->player->*(cmd->action))();
}

int main()
{
    Fl_Window window(340, 140, "Music Player");

    Fl_Box status(20, 15, 300, 40, "Stopped");

    Fl_Button play(20, 80, 90, 35, "Play");
    Fl_Button pause(125, 80, 90, 35, "Pause");
    Fl_Button stop(230, 80, 90, 35, "Stop");

    window.end();

    Player player(&status);

    Command commands[] = {
        { &player, &Player::play },
        { &player, &Player::pause },
        { &player, &Player::stop }
    };

    play.callback(button_cb, &commands[0]);
    pause.callback(button_cb, &commands[1]);
    stop.callback(button_cb, &commands[2]);

    window.show();
    return Fl::run();
}
