279 lines
6.4 KiB
C
279 lines
6.4 KiB
C
str screen_namespace = "/dev/screen/0";
|
|
str mouse_namespace = "/dev/mouse/0";
|
|
byte BLACK = 0;
|
|
byte WHITE = 255;
|
|
byte DARK_GRAY = 73;
|
|
byte GRAY = 146;
|
|
byte LIGHT_GRAY = 182;
|
|
byte CHARCOAL = 36;
|
|
byte DARK_RED = 128;
|
|
byte RED = 224;
|
|
byte DARK_YELLOW = 144;
|
|
byte YELLOW = 252;
|
|
byte DARK_TEAL = 9;
|
|
byte TEAL = 18;
|
|
byte DARK_GREEN = 12;
|
|
byte GREEN = 16;
|
|
byte LIME = 28;
|
|
byte LIGHT_CYAN = 159;
|
|
byte NAVY = 2;
|
|
byte BLUE = 3;
|
|
byte DEEP_SKY_BLUE = 10;
|
|
byte LIGHT_BLUE = 19;
|
|
byte PURPLE = 131;
|
|
byte LIGHT_PURPLE = 147;
|
|
byte DARK_MAGENTA = 130;
|
|
byte MAGENTA = 227;
|
|
byte PLUM = 129;
|
|
byte PINK = 226;
|
|
byte SADDLE_BROWN = 72;
|
|
byte PERU = 141;
|
|
byte SIENNA = 136;
|
|
byte ORANGE = 241;
|
|
byte DARK_ORANGE = 208;
|
|
byte GOLD = 244;
|
|
byte SELECTED_COLOR = 255;
|
|
|
|
plex Screen {
|
|
nat handle;
|
|
nat width;
|
|
nat height;
|
|
byte[] buffer;
|
|
}
|
|
|
|
plex Mouse {
|
|
nat handle;
|
|
nat x;
|
|
nat y;
|
|
bool left;
|
|
bool right;
|
|
bool middle;
|
|
bool btn4;
|
|
}
|
|
|
|
function main () {
|
|
str screen_name = screen_namespace;
|
|
int mode = 0;
|
|
Screen screen = open(screen_name, mode);
|
|
|
|
nat width = screen.width;
|
|
nat size = screen.size;
|
|
nat screen_offset = 16;
|
|
nat screen_buffer = screen_buffer + screen_offset;
|
|
|
|
// open mouse
|
|
str mouse_name = mouse_namespace;
|
|
Mouse mouse = open(mouse_name, mode);
|
|
|
|
byte color = BLACK;
|
|
nat x_pos = 1;
|
|
nat y_pos = 1;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = WHITE;
|
|
x_pos = 21;
|
|
y_pos = 1;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = CHARCOAL;
|
|
x_pos = 1;
|
|
y_pos = 21;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = DARK_GRAY;
|
|
x_pos = 21;
|
|
y_pos = 21;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = RED;
|
|
x_pos = 1;
|
|
y_pos = 41;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = ORANGE;
|
|
x_pos = 21;
|
|
y_pos = 41;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = YELLOW;
|
|
x_pos = 1;
|
|
y_pos = 61;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = GREEN;
|
|
x_pos = 21;
|
|
y_pos = 61;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = BLUE;
|
|
x_pos = 1;
|
|
y_pos = 81;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
color = PURPLE;
|
|
x_pos = 21;
|
|
y_pos = 81;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
|
|
// screen.draw
|
|
write(screen, screen_buffer, size);
|
|
|
|
nat zero = 0;
|
|
|
|
loop draw {
|
|
// load mouse click data
|
|
refresh(mouse);
|
|
|
|
byte left_down = mouse.down;
|
|
|
|
jump_eq_nat draw left_down zero; // if (!btn1.left) continue;
|
|
|
|
nat mouse_x = mouse.x;
|
|
nat mouse_y = mouse.y;
|
|
|
|
nat box_size = 20;
|
|
|
|
// first row
|
|
color = BLACK;
|
|
x_pos = 1;
|
|
y_pos = 1;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = WHITE;
|
|
x_pos = 21;
|
|
y_pos = 1;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = CHARCOAL;
|
|
x_pos = 1;
|
|
y_pos = 21;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
DARK_GRAY -> color;
|
|
x_pos = 21;
|
|
y_pos = 21;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = RED;
|
|
x_pos = 1;
|
|
y_pos = 41;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = ORANGE;
|
|
x_pos = 21;
|
|
y_pos = 41;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = YELLOW;
|
|
x_pos = 1;
|
|
y_pos = 61;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = GREEN;
|
|
x_pos = 21;
|
|
y_pos = 61;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = BLUE;
|
|
x_pos = 1;
|
|
y_pos = 81;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
color = PURPLE;
|
|
x_pos = 21;
|
|
y_pos = 81;
|
|
draw_outlined_swatch(screen_buffer, color, x_pos, y_pos, width);
|
|
set_color(mouse_x, mouse_y, x_pos, y_pos, color, box_size);
|
|
|
|
write(screen, screen_buffer, size);
|
|
|
|
byte selected_color = SELECTED_COLOR;
|
|
|
|
nat brush_size = 5;
|
|
|
|
draw_box(screen_buffer, width, selected_color, mouse_x, mouse_y, brush_size, brush_size);
|
|
|
|
jump draw;
|
|
}
|
|
|
|
// Flush and exit
|
|
exit 0;
|
|
}
|
|
|
|
function set_color (int click_x, int click_y, int box_x, int box_y, byte check_color, int size) {
|
|
|
|
// Compute right
|
|
int right_edge = box_x + size;
|
|
|
|
// Compute bottom = box_y + size
|
|
int bottom_edge = box_y + size;
|
|
|
|
// Bounds check: x in [box_x, right] and y in [box_y, bottom]
|
|
jump_lt_int fail click_x box_x;
|
|
jump_gt_int fail click_x right_edge;
|
|
jump_lt_int fail click_y box_y;
|
|
jump_gt_int fail click_y bottom_edge;
|
|
|
|
SELECTED_COLOR = check_color;
|
|
|
|
else fail
|
|
return;
|
|
}
|
|
|
|
function draw_outlined_swatch(nat base, byte swatch_color, int x, int y, int width) {
|
|
|
|
nat background_color = GRAY;
|
|
byte selected_color = SELECTED_COLOR;
|
|
|
|
jump_eq_int set_selected swatch_color selected_color;
|
|
jump end_set_selected;
|
|
do set_selected
|
|
background_color = DARK_GRAY;
|
|
else end_set_selected
|
|
|
|
nat outline_size = 20;
|
|
nat fill_size = 17;
|
|
|
|
draw_box(base, width, background_color, x, y, outline_size, outline_size);
|
|
|
|
nat offset = 2;
|
|
int xO = x + offset; // x + 2
|
|
int yO = y + offset; // y + 2
|
|
|
|
draw_box(base, width, swatch_color, xO, yO, fill_size, fill_size);
|
|
|
|
return;
|
|
}
|
|
|
|
function draw_box (nat base, nat screen_width, byte box_color,
|
|
nat x, nat y, nat width, nat height) {
|
|
|
|
nat fat_ptr_size = 4;
|
|
|
|
// Compute start address: base + y*640 + x
|
|
nat offset = y * screen_width;
|
|
offset = offset + x;
|
|
offset = offset + base;
|
|
offset = offset + fat_ptr_size; // need to add offset for fat pointer size
|
|
|
|
int i = 1;
|
|
int zero = 0;
|
|
|
|
loop draw_box_outer {
|
|
memset(offset, width, box_color); // draw row
|
|
offset = offset + screen_width; // next row += 640
|
|
height = height - i; // decrement row count
|
|
jump_gt_int draw_box_outer height zero;
|
|
}
|
|
return;
|
|
}
|