/***************************** cursor.c ******************************/ #include "sdi.h" /* * Copyright 1987 by Mark Weiser. * Permission to reproduce and use in any manner whatsoever on Suns is granted * so long as this copyright and other identifying marks of authorship * in the code and the game remain intact and visible. Use of this code * in other products is reserved to me--I'm working on Mac and IBM versions. */ /* * Code to manage the dynamic cursor. */ Xv_Cursor compute_cursor(); struct pixrect *compute_cursor_image(); static short dynacursor_data[] = { #include "dynacursor.h" }; mpr_static(dynabase_cursor_pr, 16, 16, 1, dynacursor_data); static short cursor_data[] = { #include "cursor.h" }; mpr_static(base_cursor_pr, 16, 16, 1, cursor_data); static short tmp_data[16]; mpr_static(cursor_tmp_pr, 16, 16, 1, tmp_data); init_cursor() { static Xv_Cursor main_cursor = NULL; extern int cursor_type; if (main_cursor) { cursor_destroy(main_cursor); } switch(cursor_type) { case 0: main_cursor = xv_create(XV_NULL, CURSOR, CURSOR_IMAGE, xv_create(XV_NULL, SERVER_IMAGE, XV_WIDTH, 16, XV_HEIGHT, 16, SERVER_IMAGE_BITS, cursor_data, NULL), CURSOR_XHOT, 8, CURSOR_YHOT, 8, 0); break; case 1: main_cursor = xv_create(XV_NULL, CURSOR, CURSOR_IMAGE, xv_create(XV_NULL, SERVER_IMAGE, XV_WIDTH, 16, XV_HEIGHT, 16, SERVER_IMAGE_BITS, dynacursor_data, NULL), CURSOR_XHOT, 8, CURSOR_YHOT, 3, 0); break; case 2: break; case 3: break; } xv_set(launchpw, WIN_CURSOR, main_cursor, 0); xv_set(citypw, WIN_CURSOR, main_cursor, 0); } update_cursor() { extern int cursor_type; switch (cursor_type) { case 1: case 3: { Xv_Cursor cursor, oldcursor1, oldcursor2; cursor = compute_cursor(); oldcursor1 = xv_get(launchpw, WIN_CURSOR); oldcursor2 = xv_get(citypw, WIN_CURSOR); xv_set(launchpw, WIN_CURSOR, compute_cursor(), 0); xv_set(citypw, WIN_CURSOR, compute_cursor(), 0); /* only one copy of the image... */ xv_destroy_safe(xv_get(oldcursor1, CURSOR_IMAGE)); break; } default: break; } } Xv_Cursor compute_cursor() { Xv_Cursor main_cursor; struct pixrect *newimage; newimage = compute_cursor_image(); main_cursor = xv_create(XV_NULL, CURSOR, CURSOR_IMAGE, xv_create(XV_NULL, SERVER_IMAGE, XV_WIDTH, 16, XV_HEIGHT, 16, SERVER_IMAGE_BITS, tmp_data, NULL), CURSOR_XHOT, 8, CURSOR_YHOT, 3, 0); return main_cursor; } /* Returns a static structure, so get rid of it before reusing it. */ struct pixrect * compute_cursor_image() { extern Panel_item rock_item; int left_current = (int)xv_get(interceptor_item, PANEL_VALUE); int left_max = (int)xv_get(interceptor_item, PANEL_MAX_VALUE); int middle_current = (int)xv_get(rock_item, PANEL_VALUE); int middle_max = (int)xv_get(rock_item, PANEL_MAX_VALUE); int right_current = (int)xv_get(laser_item, PANEL_VALUE); int right_max = (int)xv_get(laser_item, PANEL_MAX_VALUE); pr_rop(&cursor_tmp_pr, 0, 0, 16, 16, PIX_SRC, &dynabase_cursor_pr, 0, 0); put_line(&cursor_tmp_pr, 1, 8, 15, left_current, left_max); put_line(&cursor_tmp_pr, 7, 8, 15, middle_current, middle_max); put_line(&cursor_tmp_pr, 13, 8, 15, right_current, right_max); return &cursor_tmp_pr; } /* * Draw a double-width line in pr from start to finish, with * length equal current/max. assumes finish > start. */ put_line(pr, x, start, finish, current, max) struct pixrect *pr; { int length = (current*(finish-start+1))/max; if (length == 0 && current != 0) length = 1; pr_vector(pr, x, start-1, x, start+length-1, PIX_SRC, 1); pr_vector(pr, x+1, start-1, x+1, start+length-1, PIX_SRC, 1); pr_vector(pr, x+2, start-1, x+2, start+length-1, PIX_SRC, 1); }