void render_exit_menu(exit_menu_t *state, float cursor_x, float cursor_y) { // Update center of cursor set_cursor_position(state->cursor_state, cursor_x, cursor_y); // Check if anything selected check_cursor_in_image(state->cursor_state, state->mandelbrot_state); check_cursor_in_image(state->cursor_state, state->sph_state); check_cursor_in_image(state->cursor_state, state->terminal_state); // Draw background rectangle float center[2] = {0.0f, 0.0f}; float gl_dims[2] = {2.0f, 0.7f}; float background_color[4] = {1.0f, 1.0f, 1.0f, 0.8f}; render_rectangle(state->rectangle_state, center, gl_dims, background_color); // Draw mandelbrot image draw_image(state->mandelbrot_state); // Draw terminal image draw_image(state->terminal_state); // Draw SPH image draw_image(state->sph_state); // Draw cursor draw_cursor(state->cursor_state); }
int main (int argc, char **argv) { SDL_Surface *screen = NULL; SDL_Window *window = NULL; if (startup("Space Shooter")) { SDL_Surface *background = load_image("assets/background.png"); SDL_Surface *ship = load_image("assets/captain.png"); draw_image(background, 0, 0); draw_image(ship, 100, 100); SDL_UpdateWindowSurface(g_window); #if __EMSCRIPTEN__ #else SDL_Delay(5000); #endif SDL_FreeSurface(background); SDL_FreeSurface(ship); } else { printf("Could not initialise SDL\n"); } SDL_DestroyWindow(g_window); SDL_Quit(); return 0; }
/* draw_pipe - draws all active pipes on the screen */ void draw_pipe() { int i, j, len = 0, actives[MAX_PIPES], offset = 12, bottom_height, cur_ind; for (i = 0; i < MAX_PIPES; i++) if (pipes[i].active) actives[len++] = i; for (j = 0; j < len; j++) { cur_ind = actives[j]; bottom_height = (GROUND_HEIGHT - offset - (PIPE_GAP + pipes[cur_ind].height * pipes[cur_ind].pipe->h)) / pipes[cur_ind].pipe->h; for (i = 0; i < pipes[cur_ind].height - 2; i++) { draw_image(pipes[cur_ind].pipe, pipes[cur_ind].x, i * pipes[cur_ind].pipe->h); } for (i = pipes[cur_ind].height - 2; i <= pipes[cur_ind].height; i++) { draw_image(pipes[cur_ind].pipe_top, pipes[cur_ind].x - 2, i * pipes[cur_ind].pipe->h - 1); } for (i = 0; i < bottom_height - 2; i++) { draw_image(pipes[cur_ind].pipe, pipes[cur_ind].x, GROUND_HEIGHT - offset - i * pipes[cur_ind].pipe->h); } for (i = bottom_height - 2; i <= bottom_height; i++) { draw_image(pipes[cur_ind].pipe_top, pipes[cur_ind].x - 2, GROUND_HEIGHT - offset - i * pipes[cur_ind].pipe->h - 1); } } }
static void othello_color_draw(PzWidget *wid, ttk_surface srf) { unsigned char xline, yline, c; int x, y, step, startx, endx, size; #ifdef SDL ttk_fillrect(srf, 0,0, wid->w, wid->h, ttk_ap_getx("window.bg")->color); #endif step = (wid->h / 8); size = step * 8; startx = (wid->w - wid->h) / 2; endx = startx + size; ttk_fillrect(srf, startx,0, endx, size, BGCOLOR); for (x = 0; x < 9; ++x) { int mod = (size / 8) * x; ttk_line(srf, startx, mod, endx, mod, 0x000000); ttk_line(srf, startx + mod, 0, startx + mod, size, 0x000000); } yline = 0; for (c = 0; c < 64; c++) { xline = c % 8; x = xline * step + step/2 + startx; y = yline * step + step/2 + 0; if (_othello->b_set & (1ULL << c)) { if (_othello->board & (1ULL << c)) draw_image(_othello->black, srf, x, y); else draw_image(_othello->white, srf, x, y); } else if (_othello->cur_bit == c) draw_image(_othello->selection, srf, x, y); if (xline == 7) yline++; } }
int main (int argc, char **argv) { HPDF_Doc pdf; HPDF_Font font; HPDF_Page page; char fname[256]; HPDF_Destination dst; strcpy (fname, argv[0]); strcat (fname, ".pdf"); pdf = HPDF_New (error_handler, NULL); if (!pdf) { printf ("error: cannot create PdfDoc object\n"); return 1; } /* error-handler */ if (setjmp(env)) { HPDF_Free (pdf); return 1; } HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL); /* create default-font */ font = HPDF_GetFont (pdf, "Helvetica", NULL); /* add a new page object. */ page = HPDF_AddPage (pdf); HPDF_Page_SetWidth (page, 650); HPDF_Page_SetHeight (page, 500); dst = HPDF_Page_CreateDestination (page); HPDF_Destination_SetXYZ (dst, 0, HPDF_Page_GetHeight (page), 1); HPDF_SetOpenAction(pdf, dst); HPDF_Page_BeginText (page); HPDF_Page_SetFontAndSize (page, font, 20); HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70); HPDF_Page_ShowText (page, "JpegDemo"); HPDF_Page_EndText (page); HPDF_Page_SetFontAndSize (page, font, 12); draw_image (pdf, "rgb.jpg", 70, HPDF_Page_GetHeight (page) - 410, "24bit color image"); draw_image (pdf, "gray.jpg", 340, HPDF_Page_GetHeight (page) - 410, "8bit grayscale image"); /* save the document to a file */ HPDF_SaveToFile (pdf, fname); /* clean up */ HPDF_Free (pdf); return 0; }
void render_switcher(struct desktop *desktops) { tile_image(theme->tile_img, switcher_pos, switcher_width); if (!desktops) return; int ox = switcher_pos; int limgw, rimgw; ox += theme->switcher.space_gap; uint state; struct desktop *iter = desktops; state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE; if (!iter->next) draw_switcher_alone(state, ox, iter->width); else draw_switcher_left_corner(state, ox, iter->width); limgw = get_image_width(theme->switcher.left_corner_img[state]); rimgw = get_image_width(theme->switcher.right_img[state]); ox += limgw; draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw, theme->switcher.text_offset_x, theme->switcher.text_offset_y, iter->name, &theme->switcher.text_color[state]); ox += iter->width - limgw; if (!iter->next) return; iter = iter->next; state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE; if (theme->switcher.separator_img) { draw_image(theme->switcher.separator_img, ox); ox += get_image_width(theme->switcher.separator_img); } limgw = get_image_width(theme->switcher.left_img[state]); while (iter->next) { draw_switcher_middle(state, ox, iter->width); ox += limgw; draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw, theme->switcher.text_offset_x, theme->switcher.text_offset_y, iter->name, &theme->switcher.text_color[state]); ox += iter->width - limgw; iter = iter->next; state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE; if (theme->switcher.separator_img) { draw_image(theme->switcher.separator_img, ox); ox += get_image_width(theme->switcher.separator_img); } } rimgw = get_image_width(theme->switcher.right_corner_img[state]); draw_switcher_right_corner(state, ox, iter->width); ox += limgw; draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw, theme->switcher.text_offset_x, theme->switcher.text_offset_y, iter->name, &theme->switcher.text_color[state]); }
void Active::draw() { bool blend = (active_flags & TRANSPARENT) || blend_color.a < 255 || effect != Render::NONE; if (blend) { draw_image(image, x, y, blend_color, angle, x_scale, y_scale); return; } Render::disable_blend(); draw_image(image, x, y, blend_color, angle, x_scale, y_scale); Render::enable_blend(); }
void SWRenderDisplayWindowProvider::flip(int interval) { SWRenderGraphicContextProvider *gc_provider = static_cast<SWRenderGraphicContextProvider*>(gc.get_provider()); PixelCanvas *canvas = gc_provider->get_canvas(); #ifdef WIN32 HWND hwnd = window.get_hwnd(); HDC hdc = GetDC(hwnd); draw_image(hdc, get_viewport(), canvas->to_pixelbuffer()); ReleaseDC(hwnd, hdc); #elif !defined(__APPLE__) PixelBuffer &image = canvas->to_pixelbuffer(); draw_image(get_viewport(), image, Rect(0, 0, image.get_width(), image.get_height())); #endif if (interval == -1) interval = swap_interval; // use swap interval from the previous flip else swap_interval = interval; if (interval<=0) { flip_timer_set = false; } else { if (!flip_timer_set) { flip_last_time = System::get_time(); flip_timer_set = true; } else { ubyte64 current_time = System::get_time(); int time_diff = current_time - flip_last_time; interval *= 1000 / refresh_rate; int time_wait = interval - time_diff; if ( (time_wait > 0) && (time_wait < interval) ) { System::sleep(time_wait); flip_last_time = current_time + time_wait; } else { flip_last_time = current_time; } } } }
//-----------------------------------------------------------------// void monograph::draw_font(int16_t x, int16_t y, char code) { #ifdef KANJI_FONTS if(multi_byte_hi_) { uint8_t hi = multi_byte_hi_; multi_byte_hi_ = 0; if(-KANJI_FONT_WIDTH >= x || x >= fb_width_) return; if(kanji_mode_ == 0) { draw_image_P(x - FONT_WIDTH, y, &font6x12_[9 * 18], 6, 12); draw_image_P(x, y, &font6x12_[9 * 19], 6, 12); return; } const uint8_t* bitmap = scan_kanji_bitmap(hi, static_cast<uint8_t>(code)); if(bitmap != 0) { draw_image(x - FONT_WIDTH, y, bitmap, KANJI_FONT_WIDTH, KANJI_FONT_HWIGHT); } else { uint8_t* bitmap = alloc_kanji_bitmap(hi, static_cast<uint8_t>(code)); uint16_t pos = sjis_to_liner(hi, static_cast<uint8_t>(code)); if(read_kanji_bitmap(pos, bitmap)) { draw_image(x - FONT_WIDTH, y, bitmap, KANJI_FONT_WIDTH, KANJI_FONT_HEIGHT); } else { draw_image_P(x - FONT_WIDTH, y, &font6x12_[9 * 18], FONT_WIDTH, FONT_HEIGHT); draw_image_P(x, y, &font6x12_[9 * 19], FONT_WIDTH, FONT_HEIGHT); } } } else #endif { #ifdef LCD128X64 if(code >= 0) { if(-FONT_WIDTH >= x || static_cast<uint16_t>(x) >= fb_width_) { return; } draw_image_P(x, y, &font6x12_[(code << 3) + code], FONT_WIDTH, FONT_HEIGHT); } else if(static_cast<uint8_t>(code) >= 0x81 && static_cast<uint8_t>(code) <= 0x9f) { multi_byte_hi_ = code; } else if(static_cast<uint8_t>(code) >= 0xe0 && static_cast<uint8_t>(code) <= 0xef) { multi_byte_hi_ = code; } else { // 無効キャラクターの意味として multi_byte_hi_ = 0; if(-FONT_WIDTH >= x || static_cast<uint16_t>(x) >= fb_width_) return; draw_image_P(x, y, &font6x12_[(1 << 3)], FONT_WIDTH, FONT_HEIGHT); } #endif } }
void SWRenderDisplayWindowProvider::update(const Rect &rect) { SWRenderGraphicContextProvider *gc_provider = static_cast<SWRenderGraphicContextProvider*>(gc.get_provider()); PixelCanvas *canvas = gc_provider->get_canvas(); #ifdef WIN32 HWND hwnd = window.get_hwnd(); HDC hdc = GetDC(hwnd); draw_image(hdc, rect, canvas->to_pixelbuffer(), rect); ReleaseDC(hwnd, hdc); #elif !defined(__APPLE__) PixelBuffer &image = canvas->to_pixelbuffer(); draw_image(rect, image, rect); #endif }
/* **slide\_title\_in()**, **slide\_title\_out()** and * **bling\_title()** are used by the level * timeline to animate the title. * * We use cosine interpolation to slide the title in * and out, creating a smoother effect. * * **progress** will hold a value between 0 to 1 * based on the event progess/duration, making it ideal * for use with interpolation functions. */ static void* before_title_in(void* data, float elapsed_ms, float progress) { struct rectangle c = { 0, 0, 192, 108 }; struct rectangle r = { 0, 0, 64, 64 }; struct level_data* ldata = data; UNUSED(elapsed_ms); UNUSED(progress); clear_image(ldata->title.mask, color_from_RGB(0, 0, 0)); draw_on_image(ldata->title.mask); draw_image(ldata->title.spot, -15, 40, &r, 0); draw_on_screen(); draw_image(ldata->title.mask, 0, 0, &c, 0); return NULL; }
void show_scores() { int i=0; char text_name[25]; char text_score[25]; TTF_Font *MyFont; SDL_Color MyColor = {255,255,255}; SDL_Color MyColor2 = {255,0,0}; SDL_Surface *message = NULL; MyFont = TTF_OpenFont("fonts\\sfont.ttf",20); message = TTF_RenderText_Blended(MyFont,"TEAM NAMES",MyColor2); draw_image(message,screen,NULL,150,170); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"SCORES",MyColor2); draw_image(message,screen,NULL,800,170); SDL_FreeSurface(message); message = NULL; read_score(); sort_score(); for(i=0;i<10;++i) { strcpy(text_name,score[i].name); message = TTF_RenderText_Blended(MyFont,text_name,MyColor); draw_image(message,screen,NULL,150,200 + (30 * i)); SDL_FreeSurface(message); message = NULL; itoa(score[i].score,text_score,10); message = TTF_RenderText_Blended(MyFont,text_score,MyColor); draw_image(message,screen,NULL,800,200 + (30 * i)); SDL_FreeSurface(message); message = NULL; } SDL_Flip(screen); TTF_CloseFont(MyFont); SDL_FreeSurface(message); MyFont = NULL; message = NULL; }
static void apply_image(GLenum texture, int image) { if (GL_has_multitexture && texture < GL_max_multitexture) { glActiveTextureARB(texture); /* Always apply texture 0, but disable all other unused textures. */ if (texture == GL_TEXTURE0_ARB || image != 0) draw_image(image); else glDisable(GL_TEXTURE_2D); } else draw_image(image); }
static void draw_tile_sequence(Imlib_Image left, Imlib_Image tile, Imlib_Image right, int ox, int width) { int lw = get_image_width(left); int rw = get_image_width(right); int tilew = width - lw - rw; if (tilew < 0) return; draw_image(left, ox); ox += lw; tile_image(tile, ox, tilew); ox += tilew; draw_image(right, ox); }
int main(int argc, char *argv[]) { char *prog = argv[0]; int opt, rc=-1; hex_t h; utarray_new(cfg.hexv, &hex_icd); while ( (opt = getopt(argc, argv, "v+i:o:h")) != -1) { switch (opt) { case 'v': cfg.verbose++; break; case 'i': cfg.infile = strdup(optarg); break; case 'o': cfg.outfile = strdup(optarg); break; case 'h': default: usage(prog); break; } } if (!cfg.outfile || !cfg.infile) usage(prog); /* read input file */ tpl_node *tn = tpl_map("A(sii)", &h.id, &h.x, &h.y); if (tpl_load(tn, TPL_FILE, cfg.infile)) goto done; while(tpl_unpack(tn,1) > 0) utarray_push_back(cfg.hexv, &h); tpl_free(tn); find_bounds(); draw_image(); rc = 0; done: utarray_free(cfg.hexv); return rc; }
static int control(struct vo *vo, uint32_t request, void *data) { struct xvctx *ctx = vo->priv; switch (request) { case VOCTRL_GET_PANSCAN: return VO_TRUE; case VOCTRL_SET_PANSCAN: resize(vo); return VO_TRUE; case VOCTRL_SET_EQUALIZER: { vo->want_redraw = true; struct voctrl_set_equalizer_args *args = data; return xv_set_eq(vo, ctx->xv_port, args->name, args->value); } case VOCTRL_GET_EQUALIZER: { struct voctrl_get_equalizer_args *args = data; return xv_get_eq(vo, ctx->xv_port, args->name, args->valueptr); } case VOCTRL_REDRAW_FRAME: draw_image(vo, ctx->original_image); return true; } int events = 0; int r = vo_x11_control(vo, &events, request, data); if (events & (VO_EVENT_EXPOSE | VO_EVENT_RESIZE)) resize(vo); vo_event(vo, events); return r; }
int main(int argc, char **argv) { guchar image_data[width * height * 3]; collect_data(image_data); print_hash(width*height*3, image_data); draw_image(argc, argv, image_data); }
static void* slide_title_in(void* data, float elapsed_ms, float progress) { struct rectangle c = { 0, 0, 192, 108 }; struct rectangle r = { 0, 0, 64, 64 }; struct level_data* ldata = data; UNUSED(elapsed_ms); clear_image(ldata->title.mask, color_from_RGB(255 * progress, 255 * progress, 255 * progress)); draw_on_image(ldata->title.mask); draw_image(ldata->title.spot, -15, 40, &r, 0); draw_on_screen(); draw_image(ldata->title.mask, 0, 0, &c, 0); draw_sprite(ldata->title.sprite, interpolate(-100, 20, progress, circular_ease_out), 10); return NULL; }
/* void draw_image (ESContext *esContext, int16_t x, int16_t y, int16_t w, int16_t h, char *file) { */ int tclcmd_draw_image (ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { int len = 0; if (objc != 6) { Tcl_WrongNumArgs (interp, 1, objv, "{ESContext *esContext} { int16_t x} { int16_t y} { int16_t w} { int16_t h} { char *file}"); return TCL_ERROR; } int16_t arg_x; if (Tcl_GetIntFromObj(interp, objv[1], (int *)&arg_x) != TCL_OK) { return TCL_ERROR; } int16_t arg_y; if (Tcl_GetIntFromObj(interp, objv[2], (int *)&arg_y) != TCL_OK) { return TCL_ERROR; } int16_t arg_w; if (Tcl_GetIntFromObj(interp, objv[3], (int *)&arg_w) != TCL_OK) { return TCL_ERROR; } int16_t arg_h; if (Tcl_GetIntFromObj(interp, objv[4], (int *)&arg_h) != TCL_OK) { return TCL_ERROR; } char arg_file[1024]; strncpy(arg_file, Tcl_GetStringFromObj(objv[5], &len), 1024); draw_image(GlobalesContext, arg_x, arg_y, arg_w, arg_h, arg_file); return TCL_OK; }
static int redraw_frame(struct vo *vo) { struct xvctx *ctx = vo->priv; draw_image(vo, ctx->original_image); return true; }
void SoftwareRendererImp::draw_element(SVGElement* element) { // Task 4 (part 1): // Modify this to implement the transformation stack switch (element->type) { case POINT: draw_point(static_cast<Point&>(*element)); break; case LINE: draw_line(static_cast<Line&>(*element)); break; case POLYLINE: draw_polyline(static_cast<Polyline&>(*element)); break; case RECT: draw_rect(static_cast<Rect&>(*element)); break; case POLYGON: draw_polygon(static_cast<Polygon&>(*element)); break; case ELLIPSE: draw_ellipse(static_cast<Ellipse&>(*element)); break; case IMAGE: draw_image(static_cast<Image&>(*element)); break; case GROUP: draw_group(static_cast<Group&>(*element)); break; default: break; } }
static void redraw(void) { draw_fill(ctx, rgb(TTK_BACKGROUND_DEFAULT)); render_decorations(win, ctx, file_name); draw_image(); flip(ctx); yutani_flip(yctx, win); }
/* draws an inline image at rect (x,y,width,height) * maxwidth is maximum width the image can take in * zoom is whether the image is currently zoomed in * position is the y position along the image the player has scrolled */ static void draw_message_image(UTOX_NATIVE_IMAGE *image, int x, int y, uint32_t width, uint32_t height, uint32_t maxwidth, _Bool zoom, double position) { if(!zoom && width > maxwidth) { image_set_scale(image, (double)maxwidth / width); draw_image(image, x, y, maxwidth, height * maxwidth / width, 0, 0); image_set_scale(image, 1.0); } else { if(width > maxwidth) { draw_image(image, x, y, maxwidth, height, (int)((double)(width - maxwidth) * position), 0); } else { draw_image(image, x, y, width, height, 0, 0); } } }
void show_picture(u8 image,u8 dir,u8 fade) { static u8 i,j; if(fade) { for(i=0;i<4;++i) { pal_bright(dir?BRIGHT_MID+i:BRIGHT_MID-i); for(j=0;j<4;++j) vsync(); } } draw_image(0,0,image); pal_select(image); swap_screen(); if(fade) { for(i=0;i<4;++i) { pal_bright(dir?BRIGHT_MAX-i:BRIGHT_MIN+i); for(j=0;j<4;++j) vsync(); } } }
/* * Draws the required (for the free SDK) logo in the bottom-left corner of the visible camera feed */ void PointCloudApplication::draw_logo() { int h = context.viewport_height; int w = context.viewport_width; double scale_factor = w == 320 ? 0.5 : 1.0; switch_to_ortho(); draw_image(logo_texture, 10, h-(140+54)*scale_factor, 262*scale_factor, 54*scale_factor, 0, 0, 1, 1); }
/* @brief Draw a line of text to a cairo context. * * @param cr A cairo context for drawing to the screen. * @param text The text to be drawn. * @param line The index of the line to be drawn (counting from the top). * @param foreground The color of the text. * @param background The color of the background. * @return Void. */ static void draw_line(cairo_t *cr, const char *text, uint32_t line, color_t *foreground, color_t *background) { pthread_mutex_lock(&global.draw_mutex); cairo_set_source_rgb(cr, background->r, background->g, background->b); /* Add 2 to fix a weird offsetting bug. TODO: Fix the bug properly. */ cairo_rectangle(cr, 0, line * settings.height + 2, settings.width, settings.height); cairo_stroke_preserve(cr); cairo_fill(cr); offset_t offset = calculate_line_offset(line); /* Parse the response line as we draw it. */ char *c = (char *)text; while (c && *c != '\0') { draw_t d = parse_response_line(&c); char saved = *c; *c = '\0'; switch (d.type) { case DRAW_IMAGE: offset.x += draw_image(cr, d.data, offset) + settings.height / 10; break; case DRAW_TEXT: default: offset.x += draw_text(cr, d.data, offset, foreground); break; } *c = saved; } pthread_mutex_unlock(&global.draw_mutex); }
/* Collision detection * ------------------- * * When updating a frame, we traverse the star pairs * graph and test for a bounding box intersection. * To detect pixel-level collisions, we us pixels_collide() * using the portion of intersection as a test area. * If we detect a collision, we swap the star pair * motion vectors to create a deflection effect. * * When done, we update and draw the stars. */ static void update_sample(void* data, float elapsed_ms) { struct state* state = data; int visited[MAX_STARS][MAX_STARS] = { { 0 } }; int i, j; for (i = 0; i < MAX_STARS; i++) { for (j = 0; j < MAX_STARS; j++) { if (i != j && visited[i][j] == 0 && visited[j][i] == 0) { bbox sub; struct star* a = &state->stars[i]; struct star* b = &state->stars[j]; if (bbox_intersect(a->star_bbox, b->star_bbox, &sub)) { struct rectangle r1, r2; r1 = rect_from_sub_bbox(a->star_bbox, sub); r2 = rect_from_sub_bbox(b->star_bbox, sub); if (pixels_collide(state->star_img, &r1, state->star_img, &r2)) swap_vecs(&a->star_vec, &b->star_vec); } visited[i][j] = 1; } } } screen_color(color_from_RGB(10, 20, 50)); for (i = 0; i < MAX_STARS; i++) { update_star(&state->stars[i], elapsed_ms); draw_image(state->star_img, VEC_XY(state->stars[i].star_pos), NULL, 0); } }
int main(int argc, char **argv) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer DCOCTL = CALDCO_1MHZ; // Set DCO to 16MHz BCSCTL1 = CALBC1_1MHZ; // MCLC = SMCLK = DCOCLK = 16MHz BCSCTL1 |= DIVA_0; // ACLK = ACLK/1 BCSCTL3 = LFXT1S1; //Select VLOCLK for ACLCK (i.e. 12khz intosc) TACCTL0 = OUTMOD_2 + CCIE; // TACCR0 interrupt enabled TACTL = TASSEL_1 + ID1 + ID0 + MC_1; // ACLCK, 1/8 DIVIDER, upmode to TCCR0 value //Set port directions P1DIR = 0x3F; // bits 0, 1, 2, 3, 4, 5 to outputs P1OUT = 0x00; // All bits low to initialize //initialize buttons P2DIR &= ~0x0F; // Set P2.0-3 to input direction P2REN |= 0x0F; // Set P2.0-3 to use pull up/down resistor P2OUT &= ~0x0F; // Set P2.0-3 to use pull down resistor //configure interrupts for buttons 2.0-3 P2IE = 0x0F; //Enable interrupts for each button P2IES = 0x00; //Set all ports to be sensitive only to rising edges nokia_init(); TACCR0 = 0; //Compare to Timer_A register (approx. 25 sec for VLOCLK & 1/8 divider) draw_image(rvasec_logo); TACCR0 = BLINK_CONST; //Compare to Timer_A register (approx. 25 sec for VLOCLK & 1/8 divider) __bis_SR_register(LPM3_bits + GIE); //Enter LPM3 w/interrupt __no_operation(); // For debugger, executes next instruction just like a PIC }
/* **draw\_level()** draws the game frames, using * the content of the level (the wizard, level tiles, monsters, etc..). * It uses the level_data stored inside the data arg as well * as the LEVEL string that represents the level map using * ascii chars as tiles index; */ static void draw_level(void* data, float elapsed_ms) { struct level_data* ldata = data; struct rectangle tile_size = { 0, 0, 16, 16 }; unsigned int i; char fps[10]; sprintf(fps, "FPS:%02.0f", 1000 / elapsed_ms); if (ldata->wizard->sprite->active_animation == ldata->wizard->spell) { if (ldata->wizard->sprite->current_frame > 1) shake_screen(elapsed_ms); } else { relax_screen(elapsed_ms); } for (i = 0; i < strlen(LEVEL); i++) { if (LEVEL[i] != ' ') { int x = 16 * (i % 13); int y = 16 * (i / 13); draw_image(LEVEL[i] == '-' ? ldata->grass_tile : ldata->earth_tile, x, y, &tile_size, 0); } } draw_sprite(ldata->tree.sprite, 100, 56); draw_sprite(ldata->wizard->sprite, xy(ldata->wizard->pos.x, ldata->wizard->pos.y)); draw_text(ldata->font, fps, 75, 3); }
/* * Calls draw_image on a new pixmap and swaps that with the current pixmap * */ void redraw_screen(void) { /* avoid drawing if monitor state is not on */ if (dpms_capable) { xcb_dpms_info_reply_t *dpms_info = xcb_dpms_info_reply(conn,xcb_dpms_info(conn), NULL); if (dpms_info) { /* monitor is off when DPMS state is enabled and power level is not * DPMS_MODE_ON */ uint8_t monitor_off = dpms_info->state && dpms_info->power_level != XCB_DPMS_DPMS_MODE_ON; free(dpms_info); if (monitor_off) return; } } xcb_pixmap_t bg_pixmap = draw_image(last_resolution); xcb_change_window_attributes(conn, win, XCB_CW_BACK_PIXMAP, (uint32_t[1]){ bg_pixmap }); /* XXX: Possible optimization: Only update the area in the middle of the * screen instead of the whole screen. */ xcb_clear_area(conn, 0, win, 0, 0, last_resolution[0], last_resolution[1]); xcb_free_pixmap(conn, bg_pixmap); xcb_flush(conn); }