/** Set the window border color. * \param L The Lua VM state. * \param window The window object. * \return The number of elements pushed on stack. */ static int luaA_window_set_border_color(lua_State *L, window_t *window) { size_t len; const char *color_name = luaL_checklstring(L, -1, &len); if(color_name && color_init_reply(color_init_unchecked(&window->border_color, color_name, len))) { xwindow_set_border_color(window_get(window), &window->border_color); luaA_object_emit_signal(L, -3, "property::border_color", 0); } return 0; }
void window_list_move_after(Window id, Window sibling) { window_t *window, *before; window = window_list_remove(id); before = window_get(sibling); window->prev = before; window->next = before->next; if (before->next != NULL) before->next->prev = window; before->next = window; }
void window_list_move_before(Window id, Window sibling) { window_t *window, *after; window = window_list_remove(id); after = window_get(sibling); window->prev = after->prev; window->next = after; if (after->prev != NULL) after->prev->next = window; after->prev = window; }
/** Get or set mouse buttons bindings on a window. * \param L The Lua VM state. * \return The number of elements pushed on the stack. */ static int luaA_window_buttons(lua_State *L) { window_t *window = luaA_checkudata(L, 1, &window_class); if(lua_gettop(L) == 2) { luaA_button_array_set(L, 1, 2, &window->buttons); luaA_object_emit_signal(L, 1, "property::buttons", 0); xwindow_buttons_grab(window_get(window), &window->buttons); xwindow_buttons_grab(window->window, &window->buttons); } return luaA_button_array_get(L, 1, &window->buttons); }
/** * @brief Unsets the key. */ static void opt_unsetKey( unsigned int wid, char *str ) { (void) str; unsigned int parent; /* Unsets the keybind. */ input_setKeybind( opt_selectedKeybind, KEYBIND_NULL, 0, 0 ); /* Close window. */ window_close( wid, NULL ); /* Update parent window. */ parent = window_get("Keybindings"); window_destroyWidget( parent, "lstKeybinds" ); menuKeybinds_genList( parent ); menuKeybinds_update( parent, NULL ); }
/** Set a window border width. * \param L The Lua VM state. * \param idx The window index. * \param width The border width. */ void window_set_border_width(lua_State *L, int idx, int width) { window_t *window = luaA_checkudata(L, idx, &window_class); if(width == window->border_width || width < 0) return; if(window->window) xcb_configure_window(globalconf.connection, window_get(window), XCB_CONFIG_WINDOW_BORDER_WIDTH, (uint32_t[]) { width }); window->border_width = width; luaA_object_emit_signal(L, idx, "property::border_width", 0); }
void window_configure(XConfigureEvent event) { window_t *window = window_get(event.window); if (window == NULL) return; window->x = event.x; window->y = event.y; window->width = event.width; window->height = event.height; if (event.above != None) { window_list_remove(event.window); window_list_append(event.window); } }
void window_out_commit( window_t* window) { debug_print("window_out_commit()\n"); window_lock(window); if (!window->buffer->size) { window->size = 0; window->head = 0; window->tail = 0; } else { window->size = MIN(window->max_size, window->buffer->size); window->head = queue_head(window->buffer); window->tail = window_get(window, window->size-1); //printf("head: %p, tail: %p\n", window->head, window->tail); if (!window->tail || !window->head) { return; } queue_node_t* node = window->head; packet_t* packet = (packet_t*) node->data; while(node != window->tail) { packet = (packet_t*) node->data; if (!packet->transmission_time) { channel_send_packet(packet); } node = node->next; } if (node == window->tail) { if (!packet->transmission_time) { channel_send_packet(packet); } } } window_unlock(window); success_print("window_out_commit() succeed\n"); }
/** * @brief Loads a GUI. * * @param wdw Window triggering function. * @param str Unused. */ static void setgui_load( unsigned int wdw, char *str ) { (void)str; char *gui; int wid; wid = window_get( "Select GUI" ); gui = toolkit_getList( wid, "lstGUI" ); if (strcmp(gui,"None") == 0) return; /* Set the GUI. */ if (player.gui != NULL) free( player.gui ); player.gui = strdup( gui ); /* Close menus before loading for proper rendering. */ setgui_close(wdw, NULL); /* Load the GUI. */ gui_load( gui_pick() ); }
/* called only by initial setup */ int mix_load(int outch){ int i; mix_set=calloc(input_ch,sizeof(*mix_set)); mixpanel_active=calloc(input_ch,sizeof(*mixpanel_active)); mixpanel_visible=calloc(input_ch,sizeof(*mixpanel_visible)); memset(&ms,0,sizeof(ms)); ms.prev=calloc(input_ch,sizeof(*ms.prev)); ms.curr=calloc(input_ch,sizeof(*ms.curr)); ms.cacheP=malloc(input_ch*sizeof(*ms.cacheP)); ms.cachePP=malloc(input_ch*sizeof(*ms.cachePP)); ms.cachePA=malloc(input_ch*sizeof(*ms.cachePA)); ms.cachePPA=malloc(input_ch*sizeof(*ms.cachePPA)); ms.cachePB=malloc(input_ch*sizeof(*ms.cachePB)); ms.cachePPB=malloc(input_ch*sizeof(*ms.cachePPB)); for(i=0;i<input_ch;i++) ms.cacheP[i]=malloc(input_size*sizeof(**ms.cacheP)); for(i=0;i<input_ch;i++) ms.cachePP[i]=malloc(input_size*sizeof(**ms.cachePP)); for(i=0;i<input_ch;i++) ms.cachePA[i]=malloc(input_size*sizeof(**ms.cachePA)); for(i=0;i<input_ch;i++) ms.cachePPA[i]=malloc(input_size*sizeof(**ms.cachePPA)); for(i=0;i<input_ch;i++) ms.cachePB[i]=malloc(input_size*sizeof(**ms.cachePB)); for(i=0;i<input_ch;i++) ms.cachePPB[i]=malloc(input_size*sizeof(**ms.cachePPB)); ms.out.channels=outch; ms.out.data=malloc(outch*sizeof(*ms.out.data)); for(i=0;i<outch;i++) ms.out.data[i]=malloc(input_size*sizeof(**ms.out.data)); window=window_get(1,input_size); return 0; }
/** * @brief Deletes an old game. * @param wdw Window to delete. * @param str Unused. */ static void load_menu_delete( unsigned int wdw, char *str ) { (void)str; char *save, path[PATH_MAX]; int wid; wid = window_get( "Load Game" ); save = toolkit_getList( wid, "lstSaves" ); if (strcmp(save,"None") == 0) return; if (dialogue_YesNo( "Permanently Delete?", "Are you sure you want to permanently delete '%s'?", save) == 0) return; snprintf( path, PATH_MAX, "%ssaves/%s.ns", nfile_basePath(), save ); remove(path); /* remove is portable and will call unlink on linux. */ /* need to reload the menu */ load_menu_close(wdw, NULL); load_game_menu(); }
/** * @brief Loads a new game. * @param wdw Window triggering function. * @param str Unused. */ static void load_menu_load( unsigned int wdw, char *str ) { (void)str; char *save, path[PATH_MAX]; int wid; wid = window_get( "Load Game" ); save = toolkit_getList( wid, "lstSaves" ); if (strcmp(save,"None") == 0) return; snprintf( path, PATH_MAX, "%ssaves/%s.ns", nfile_basePath(), save ); /* Close menus before loading for proper rendering. */ load_menu_close(wdw, NULL); menu_main_close(); if (load_game( path )) { menu_main(); load_game_menu(); } }
/** * @brief Tries to set the key from an event. */ static int opt_setKeyEvent( unsigned int wid, SDL_Event *event ) { unsigned int parent; KeybindType type; int key; SDLMod mod; const char *str; /* See how to handle it. */ switch (event->type) { case SDL_KEYDOWN: key = event->key.keysym.sym; /* If control key make player hit twice. */ if (((key == SDLK_NUMLOCK) || (key == SDLK_CAPSLOCK) || (key == SDLK_SCROLLOCK) || (key == SDLK_RSHIFT) || (key == SDLK_LSHIFT) || (key == SDLK_RCTRL) || (key == SDLK_LCTRL) || (key == SDLK_RALT) || (key == SDLK_LALT) || (key == SDLK_RMETA) || (key == SDLK_LMETA) || (key == SDLK_LSUPER) || (key == SDLK_RSUPER)) && (opt_lastKeyPress != key)) { opt_lastKeyPress = key; return 0; } type = KEYBIND_KEYBOARD; if (window_checkboxState( wid, "chkAny" )) mod = KMOD_ALL; else mod = event->key.keysym.mod & ~(KMOD_CAPS | KMOD_NUM | KMOD_MODE); /* Set key. */ opt_lastKeyPress = key; break; case SDL_JOYAXISMOTION: if (event->jaxis.value > 0) type = KEYBIND_JAXISPOS; else if (event->jaxis.value < 0) type = KEYBIND_JAXISNEG; else return 0; /* Not handled. */ key = event->jaxis.axis; mod = KMOD_ALL; break; case SDL_JOYBUTTONDOWN: type = KEYBIND_JBUTTON; key = event->jbutton.button; mod = KMOD_ALL; break; /* Not handled. */ default: return 0; } /* Warn if already bound. */ str = input_keyAlreadyBound( type, key, mod ); if ((str != NULL) && strcmp(str, opt_selectedKeybind)) dialogue_alert( "Key '%s' overlaps with key '%s' that was just set. " "You may want to correct this.", str, opt_selectedKeybind ); /* Set keybinding. */ input_setKeybind( opt_selectedKeybind, type, key, mod ); /* Close window. */ window_close( wid, NULL ); /* Update parent window. */ parent = window_get("Keybindings"); window_destroyWidget( parent, "lstKeybinds" ); menuKeybinds_genList( parent ); menuKeybinds_update( parent, NULL ); return 0; }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w, h, x, y, rw; /* Not under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); window_handleKeys( wid, map_keyHandler ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * [Autonav] * [ Find ] * [ Close ] */ x = -70; /* Right column X offset. */ y = -20; rw = ABS(x) + 60; /* Right column indented width maximum. */ /* System Name */ window_addText( wid, -90 + 80, y, 160, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); y -= 10; /* Faction image */ window_addImage( wid, -90 + 32, y - 32, 0, 0, "imgFaction", NULL, 0 ); y -= 64 + 10; /* Faction */ window_addText( wid, x, y, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_addText( wid, x, y, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_addText( wid, x, y, 90, 20, 0, "txtSPresence", &gl_smallFont, &cDConsole, "Presence:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtPresence", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_addText( wid, x, y, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 150, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_addText( wid, x, y, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Find button */ window_addButton( wid, -20 - (BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnFind", "Find", map_inputFind ); /* Autonav button */ window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnAutonav", "Autonav", player_autonavStartWindow ); /* * Bottom stuff * * [+] [-] Nebula, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-200, h-100, 1. ); /* Reset zoom. */ map_update( wid ); /* * Disable Autonav button if player lacks fuel. */ if ((player.p->fuel < HYPERSPACE_FUEL) || pilot_isFlag( player.p, PILOT_NOJUMP)) window_disableButton( wid, "btnAutonav" ); }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w,h; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * * [Close] */ /* System Name */ window_addText( wid, -20, -20, 100, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); /* Faction */ window_addImage( wid, -20-64, -60-64, "imgFaction", NULL, 0 ); window_addText( wid, -20, -60, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); /* Standing */ window_addText( wid, -20, -100, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, -20, -100-gl_smallFont.h-5, 80, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); /* Security. */ window_addText( wid, -20, -140, 90, 20, 0, "txtSSecurity", &gl_smallFont, &cDConsole, "Security:" ); window_addText( wid, -20, -140-gl_smallFont.h-5, 80, 100, 0, "txtSecurity", &gl_smallFont, &cBlack, NULL ); /* Planets */ window_addText( wid, -20, -180, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, -20, -180-gl_smallFont.h-5, 80, 100, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); /* Services */ window_addText( wid, -20, -220, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, -20, -220-gl_smallFont.h-5, 80, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* * Bottom stuff * * [+] [-] Nebula, Asteroids, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-150, h-100, 1. ); /* Reset zoom. */ map_update( wid ); }
/** * @brief Closes the main menu. */ void menu_main_close (void) { window_destroy( window_get("Main Menu") ); menu_Close(MENU_MAIN); }