bool dropdown_widget::handle_event(const SDL_Event& event, bool claimed) { SDL_Event ev = event; normalize_event(&ev); if(claimed) { return claimed; } if(type_ == DROPDOWN_COMBOBOX && editor_) { if(editor_->handle_event(ev, claimed)) { return true; } } if(dropdown_menu_ && dropdown_menu_->visible()) { if(dropdown_menu_->handle_event(ev, claimed)) { return true; } } if(event.type == SDL_MOUSEMOTION) { return handle_mousemotion(event.motion, claimed); } else if(event.type == SDL_MOUSEBUTTONDOWN) { return handle_mousedown(event.button, claimed); } else if(event.type == SDL_MOUSEBUTTONUP) { return handle_mouseup(event.button, claimed); } return claimed; }
bool selector_widget::handle_event(const SDL_Event& event, bool claimed) { SDL_Event ev = event; normalize_event(&ev); if(claimed) { return claimed; } if(event.type == SDL_MOUSEMOTION) { return handle_mousemotion(event.motion, claimed); } else if(event.type == SDL_MOUSEBUTTONDOWN) { return handle_mousedown(event.button, claimed); } else if(event.type == SDL_MOUSEBUTTONUP) { return handle_mouseup(event.button, claimed); } else if(event.type == SDL_KEYDOWN) { const SDL_Keycode key = event.key.keysym.sym; if(key == SDLK_LEFT || key == SDLK_PAGEUP) { select_left(); } else if(key == SDLK_RIGHT || key == SDLK_PAGEDOWN) { select_right(); } else if(key == SDLK_HOME) { if(!list_.empty()) { set_selection(0); } } else if(key == SDLK_END) { if(!list_.empty()) { set_selection(list_.size()-1); } } else if(key == SDLK_RETURN && on_select_) { on_select_(list_[current_selection_].first); } } return claimed; }
bool dropdown_widget::handle_event(const SDL_Event& event, bool claimed) { SDL_Event ev = event; switch(ev.type) { case SDL_MOUSEMOTION: { ev.motion.x -= x() & ~1; ev.motion.y -= y() & ~1; break; } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { ev.button.x -= x() & ~1; ev.button.y -= y() & ~1; break; } } if(claimed) { return claimed; } if(type_ == DROPDOWN_COMBOBOX && editor_) { if(editor_->handle_event(ev, claimed)) { return true; } } if(dropdown_menu_ && dropdown_menu_->visible()) { if(dropdown_menu_->handle_event(ev, claimed)) { return true; } } if(has_focus() && dropdown_menu_) { if(event.type == SDL_KEYDOWN && (ev.key.keysym.sym == controls::get_keycode(controls::CONTROL_ATTACK) || ev.key.keysym.sym == controls::get_keycode(controls::CONTROL_JUMP))) { claimed = true; dropdown_menu_->set_visible(!dropdown_menu_->visible()); } } if(event.type == SDL_MOUSEMOTION) { return handle_mousemotion(event.motion, claimed); } else if(event.type == SDL_MOUSEBUTTONDOWN) { return handle_mousedown(event.button, claimed); } else if(event.type == SDL_MOUSEBUTTONUP) { return handle_mouseup(event.button, claimed); } return claimed; }
int main(int argc, char* argv[]) { msgbuf = malloc(256); msgbuf[0] = 0; currentLayer = 0; cache = true; int longIndex; int opt; do { opt = getopt_long(argc, argv, optString, longOpts, &longIndex); if (opt != -1) { switch( opt ) { case 'l': currentLayer = strtol(optarg, NULL, 10); break; case 'w': extrusionWidth = strtof(optarg, NULL); break; case 'n': printf("DISABLING CACHE\n"); cache = false; break; case 'h': /* fall-through is intentional */ case '?': display_usage(); break; case 0: /* long option without a short arg */ //if( strcmp( "randomize", longOpts[longIndex].name ) == 0 ) { // globalArgs.randomized = 1; //} break; default: /* You won't actually get here. */ break; } } } while (opt != -1); if (optind >= argc) display_usage(); int fd = open(argv[optind], 0); if (fd == -1) die("Open ", argv[optind]); struct stat filestats; if (fstat(fd, &filestats) == -1) die("fstat ", argv[optind]); filesz = filestats.st_size; printf("File is %d long\n", filesz); #ifdef __linux__ gcodefile = mmap(NULL, filesz, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); #elif defined __APPLE__ gcodefile = mmap(NULL, filesz, PROT_READ, MAP_PRIVATE, fd, 0); #else #error "don't know how to mmap on this system!" #endif if (gcodefile == MAP_FAILED) die("mmap ", argv[optind]); gcodefile_end = &gcodefile[filesz]; busy = BUSY_SCANFILE; scanLines(); if (currentLayer >= layerCount) currentLayer = layerCount - 1; //for (int i = 0; i < layerCount; i++) // printf("Layer %3d starts at %7d and is %7d bytes long\n", i, layer[i].index - gcodefile, layer[i].size); Running = true; Surf_Display = NULL; if (SDL_Init(SDL_INIT_EVERYTHING) < 0) die("SDL_init", ""); if (FcInitLoadConfigAndFonts() == ((void *) FcTrue)) die("FontConfig Init",""); // from http://www.spinics.net/lists/font-config/msg03050.html FcPattern *pat, *match; FcResult result; char *file; int index; pat = FcPatternCreate(); FcPatternAddString(pat, FC_FAMILY, (FcChar8 *) "Mono"); FcConfigSubstitute(NULL, pat, FcMatchPattern); FcDefaultSubstitute(pat); match = FcFontMatch(NULL, pat, &result); FcPatternGetString(match, FC_FILE, 0, (FcChar8 **) &file); FcPatternGetInteger(match, FC_INDEX, 0, &index); font = ftglCreateExtrudeFont(file); if (!font) die("FTGL createFont", ""); FcPatternDestroy (match); FcPatternDestroy (pat); #ifdef OPENGL transX = transY = 0.0; zoomFactor = 1.0; resize(600, 600); #else viewPortL = viewPortT = 0.0; viewPortR = viewPortB = 200.0; zoomFactor = 3.0; resize(viewPortR * zoomFactor, viewPortB * zoomFactor); #endif SDL_WM_SetCaption("gcodeview", 0); drawLayer(currentLayer); layerVelocity = 0; timerIdle = SDL_AddTimer(20, &timerCallback, (void *) TIMER_IDLE); SDL_Event Event; while(Running != false) { if (busy) { Event.type = SDL_NOEVENT; SDL_PollEvent(&Event); } else { if (SDL_WaitEvent(&Event) == 0) die("SDL_WaitEvent", ""); } //SDL_RemoveTimer(timerIdle); switch (Event.type) { case SDL_NOEVENT: if (busy & BUSY_SCANFILE) { // TODO: scan next layer scanLine(); if ((busy & BUSY_SCANFILE) == 0) { if (cache) { printf("File scanned, rendering...\n"); busy = BUSY_RENDER; } else { printf("File scanned.\n"); busy = 0; } } } else if ((busy & BUSY_RENDER) && cache) { bool allRendered = true; int i; // TODO: render next layer in background for (i = 0; i < layerCount; i++) { if (layer[i].glList == 0) { layer[i].glList = glGenLists(1); glNewList(layer[i].glList, GL_COMPILE); glBegin(GL_QUADS); for (int j = SHADOW_LAYERS; j >= 1; j--) { if (i - j > 0) render_layer(i - j, SHADOW_ALPHA - (j - 1) * (SHADOW_ALPHA / SHADOW_LAYERS)); } render_layer(i, 1.0); glEnd(); glEndList(); layer[i].flags |= LD_LISTGENERATED; allRendered = false; break; } } if (allRendered) { printf("All %d layers rendered\n", i); busy &= ~BUSY_RENDER; } } break; case SDL_QUIT: Running = false; break; case SDL_VIDEORESIZE: resize(Event.resize.w, Event.resize.h); break; case SDL_VIDEOEXPOSE: render(); break; case SDL_MOUSEBUTTONDOWN: handle_mousedown(Event.button); break; case SDL_MOUSEBUTTONUP: handle_mouseup(Event.button); break; case SDL_MOUSEMOTION: handle_mousemove(Event.motion); break; case SDL_ACTIVEEVENT: // lose or gain focus break; case SDL_KEYDOWN: handle_keydown(Event.key); break; case SDL_KEYUP: handle_keyup(Event.key); break; case SDL_USEREVENT: handle_userevent(Event.user); break; default: printf("SDL Event %d\n", Event.type); break; } //idle code //if (busy) // timerIdle = SDL_AddTimer(20, &timerCallback, (void *) TIMER_IDLE); } if (timerKeyRepeat) SDL_RemoveTimer(timerKeyRepeat); if (timerDragRender) SDL_RemoveTimer(timerDragRender); free(layer); SDL_FreeSurface(Surf_Display); SDL_Quit(); return 0; }