2014-06-08 10:13:29 +04:00
|
|
|
/* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2013-2014 Kevin Lange
|
|
|
|
*/
|
2012-07-07 08:08:28 +04:00
|
|
|
/*
|
|
|
|
* drawlines
|
|
|
|
*
|
|
|
|
* Test application to draw lines to a window.
|
|
|
|
*/
|
2012-02-12 04:54:34 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2014-04-16 07:08:12 +04:00
|
|
|
#include <syscall.h>
|
|
|
|
#include <unistd.h>
|
2012-02-12 04:54:34 +04:00
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
#include "lib/yutani.h"
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
#include "lib/graphics.h"
|
2014-04-16 07:08:12 +04:00
|
|
|
#include "lib/pthread.h"
|
2012-02-12 04:54:34 +04:00
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
static int left, top, width, height;
|
2012-02-12 04:54:34 +04:00
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
static yutani_t * yctx;
|
|
|
|
static yutani_window_t * wina;
|
|
|
|
static gfx_context_t * ctx;
|
|
|
|
static int should_exit = 0;
|
|
|
|
|
|
|
|
static int32_t min(int32_t a, int32_t b) {
|
2012-02-12 04:54:34 +04:00
|
|
|
return (a < b) ? a : b;
|
|
|
|
}
|
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
static int32_t max(int32_t a, int32_t b) {
|
2012-02-12 04:54:34 +04:00
|
|
|
return (a > b) ? a : b;
|
|
|
|
}
|
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
void * draw_thread(void * garbage) {
|
|
|
|
(void)garbage;
|
|
|
|
while (!should_exit) {
|
|
|
|
draw_line(ctx, rand() % width, rand() % width, rand() % height, rand() % height, rgb(rand() % 255,rand() % 255,rand() % 255));
|
|
|
|
yutani_flip(yctx, wina);
|
|
|
|
usleep(16666);
|
|
|
|
}
|
|
|
|
pthread_exit(0);
|
2012-11-16 11:33:45 +04:00
|
|
|
}
|
2012-02-12 04:54:34 +04:00
|
|
|
|
2012-11-16 11:33:45 +04:00
|
|
|
int main (int argc, char ** argv) {
|
|
|
|
left = 100;
|
|
|
|
top = 100;
|
|
|
|
width = 500;
|
|
|
|
height = 500;
|
2012-02-12 04:54:34 +04:00
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
yctx = yutani_init();
|
|
|
|
wina = yutani_window_create(yctx, width, height);
|
|
|
|
yutani_window_move(yctx, wina, left, top);
|
2012-02-13 03:00:21 +04:00
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
ctx = init_graphics_yutani(wina);
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
draw_fill(ctx, rgb(0,0,0));
|
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
pthread_t thread;
|
|
|
|
pthread_create(&thread, NULL, draw_thread, NULL);
|
2012-02-16 09:14:36 +04:00
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
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;
|
|
|
|
syscall_yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-05-20 05:34:05 +04:00
|
|
|
case YUTANI_MSG_SESSION_END:
|
|
|
|
should_exit = 1;
|
|
|
|
break;
|
2014-04-16 07:08:12 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-16 07:22:02 +04:00
|
|
|
free(m);
|
2012-02-12 04:54:34 +04:00
|
|
|
}
|
|
|
|
|
2014-04-16 07:08:12 +04:00
|
|
|
yutani_close(yctx, wina);
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|