main: add tray
This commit is contained in:
37
main.cpp
37
main.cpp
@@ -8,6 +8,35 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Tray {
|
||||
private:
|
||||
SDL_Tray *tray;
|
||||
SDL_TrayMenu *menu;
|
||||
SDL_TrayEntry *entry_open;
|
||||
SDL_TrayEntry *entry_quit;
|
||||
public:
|
||||
Tray(SDL_Surface *icon, DlgMainMenu *dlg_menu) {
|
||||
tray = SDL_CreateTray(icon, "Rousku");
|
||||
menu = SDL_CreateTrayMenu(tray);
|
||||
entry_open = SDL_InsertTrayEntryAt(menu, -1, "Avaa valikko", SDL_TRAYENTRY_BUTTON);
|
||||
entry_quit = SDL_InsertTrayEntryAt(menu, -1, "Sulje Rousku", SDL_TRAYENTRY_BUTTON);
|
||||
SDL_SetTrayEntryCallback(entry_open, callback_open, dlg_menu);
|
||||
SDL_SetTrayEntryCallback(entry_quit, callback_quit, NULL);
|
||||
}
|
||||
~Tray() {
|
||||
SDL_DestroyTray(tray);
|
||||
}
|
||||
static void callback_open(void *userdata, SDL_TrayEntry *invoker) {
|
||||
DlgMainMenu *dlg_menu = (DlgMainMenu *) userdata;
|
||||
dlg_menu->setExit(false);
|
||||
}
|
||||
static void callback_quit(void *userdata, SDL_TrayEntry *invoker) {
|
||||
SDL_Event e;
|
||||
e.type = SDL_EVENT_QUIT;
|
||||
SDL_PushEvent(&e);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (!SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO)) {
|
||||
SDL_Log("Could not init SDL %s", SDL_GetError());
|
||||
@@ -73,6 +102,9 @@ int main(int argc, char **argv) {
|
||||
// Get MOUSE_DOWN event when clicking unfocused window
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||
|
||||
SDL_Surface *icon_sfe = rousku.getPreviewSurface();
|
||||
Tray *tray = new Tray(icon_sfe, dlg_menu);
|
||||
|
||||
while (!dlg_menu->isAppExit()) {
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
@@ -128,6 +160,9 @@ int main(int argc, char **argv) {
|
||||
string changed_setting = dlg_menu->getChangedSetting();
|
||||
if (changed_setting == "skin_list") {
|
||||
rousku.readSkin(dlg_menu->getSkin());
|
||||
icon_sfe = rousku.getPreviewSurface();
|
||||
delete tray;
|
||||
tray = new Tray(icon_sfe, dlg_menu);
|
||||
rousku.setSpecialState(drop);
|
||||
}
|
||||
Uint64 delay = rousku.step(SDL_GetTicks(), press);
|
||||
@@ -189,6 +224,8 @@ int main(int argc, char **argv) {
|
||||
SDL_Delay(delay);
|
||||
}
|
||||
|
||||
delete tray;
|
||||
|
||||
SDL_DestroyWindow(sdl_window);
|
||||
SDL_Quit();
|
||||
TTF_Quit();
|
||||
|
||||
Reference in New Issue
Block a user