console init_console(int x, int y, int w, int h) { console c; button console_btn, chat_btn, log_btn; window_load_textures(); console_load_textures(); add_texture("/usr/local/share/vektor/ui/ui_content.texture", &texture_cpane); add_texture("/usr/local/share/vektor/ui/ui_input_bar.texture", &texture_input_bar); // allocate and initialize a new console c = calloc(1, sizeof(*c)); c->x = x; c->y = y; c->w = w; c->h = h; c->active = 1; user = getenv("USER"); main_console = c; c->win = add_window((float)x,(float)y,w,h); hide_window(c->win); // add tab bar and buttons c->tabs = add_tabbar(10, -26, 502, 36); // add textboxes c->tb_out = textbox_new(25, -80, 57, 16, 500000); c->tb_in = textbox_new(25, -300, 59, 1, 1000); console_data = c->tb_out->data; chat_data = calloc(500000,1); set_input(c->tb_in->data, 1000); textbox_set_text(c->tb_in, "v$ "); // add textbox listeners add_listener(&console_return, c->tb_in, vektor_event_return); add_listener(&chat_recv, c->tb_out, vektor_event_net_recv); // add content pane //c->cpane = add_bitmap(10, -65, 502, 262, &texture_cpane); //c->in_bar = add_bitmap(20, -293, 482, 25, &texture_input_bar); // add buttons console_btn = add_button(x + 5, y + 5, 87, 26, &texture_btn_console); chat_btn = add_button(x + 10 + 87, y + 5, 87, 26, &texture_btn_chat); log_btn = add_button(x + 15 + 174, y + 5, 87, 26, &texture_btn_log); // set button actions console_btn->action = &set_console; chat_btn->action = &set_chat; log_btn->action = &set_log; // attach buttons to tab bar tabbar_add_tab(c->tabs, console_btn); tabbar_add_tab(c->tabs, chat_btn); tabbar_add_tab(c->tabs, log_btn); // attach objects to window window_addchild(c->win, c->tabs, c->tabs->draw, c->tabs->move, c->tabs->resize, c->tabs->remove); //window_addchild(c->win, c->cpane, c->cpane->draw, c->cpane->move, c->cpane->resize, c->cpane->remove); //window_addchild(c->win, c->in_bar, c->in_bar->draw, c->in_bar->move, c->in_bar->resize, c->in_bar->remove); window_addchild(c->win, c->tb_out, c->tb_out->scene_data.draw, c->tb_out->move, c->tb_out->resize, c->tb_out->scene_data.remove); window_addchild(c->win, c->tb_in, c->tb_in->scene_data.draw, c->tb_in->move, c->tb_in->resize, c->tb_in->scene_data.remove); //add_object_2d(c, NULL, &draw_console, NULL, &free_console); keybind_add(c, &toggle_console, NULL, vektor_key_f1); toggle_console(c); return c; }
// returns an ASCII character from the keyboard; will wait here forever until a key is pressed // not all characters are supported char con_getkey() { unsigned char result = 0; SDL_Event event; #ifdef CPU_DEBUG con_flush(); // print current line #endif SDL_EnableUNICODE(1); while (!result && !get_quitflag()) { if (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_BACKSPACE: result = 8; break; case SDLK_RETURN: result = 13; break; case SDLK_ESCAPE: result = 27; break; case SDLK_BACKQUOTE: #ifdef CPU_DEBUG toggle_console(); #endif result = 0; break; default: result = (unsigned char) event.key.keysym.unicode; break; } break; //WO: make any joystick button = enter, // so lazy folks (like me) can pass the issues screen // without going to the keyboard :) case SDL_JOYBUTTONDOWN: #ifndef GP2X result = 13; #else // one of the buttons needs to exit the emulator switch(event.jbutton.button) { // L is #10, and it will map to escape for now ... case 10: result = 27; break; case 15: // Y (hide console) #ifdef CPU_DEBUG toggle_console(); #endif result = 0; break; default: result = 13; break; } break; #endif break; case SDL_QUIT: set_quitflag(); break; default: break; } } // end if check_console_refresh(); SDL_Delay(1); // sleep to be CPU friendly #ifdef UNIX // NOTE : non-blocking I/O should be enabled, so we will get EOF if there is nothing waiting for us ... int iRes = getchar(); if (iRes != EOF) { result = (unsigned char) iRes; } #endif } // end while SDL_EnableUNICODE(0); return(result); }