void * draw_thread(void * garbage) { (void)garbage; double time = 0; /* Generate a palette */ uint32_t palette[256]; for (int x = 0; x < 256; ++x) { palette[x] = hsv_to_rgb(x,1.0,1.0); } while (!should_exit) { time += 1.0; int w = win_width; int h = win_height; spin_lock(&draw_lock); for (int x = 0; x < win_width; ++x) { for (int y = 0; y < win_height; ++y) { double value = sin(dist(x + time, y, 128.0, 128.0) / 8.0) + sin(dist(x, y, 64.0, 64.0) / 8.0) + sin(dist(x, y + time / 7, 192.0, 64) / 7.0) + sin(dist(x, y, 192.0, 100.0) / 8.0); GFX(ctx, x + off_x, y + off_y) = palette[(int)((value + 4) * 32)]; } } redraw_borders(); flip(ctx); yutani_flip(yctx, wina); spin_unlock(&draw_lock); syscall_yield(); } }
struct windows* prepare_windows(struct conf* cnf) { struct windows* W = malloc(sizeof(struct windows)); int t_size; int r_size; int buf_size; if (cnf == NULL | cnf->t_size == 0) { t_size = 6; } else { t_size = cnf->t_size; } if (cnf == NULL | cnf->t_size == 0) { r_size = 25; } else { r_size = cnf->r_size; } if (cnf == NULL | cnf->buffer < 2*LINES) { buf_size = 2*LINES; } else { buf_size = cnf->buffer; } W->t_win = create_window(t_size+1,COLS,0,0,buf_size); W->r_win = create_window(LINES-t_size-1,r_size+1,t_size+1,COLS-r_size-1,buf_size); W->b_win = create_window(2,COLS-r_size-1,LINES-2,0,buf_size); W->m_win = create_window(LINES-t_size-3,COLS-r_size-1,t_size+1,0,buf_size); redraw_borders(W); return W; }
void resize_callback(window_t * window) { win_width = window->width - decor_width(); win_height = window->height - decor_height(); reinit_graphics_window(ctx, wina); draw_fill(ctx, rgb(0,0,0)); redraw_borders(); flip(ctx); }
int main (int argc, char ** argv) { char * _windowed = getenv("DISPLAY"); if (_windowed) { setup_windowing(); resize_window_callback = resize_callback; win_width = 500; win_height = 500; init_decorations(); off_x = decor_left_width; off_y = decor_top_height; /* Do something with a window */ wina = window_create(300, 300, win_width + decor_width(), win_height + decor_height()); assert(wina); ctx = init_graphics_window_double_buffer(wina); } else { ctx = init_graphics_fullscreen_double_buffer(); win_width = ctx->width; win_height = ctx->height; off_x = 0; off_y = 0; } draw_fill(ctx, rgb(0,0,0)); redraw_borders(); flip(ctx); double time; /* Generate a palette */ uint32_t palette[256]; for (int x = 0; x < 256; ++x) { palette[x] = hsv_to_rgb(x,1.0,1.0); } while (1) { if (_windowed) { w_keyboard_t * kbd = poll_keyboard_async(); if (kbd) { char ch = kbd->key; free(kbd); if (ch == 'q') { goto done; break; } } } time += 1.0; int w = win_width; int h = win_height; for (int x = 0; x < win_width; ++x) { for (int y = 0; y < win_height; ++y) { double value = sin(dist(x + time, y, 128.0, 128.0) / 8.0) + sin(dist(x, y, 64.0, 64.0) / 8.0) + sin(dist(x, y + time / 7, 192.0, 64) / 7.0) + sin(dist(x, y, 192.0, 100.0) / 8.0); GFX(ctx, x + off_x, y + off_y) = palette[(int)((value + 4) * 32)]; } } redraw_borders(); flip(ctx); } done: if (_windowed) { teardown_windowing(); } return 0; }
int main (int argc, char ** argv) { yctx = yutani_init(); win_width = 100; win_height = 100; init_decorations(); off_x = decor_left_width; off_y = decor_top_height; /* Do something with a window */ wina = yutani_window_create(yctx, win_width + decor_width(), win_height + decor_height()); yutani_window_move(yctx, wina, 300, 300); ctx = init_graphics_yutani_double_buffer(wina); draw_fill(ctx, rgb(0,0,0)); redraw_borders(); flip(ctx); yutani_flip(yctx, wina); yutani_window_advertise(yctx, wina, "Graphics Test"); pthread_t thread; pthread_create(&thread, NULL, draw_thread, NULL); 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.action == KEY_ACTION_DOWN && ke->event.keycode == 'q') { should_exit = 1; } } break; case YUTANI_MSG_WINDOW_FOCUS_CHANGE: { struct yutani_msg_window_focus_change * wf = (void*)m->data; yutani_window_t * win = hashmap_get(yctx->windows, (void*)wf->wid); if (win) { win->focused = wf->focused; } } break; case YUTANI_MSG_SESSION_END: should_exit = 1; break; case YUTANI_MSG_RESIZE_OFFER: { struct yutani_msg_window_resize * wr = (void*)m->data; spin_lock(&draw_lock); resize_finish(wr->width, wr->height); spin_unlock(&draw_lock); } break; case YUTANI_MSG_WINDOW_MOUSE_EVENT: if (decor_handle_event(yctx, m) == DECOR_CLOSE) { should_exit = 1; } break; default: break; } free(m); } } yutani_close(yctx, wina); return 0; }