static void tab_rom_init(multirom_theme_data *t, tab_data_roms *d, int tab_type) { int base_y = fb_height-ROMS_FOOTER_H; d->rom_name = fb_add_text(HEADER_WIDTH, center_y(base_y, ROMS_FOOTER_H, SIZE_NORMAL), WHITE, SIZE_NORMAL, ""); d->list->x = HEADER_WIDTH; d->list->y = ROMS_HEADER_H; d->list->w = fb_width-HEADER_WIDTH; d->list->h = fb_height - d->list->y - ROMS_FOOTER_H-20; // header int y = center_y(0, ROMS_HEADER_H, SIZE_BIG); d->title_text = fb_add_text(HEADER_WIDTH, y, CLR_PRIMARY, SIZE_BIG, ""); list_add(d->title_text, &d->ui_elements); // footer fb_rect *sep = fb_add_rect(HEADER_WIDTH+2, fb_height-ROMS_FOOTER_H, fb_width-HEADER_WIDTH-2, 2, CLR_PRIMARY); list_add(sep, &d->ui_elements); // boot btn d->boot_btn->x = fb_width - BOOTBTN_W - 5; d->boot_btn->y = base_y + (ROMS_FOOTER_H-BOOTBTN_H)/2; d->boot_btn->w = BOOTBTN_W; d->boot_btn->h = BOOTBTN_H; }
void button_init_ui(button *b, const char *text, int size) { b->touch_id = -1; if(text != NULL) { b->c[CLR_NORMAL][0] = CLR_PRIMARY; b->c[CLR_NORMAL][1] = WHITE; b->c[CLR_HOVER][0] = CLR_SECONDARY; b->c[CLR_HOVER][1] = WHITE; b->c[CLR_DIS][0] = GRAY; b->c[CLR_DIS][1] = WHITE; b->c[CLR_CHECK][0] = CLR_SECONDARY; b->c[CLR_CHECK][1] = WHITE; b->rect = fb_add_rect(b->x, b->y, b->w, b->h, b->c[CLR_NORMAL][0]); int text_x = center_x(b->x, b->w, size, text); int text_y = center_y(b->y, b->h, size); b->text = fb_add_text(text_x, text_y, b->c[CLR_NORMAL][1], size, text); } else { b->text = NULL; b->rect = NULL; } add_touch_handler(&button_touch_handler, b); }
void button_move(button *b, int x, int y) { b->x = x; b->y = y; if(b->text) { b->rect->head.x = x; b->rect->head.y = y; b->text->head.x = center_x(x, b->w, b->text->size, b->text->text); b->text->head.y = center_y(y, b->h, b->text->size); } }
double score_circle(double *pt, int start, int end, struct Inertia *s) { double sum, x0, y0, r0, dm, deltar; int i; if (s->mass == 0.) return 0; sum = 0.; x0 = center_x(*s); y0 = center_y(*s); r0 = I_rad(*s); for (i=start, pt+=2*start; i<end; i++, pt+=2) { dm = hypot(pt[2]-pt[0], pt[3]-pt[1]); deltar = hypot(pt[0]-x0, pt[1]-y0) - r0; sum += dm * fabs(deltar); } return sum/(s->mass*r0); }
int main (int argc, char ** argv) { setup_windowing(); int width = wins_globals->server_width; int height = wins_globals->server_height; win_width = width; win_height = height; /* Do something with a window */ window_t * wina = window_create(0,0, width, height); assert(wina); window_reorder (wina, 0); ctx = init_graphics_window_double_buffer(wina); draw_fill(ctx, rgb(127,127,127)); flip(ctx); #if 1 printf("Loading background...\n"); init_sprite(0, "/usr/share/login-background.bmp", NULL); printf("Background loaded.\n"); draw_sprite_scaled(ctx, sprites[0], 0, 0, width, height); #endif #if 0 init_sprite(1, "/usr/share/bs.bmp", "/usr/share/bs-alpha.bmp"); draw_sprite_scaled(sprites[1], center_x(sprites[1]->width), center_y(sprites[1]->height), sprites[1]->width, sprites[1]->height); #endif flip(ctx); while (1) { syscall_yield(); //syscall_wait(wins_globals->server_pid); } #if 0 window_destroy(window); // (will close on exit) teardown_windowing(); #endif return 0; }
t_pad *get_pad(t_crd *map, int w, int h) { t_pad *ret; ret = (t_pad *)malloc(sizeof(t_pad)); get_max(ret, map); if (ret->zx->z > 75 || ret->zn->z < -75) ret->ct = 0.09; else ret->ct = 0.38; if (ret->xm->x != 0) ret->px = (w / ret->xm->x); if (ret->ym->y != 0) ret->py = (h / ret->ym->y) / 2; ret->cx = center_x(ret, w); ret->cy = center_y(ret, h); return (ret); }
static void init_header(multirom_theme_data *t) { button **tab_btns = t->tab_btns; fb_text **tab_texts = t->tab_texts; int i, text_x, text_y; int x = fb_width - (TAB_BTN_WIDTH*TAB_COUNT); static const char *str[] = { "Internal", "USB", "Misc", "MultiROM" }; text_x = center_x(0, x, SIZE_EXTRA, str[3]); fb_add_text(text_x, 5, WHITE, SIZE_EXTRA, str[3]); pong_btn = mzalloc(sizeof(button)); pong_btn->w = x; pong_btn->h = HEADER_HEIGHT; pong_btn->clicked = &multirom_ui_start_pong; button_init_ui(pong_btn, NULL, 0); for(i = 0; i < TAB_COUNT; ++i) { text_x = center_x(x, TAB_BTN_WIDTH, SIZE_NORMAL, str[i]); text_y = center_y(0, HEADER_HEIGHT, SIZE_NORMAL); tab_texts[i] = fb_add_text(text_x, text_y, WHITE, SIZE_NORMAL, str[i]); fb_add_rect(x, 0, 2, HEADER_HEIGHT, WHITE); tab_btns[i] = malloc(sizeof(button)); memset(tab_btns[i], 0, sizeof(button)); tab_btns[i]->x = x; tab_btns[i]->w = TAB_BTN_WIDTH; tab_btns[i]->h = HEADER_HEIGHT; tab_btns[i]->action = i; tab_btns[i]->clicked = &multirom_ui_switch; button_init_ui(tab_btns[i], NULL, 0); x += TAB_BTN_WIDTH; } fb_add_rect(0, HEADER_HEIGHT, fb_width, 2, WHITE); }
void get_segment_geometry(double *pt, int start, int end, struct Inertia *s, struct RecoSegment *r) { double a, b, c, lmin, lmax, l; int i; r->xcenter = center_x(*s); r->ycenter = center_y(*s); a = I_xx(*s); b = I_xy(*s); c = I_yy(*s); /* max angle for inertia quadratic form solves: tan(2t) = 2b/(a-c) */ r->angle = atan2(2*b, a-c)/2; r->radius = sqrt(3*(a+c)); lmin = lmax = 0.; for (i=start, pt+=2*start; i<=end; i++, pt+=2) { l = (pt[0]-r->xcenter)*cos(r->angle)+(pt[1]-r->ycenter)*sin(r->angle); if (l<lmin) lmin = l; if (l>lmax) lmax = l; } r->x1 = r->xcenter + lmin*cos(r->angle); r->y1 = r->ycenter + lmin*sin(r->angle); r->x2 = r->xcenter + lmax*cos(r->angle); r->y2 = r->ycenter + lmax*sin(r->angle); }
static void init_header(multirom_theme_data *t) { button **tab_btns = t->tab_btns; fb_text **tab_texts = t->tab_texts; int i, text_x, text_y; int y = TAB_BTN_HEIGHT; static const char *str[] = { "Internal", "USB", "Misc", "MultiROM" }; text_x = center_x(0, HEADER_WIDTH, SIZE_EXTRA, str[3]); fb_add_text(text_x, 5, WHITE, SIZE_EXTRA, str[3]); for(i = 0; i < TAB_COUNT; ++i) { text_x = center_x(0, HEADER_WIDTH, SIZE_NORMAL, str[i]); text_y = center_y(y, TAB_BTN_HEIGHT, SIZE_NORMAL); tab_texts[i] = fb_add_text(text_x, text_y, WHITE, SIZE_NORMAL, str[i]); fb_add_rect(0, y, HEADER_WIDTH, 2, WHITE); tab_btns[i] = malloc(sizeof(button)); memset(tab_btns[i], 0, sizeof(button)); tab_btns[i]->y = y; tab_btns[i]->w = HEADER_WIDTH; tab_btns[i]->h = TAB_BTN_HEIGHT; tab_btns[i]->action = i; tab_btns[i]->clicked = &multirom_ui_switch; button_init_ui(tab_btns[i], NULL, 0); y += TAB_BTN_HEIGHT; } fb_add_rect(0, y, HEADER_WIDTH, 2, WHITE); fb_add_rect(HEADER_WIDTH-2, 0, 2, fb_height, WHITE); }
void multirom_ui_tab_rom_set_empty(void *data, int empty) { assert(empty == 0 || empty == 1); tab_data_roms *t = (tab_data_roms*)data; int width = cur_theme->get_tab_width(themes_info->data); static const char *str[] = { "Select ROM to boot:", "No ROMs in this location!" }; t->title_text->head.x = center_x(t->list->x, width, SIZE_BIG, str[empty]); t->title_text->text = realloc(t->title_text->text, strlen(str[empty])+1); strcpy(t->title_text->text, str[empty]); if(t->boot_btn) button_enable(t->boot_btn, !empty); if(empty && !t->usb_text) { const int line_len = 37; static const char *txt = "This list is refreshed automagically,\njust plug in the USB drive and wait."; int x = t->list->x + (width/2 - (line_len*ISO_CHAR_WIDTH*SIZE_NORMAL)/2); int y = center_y(t->list->y, t->list->h, SIZE_NORMAL); t->usb_text = fb_add_text(x, y, WHITE, SIZE_NORMAL, txt); list_add(t->usb_text, &t->ui_elements); x = t->list->x + ((width/2) - (PROGDOTS_W/2)); t->usb_prog = progdots_create(x, y+100*DPI_MUL); } else if(!empty && t->usb_text) { progdots_destroy(t->usb_prog); t->usb_prog = NULL; list_rm(t->usb_text, &t->ui_elements, &fb_remove_item); t->usb_text = NULL; } }
int main (int argc, char ** argv) { init_shmemfonts(); yutani_t * y = yutani_init(); if (!y) { fprintf(stderr, "[glogin] Connection to server failed.\n"); return 1; } /* Load config */ { confreader_t * conf = confreader_load("/etc/glogin.conf"); LOGO_FINAL_OFFSET = confreader_intd(conf, "style", "logo_padding", LOGO_FINAL_OFFSET); BOX_WIDTH = confreader_intd(conf, "style", "box_width", BOX_WIDTH); BOX_HEIGHT = confreader_intd(conf, "style", "box_height", BOX_HEIGHT); BOX_ROUNDNESS = confreader_intd(conf, "style", "box_roundness", BOX_ROUNDNESS); CENTER_BOX_X = confreader_intd(conf, "style", "center_box_x", CENTER_BOX_X); CENTER_BOX_Y = confreader_intd(conf, "style", "center_box_y", CENTER_BOX_Y); BOX_LEFT = confreader_intd(conf, "style", "box_left", BOX_LEFT); BOX_RIGHT = confreader_intd(conf, "style", "box_right", BOX_RIGHT); BOX_TOP = confreader_intd(conf, "style", "box_top", BOX_TOP); BOX_BOTTOM = confreader_intd(conf, "style", "box_bottom", BOX_BOTTOM); BOX_COLOR_R = confreader_intd(conf, "style", "box_color_r", BOX_COLOR_R); BOX_COLOR_G = confreader_intd(conf, "style", "box_color_g", BOX_COLOR_G); BOX_COLOR_B = confreader_intd(conf, "style", "box_color_b", BOX_COLOR_B); BOX_COLOR_A = confreader_intd(conf, "style", "box_color_a", BOX_COLOR_A); WALLPAPER = confreader_getd(conf, "image", "wallpaper", WALLPAPER); LOGO = confreader_getd(conf, "image", "logo", LOGO); confreader_free(conf); TRACE("Loading complete"); } TRACE("Loading logo..."); load_sprite_png(&logo, LOGO); TRACE("... done."); /* Generate surface for background */ sprite_t * bg_sprite; int width = y->display_width; int height = y->display_height; int skip_animation = 0; /* Do something with a window */ TRACE("Connecting to window server..."); yutani_window_t * wina = yutani_window_create(y, width, height); assert(wina); yutani_set_stack(y, wina, 0); ctx = init_graphics_yutani_double_buffer(wina); draw_fill(ctx, rgba(0,0,0,255)); yutani_flip(y, wina); TRACE("... done."); redo_everything: win_width = width; win_height = height; cairo_surface_t * cs = cairo_image_surface_create_for_data((void*)ctx->backbuffer, CAIRO_FORMAT_ARGB32, ctx->width, ctx->height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ctx->width)); cairo_t * cr = cairo_create(cs); TRACE("Loading wallpaper..."); { sprite_t * wallpaper = malloc(sizeof(sprite_t)); load_sprite_png(wallpaper, WALLPAPER); float x = (float)width / (float)wallpaper->width; float y = (float)height / (float)wallpaper->height; int nh = (int)(x * (float)wallpaper->height); int nw = (int)(y * (float)wallpaper->width);; bg_sprite = create_sprite(width, height, ALPHA_OPAQUE); gfx_context_t * bg = init_graphics_sprite(bg_sprite); if (nw > width) { draw_sprite_scaled(bg, wallpaper, (width - nw) / 2, 0, nw, height); } else { draw_sprite_scaled(bg, wallpaper, 0, (height - nh) / 2, width, nh); } /* Three box blurs = good enough approximation of a guassian, but faster*/ blur_context_box(bg, 20); blur_context_box(bg, 20); blur_context_box(bg, 20); free(bg); free(wallpaper); } TRACE("... done."); while (1) { yutani_set_stack(y, wina, 0); yutani_focus_window(y, wina->wid); draw_fill(ctx, rgb(0,0,0)); draw_sprite(ctx, bg_sprite, center_x(width), center_y(height)); flip(ctx); yutani_flip(y, wina); char * foo = malloc(sizeof(uint32_t) * width * height); memcpy(foo, ctx->backbuffer, sizeof(uint32_t) * width * height); TRACE("Begin animation."); if (!skip_animation) { struct timeval start; gettimeofday(&start, NULL); while (1) { uint32_t tick; struct timeval t; gettimeofday(&t, NULL); uint32_t sec_diff = t.tv_sec - start.tv_sec; uint32_t usec_diff = t.tv_usec - start.tv_usec; if (t.tv_usec < start.tv_usec) { sec_diff -= 1; usec_diff = (1000000 + t.tv_usec) - start.tv_usec; } tick = (uint32_t)(sec_diff * 1000 + usec_diff / 1000); int i = (float)LOGO_FINAL_OFFSET * (float)tick / 700.0f; if (i >= LOGO_FINAL_OFFSET) break; memcpy(ctx->backbuffer, foo, sizeof(uint32_t) * width * height); draw_sprite(ctx, &logo, center_x(logo.width), center_y(logo.height) - i); flip(ctx); yutani_flip_region(y, wina, center_x(logo.width), center_y(logo.height) - i, logo.width, logo.height + 5); usleep(10000); } } TRACE("End animation."); skip_animation = 0; size_t buf_size = wina->width * wina->height * sizeof(uint32_t); char * buf = malloc(buf_size); uint32_t i = 0; uint32_t black = rgb(0,0,0); uint32_t white = rgb(255,255,255); int x_offset = 65; int y_offset = 64; int fuzz = 3; char username[INPUT_SIZE] = {0}; char password[INPUT_SIZE] = {0}; char hostname[512]; // we do it here to calculate the final string position get_updated_hostname_with_time_info(hostname); char kernel_v[512]; { struct utsname u; uname(&u); /* UTF-8 Strings FTW! */ uint8_t * os_name_ = "とあるOS"; uint32_t l = snprintf(kernel_v, 512, "%s %s", os_name_, u.release); } uid = 0; int box_x, box_y; if (CENTER_BOX_X) { box_x = center_x(BOX_WIDTH); } else if (BOX_LEFT == -1) { box_x = win_width - BOX_RIGHT - BOX_WIDTH; } else { box_x = BOX_LEFT; } if (CENTER_BOX_Y) { box_y = center_y(0) + 8; } else if (BOX_TOP == -1) { box_y = win_width - BOX_BOTTOM - BOX_HEIGHT; } else { box_y = BOX_TOP; } int focus = 0; set_font_size(11); int hostname_label_left = width - 10 - draw_string_width(hostname); int kernel_v_label_left = 10; struct text_box username_box = { (BOX_WIDTH - 170) / 2, 30, 170, 20, rgb(0,0,0), NULL, 0, 0, 0, username, "Username" }; struct text_box password_box = { (BOX_WIDTH - 170) / 2, 58, 170, 20, rgb(0,0,0), NULL, 0, 1, 0, password, "Password" }; struct login_container lc = { box_x, box_y, BOX_WIDTH, BOX_HEIGHT, &username_box, &password_box, 0 }; username_box.parent = &lc; password_box.parent = &lc; while (1) { focus = 0; memset(username, 0x0, INPUT_SIZE); memset(password, 0x0, INPUT_SIZE); while (1) { // update time info get_updated_hostname_with_time_info(hostname); memcpy(ctx->backbuffer, foo, sizeof(uint32_t) * width * height); draw_sprite(ctx, &logo, center_x(logo.width), center_y(logo.height) - LOGO_FINAL_OFFSET); set_font_size(11); draw_string_shadow(ctx, hostname_label_left, height - 12, white, hostname, rgb(0,0,0), 2, 1, 1, 3.0); draw_string_shadow(ctx, kernel_v_label_left, height - 12, white, kernel_v, rgb(0,0,0), 2, 1, 1, 3.0); if (focus == USERNAME_BOX) { username_box.is_focused = 1; password_box.is_focused = 0; } else if (focus == PASSWORD_BOX) { username_box.is_focused = 0; password_box.is_focused = 1; } else { username_box.is_focused = 0; password_box.is_focused = 0; } draw_login_container(cr, &lc); flip(ctx); yutani_flip(y, wina); struct yutani_msg_key_event kbd; struct yutani_msg_window_mouse_event mou; int msg_type = 0; collect_events: do { yutani_msg_t * msg = yutani_poll(y); switch (msg->type) { case YUTANI_MSG_KEY_EVENT: { struct yutani_msg_key_event * ke = (void*)msg->data; if (ke->event.action == KEY_ACTION_DOWN) { memcpy(&kbd, ke, sizeof(struct yutani_msg_key_event)); msg_type = 1; } } break; case YUTANI_MSG_WINDOW_MOUSE_EVENT: { struct yutani_msg_window_mouse_event * me = (void*)msg->data; memcpy(&mou, me, sizeof(struct yutani_msg_mouse_event)); msg_type = 2; } break; case YUTANI_MSG_WELCOME: { struct yutani_msg_welcome * mw = (void*)msg->data; yutani_window_resize(y, wina, mw->display_width, mw->display_height); } break; case YUTANI_MSG_RESIZE_OFFER: { struct yutani_msg_window_resize * wr = (void*)msg->data; width = wr->width; height = wr->height; yutani_window_resize_accept(y, wina, width, height); reinit_graphics_yutani(ctx, wina); yutani_window_resize_done(y, wina); sprite_free(bg_sprite); cairo_destroy(cr); cairo_surface_destroy(cs); skip_animation = 1; goto redo_everything; } break; } free(msg); } while (!msg_type); if (msg_type == 1) { if (kbd.event.keycode == '\n') { if (focus == USERNAME_BOX) { focus = PASSWORD_BOX; continue; } else if (focus == PASSWORD_BOX) { break; } else { focus = USERNAME_BOX; continue; } } if (kbd.event.keycode == '\t') { if (focus == USERNAME_BOX) { focus = PASSWORD_BOX; } else { focus = USERNAME_BOX; } continue; } if (kbd.event.key) { if (!focus) { focus = USERNAME_BOX; } if (focus == USERNAME_BOX) { buffer_put(username, kbd.event.key); } else if (focus == PASSWORD_BOX) { buffer_put(password, kbd.event.key); } } } else if (msg_type == 2) { if ((mou.command == YUTANI_MOUSE_EVENT_DOWN && mou.buttons & YUTANI_MOUSE_BUTTON_LEFT) || (mou.command == YUTANI_MOUSE_EVENT_CLICK)) { /* Determine if we were inside of a text box */ if (mou.new_x >= lc.x + username_box.x && mou.new_x <= lc.x + username_box.x + username_box.width && mou.new_y >= lc.y + username_box.y && mou.new_y <= lc.y + username_box.y + username_box.height) { /* Ensure this box is focused. */ focus = USERNAME_BOX; continue; } else if (mou.new_x >= lc.x + password_box.x && mou.new_x <= lc.x + password_box.x + password_box.width && mou.new_y >= lc.y + password_box.y && mou.new_y <= lc.y + password_box.y + password_box.height) { /* Ensure this box is focused. */ focus = PASSWORD_BOX; continue; } else { focus = 0; continue; } } else { goto collect_events; } } } uid = toaru_auth_check_pass(username, password); if (uid >= 0) { break; } lc.show_error = 1; } memcpy(ctx->backbuffer, foo, sizeof(uint32_t) * width * height); flip(ctx); yutani_flip(y, wina); syscall_yield(); pid_t _session_pid = fork(); if (!_session_pid) { setuid(uid); toaru_auth_set_vars(); char * args[] = {"/bin/gsession", NULL}; execvp(args[0], args); } free(foo); free(buf); waitpid(_session_pid, NULL, 0); } yutani_close(y, wina); return 0; }
/* the main pattern recognition function, called after finalize_stroke() */ void recognize_patterns(void) { struct Item *it; struct Inertia s, ss[4]; struct RecoSegment *rs; int n, i; int brk[5]; double score; if (!undo || undo->type!=ITEM_STROKE) return; if (undo->next != last_item_checker) reset_recognizer(); // reset queue if (last_item_checker!=NULL && ui.cur_layer != last_item_checker->layer) reset_recognizer(); it = undo->item; calc_inertia(it->path->coords, 0, it->path->num_points-1, &s); #ifdef RECOGNIZER_DEBUG printf("DEBUG: Mass=%.0f, Center=(%.1f,%.1f), I=(%.0f,%.0f, %.0f), " "Rad=%.2f, Det=%.4f \n", s.mass, center_x(s), center_y(s), I_xx(s), I_yy(s), I_xy(s), I_rad(s), I_det(s)); #endif // first see if it's a polygon n = find_polygonal(it->path->coords, 0, it->path->num_points-1, MAX_POLYGON_SIDES, brk, ss); if (n>0) { optimize_polygonal(it->path->coords, n, brk, ss); #ifdef RECOGNIZER_DEBUG printf("DEBUG: Polygon, %d edges: ", n); for (i=0; i<n; i++) printf("DEBUG: %d-%d (M=%.0f, det=%.4f) ", brk[i], brk[i+1], ss[i].mass, I_det(ss[i])); printf("\n"); #endif /* update recognizer segment queue (most recent at end) */ while (n+recognizer_queue_length > MAX_POLYGON_SIDES) { // remove oldest polygonal stroke i=1; while (i<recognizer_queue_length && recognizer_queue[i].startpt!=0) i++; recognizer_queue_length-=i; g_memmove(recognizer_queue, recognizer_queue+i, recognizer_queue_length * sizeof(struct RecoSegment)); } #ifdef RECOGNIZER_DEBUG printf("DEBUG: Queue now has %d + %d edges\n", recognizer_queue_length, n); #endif rs = recognizer_queue + recognizer_queue_length; recognizer_queue_length += n; for (i=0; i<n; i++) { rs[i].item = it; rs[i].startpt = brk[i]; rs[i].endpt = brk[i+1]; get_segment_geometry(it->path->coords, brk[i], brk[i+1], ss+i, rs+i); } if (try_rectangle()) { reset_recognizer(); return; } if (try_arrow()) { reset_recognizer(); return; } if (try_closed_polygon(3)) { reset_recognizer(); return; } if (try_closed_polygon(4)) { reset_recognizer(); return; } if (n==1) { // current stroke is a line if (fabs(rs->angle)<SLANT_TOLERANCE) { // nearly horizontal rs->angle = 0.; rs->y1 = rs->y2 = rs->ycenter; } if (fabs(rs->angle)>M_PI/2-SLANT_TOLERANCE) { // nearly vertical rs->angle = (rs->angle>0)?(M_PI/2):(-M_PI/2); rs->x1 = rs->x2 = rs->xcenter; } realloc_cur_path(2); ui.cur_path.num_points = 2; ui.cur_path.coords[0] = rs->x1; ui.cur_path.coords[1] = rs->y1; ui.cur_path.coords[2] = rs->x2; ui.cur_path.coords[3] = rs->y2; remove_recognized_strokes(rs, 1); rs->item = insert_recognized_curpath(); } last_item_checker = undo; return; } // not a polygon: maybe a circle ? reset_recognizer(); if (I_det(s)>CIRCLE_MIN_DET) { score = score_circle(it->path->coords, 0, it->path->num_points-1, &s); #ifdef RECOGNIZER_DEBUG printf("DEBUG: Circle score: %.2f\n", score); #endif if (score < CIRCLE_MAX_SCORE) { make_circle_shape(center_x(s), center_y(s), I_rad(s)); recognizer_queue[0].item = it; remove_recognized_strokes(recognizer_queue, 1); insert_recognized_curpath(); } } }
BasicVector<T, 2> center() const { return BasicVector<T, 2>(center_x(), center_y()); }
int main (int argc, char ** argv) { init_sprite_png(0, "/usr/share/logo_login.png"); init_shmemfonts(); while (1) { syscall_print("Setup...\n"); setup_windowing(); int width = wins_globals->server_width; int height = wins_globals->server_height; win_width = width; win_height = height; /* Do something with a window */ window_t * wina = window_create(0,0, width, height); assert(wina); window_reorder (wina, 0); /* Disables movement */ ctx = init_graphics_window_double_buffer(wina); for (int i = 0; i < LOGO_FINAL_OFFSET; ++i) { draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - i); flip(ctx); } size_t buf_size = wina->width * wina->height * sizeof(uint32_t); char * buf = malloc(buf_size); uint32_t i = 0; uint32_t black = rgb(0,0,0); uint32_t white = rgb(255,255,255); uint32_t red = rgb(240, 20, 20); int x_offset = 65; int y_offset = 64; int fuzz = 3; char username[INPUT_SIZE] = {0}; char password[INPUT_SIZE] = {0}; char hostname[512]; { char _hostname[256]; syscall_gethostname(_hostname); struct tm * timeinfo; struct timeval now; syscall_gettimeofday(&now, NULL); //time(NULL); timeinfo = localtime((time_t *)&now.tv_sec); char _date[256]; strftime(_date, 256, "%a %B %d %Y", timeinfo); sprintf(hostname, "%s // %s", _hostname, _date); } char kernel_v[512]; { struct utsname u; uname(&u); /* UTF-8 Strings FTW! */ uint8_t * os_name_ = "PonyOS"; uint32_t l = snprintf(kernel_v, 512, "%s %s", os_name_, u.release); } uid = 0; #define BOX_WIDTH 272 #define BOX_HEIGHT 104 #define USERNAME_BOX 1 #define PASSWORD_BOX 2 #define EXTRA_TEXT_OFFSET 12 #define TEXTBOX_INTERIOR_LEFT 4 #define LEFT_OFFSET 80 int box_x = center_x(BOX_WIDTH); int box_y = center_y(0) + 8; int focus = USERNAME_BOX; set_font_size(11); int username_label_left = LEFT_OFFSET - 2 - draw_string_width("Username:"******"Password:"******""); for (int i = 0; i < strlen(password); ++i) { strcat(password_circles, "●"); } /* Redraw the background */ draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET); draw_string(ctx, hostname_label_left, height - 12, white, hostname); draw_string(ctx, kernel_v_label_left, height - 12, white, kernel_v); /* Draw backdrops */ draw_box(ctx, box_x, box_y, BOX_WIDTH, BOX_HEIGHT, rgb(180,124,205)); draw_box(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(255,255,255)); draw_box(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(255,255,255)); /* Draw labels */ draw_string(ctx, box_x + username_label_left, box_y + 32 + EXTRA_TEXT_OFFSET, white, "Username:"******"Password:"******"Incorrect username or password."; draw_string(ctx, box_x + (BOX_WIDTH - draw_string_width(error_message)) / 2, box_y + 8 + EXTRA_TEXT_OFFSET, red, error_message); } if (focus == USERNAME_BOX) { draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(229, 68, 138)); } else if (focus == PASSWORD_BOX) { draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(229, 68, 138)); } flip(ctx); w_keyboard_t * kbd = NULL; do { kbd = poll_keyboard(); } while (!kbd); if (kbd->key == '\n') { if (focus == USERNAME_BOX) { free(kbd); focus = PASSWORD_BOX; continue; } else if (focus == PASSWORD_BOX) { free(kbd); break; } } if (kbd->key == '\t') { if (focus == USERNAME_BOX) { focus = PASSWORD_BOX; } else if (focus == PASSWORD_BOX) { focus = USERNAME_BOX; } free(kbd); continue; } if (focus == USERNAME_BOX) { buffer_put(username, kbd->key); } else if (focus == PASSWORD_BOX) { buffer_put(password, kbd->key); } free(kbd); } uid = checkUserPass(username, password); if (uid >= 0) { break; } show_error = 1; } draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET); flip(ctx); teardown_windowing(); pid_t _session_pid = fork(); if (!_session_pid) { setenv("PATH", "/usr/bin:/bin", 0); syscall_setuid(uid); char * args[] = {"/bin/gsession", NULL}; execvp(args[0], args); } free(buf); free(ctx->backbuffer); free(ctx); syscall_wait(_session_pid); } return 0; }
int main(int argc, char * argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s image_file\n", argv[0]); return 1; } file_name = argv[1]; load_sprite_png(&image, argv[1]); yctx = yutani_init(); init_decorations(); win = yutani_window_create(yctx, image.width + decor_width(), image.height + decor_height()); yutani_window_move(yctx, win, center_x(image.width + decor_width()), center_y(image.height + decor_height())); ctx = init_graphics_yutani_double_buffer(win); int stride; stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, win->width); surface_win = cairo_image_surface_create_for_data(ctx->backbuffer, CAIRO_FORMAT_ARGB32, win->width, win->height, stride); cr_win = cairo_create(surface_win); yutani_window_advertise_icon(yctx, win, "Image Viewer", "image-viewer"); redraw(); yutani_focus_window(yctx, win->wid); while (!should_exit) { yutani_msg_t * m = yutani_poll(yctx); if (m) { switch (m->type) { case YUTANI_MSG_KEY_EVENT: { struct yutani_msg_key_event * ke = (void*)m->data; if (ke->event.key == 'q' && ke->event.action == KEY_ACTION_DOWN) { should_exit = 1; } } break; case YUTANI_MSG_WINDOW_FOCUS_CHANGE: { struct yutani_msg_window_focus_change * wf = (void*)m->data; if (wf->wid == win->wid) { win->focused = wf->focused; redraw(); } } break; case YUTANI_MSG_WINDOW_MOUSE_EVENT: { struct yutani_msg_window_mouse_event * me = (void*)m->data; if (me->wid != win->wid) break; int result = decor_handle_event(yctx, m); switch (result) { case DECOR_CLOSE: should_exit = 1; break; default: /* Other actions */ break; } } break; case YUTANI_MSG_SESSION_END: should_exit = 1; break; default: break; } free(m); } } return 0; }
const bool interpolate_and_define_vertices_using_bilinear_interpolation( const T1* const input_vertex_pointer, const std::size_t image_width, const std::size_t image_height, const std::size_t x_step, const std::size_t z_step, const bool should_ylikuutio_use_real_texture_coordinates, std::vector<glm::vec3>& temp_vertices, std::vector<glm::vec2>& temp_UVs) { std::cout << "Interpolating center vertices.\n"; if (image_width < 2 || image_height < 2) { // Can not interpolate center vertices if image width < 2 or image height < 2. return false; } if (x_step <= 0 || z_step <= 0) { // Can not interpolate center vertices if x_step <= 0 or z_step <= 0. return false; } // Elevation maps are created using a mapping from [min_y_value, max_y_value] to [0, 1]. // `min_y_value` & `max_y_value` are needed only for elevation maps. float min_y_value = NAN; float max_y_value = NAN; float divisor = NAN; if (!should_ylikuutio_use_real_texture_coordinates) { bool result = yli::geometry::compute_range( input_vertex_pointer, image_width, image_height, x_step, z_step, min_y_value, max_y_value, divisor); if (!result) { return false; } } // Then, define the faces in a double loop. // Begin from index `z_step`. for (std::size_t z = z_step; z < image_height; z += z_step) { // Begin from index `x_step`. for (std::size_t x = x_step; x < image_width; x += x_step) { // This corresponds to "f": specify a face (but here we specify 2 faces instead!). // Interpolate y coordinate (altitude). const float y = center_y(x, z, input_vertex_pointer, image_width, x_step, z_step); // Create a new vertex using bilinear interpolation. // This corresponds to "v": specify one vertex. glm::vec3 vertex; vertex.x = static_cast<float>(x) - 0.5f * x_step; vertex.y = static_cast<float>(y); vertex.z = static_cast<float>(z) - 0.5f * z_step; temp_vertices.push_back(vertex); // This corresponds to "vt": specify texture coordinates of one vertex. glm::vec2 uv; if (should_ylikuutio_use_real_texture_coordinates) { uv.x = 0.5f; uv.y = 0.5f; } else { uv.x = static_cast<float>(y - min_y_value) / divisor; uv.y = 0.0f; } temp_UVs.push_back(uv); } } return true; }