Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * OpenTyrian: A modern cross-platform port of Tyrian
  3.  * Copyright (C) 2007-2009  The OpenTyrian Development Team
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License
  7.  * as published by the Free Software Foundation; either version 2
  8.  * of the License, or (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18.  */
  19. #include "vga256d.h"
  20.  
  21. #include "config.h" // For fullscreen stuff
  22. #include "keyboard.h"
  23. #include "opentyr.h"
  24. #include "palette.h"
  25. #include "video.h"
  26.  
  27. #include "SDL.h"
  28.  
  29. #include <assert.h>
  30. #include <ctype.h>
  31. #include <math.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34.  
  35. void JE_pix( SDL_Surface *surface, int x, int y, JE_byte c )
  36. {
  37.         /* Bad things happen if we don't clip */
  38.         if (x <  surface->pitch && y <  surface->h)
  39.         {
  40.                 Uint8 *vga = surface->pixels;
  41.                 vga[y * surface->pitch + x] = c;
  42.         }
  43. }
  44.  
  45. void JE_pix3( SDL_Surface *surface, int x, int y, JE_byte c )
  46. {
  47.         /* Originally impemented as several direct accesses */
  48.         JE_pix(surface, x, y, c);
  49.         JE_pix(surface, x - 1, y, c);
  50.         JE_pix(surface, x + 1, y, c);
  51.         JE_pix(surface, x, y - 1, c);
  52.         JE_pix(surface, x, y + 1, c);
  53. }
  54.  
  55. void JE_rectangle( SDL_Surface *surface, int a, int b, int c, int d, int e ) /* x1, y1, x2, y2, color */
  56. {
  57.         if (a < surface->pitch && b < surface->h &&
  58.             c < surface->pitch && d < surface->h)
  59.         {
  60.                 Uint8 *vga = surface->pixels;
  61.                 int i;
  62.  
  63.                 /* Top line */
  64.                 memset(&vga[b * surface->pitch + a], e, c - a + 1);
  65.  
  66.                 /* Bottom line */
  67.                 memset(&vga[d * surface->pitch + a], e, c - a + 1);
  68.  
  69.                 /* Left line */
  70.                 for (i = (b + 1) * surface->pitch + a; i < (d * surface->pitch + a); i += surface->pitch)
  71.                 {
  72.                         vga[i] = e;
  73.                 }
  74.  
  75.                 /* Right line */
  76.                 for (i = (b + 1) * surface->pitch + c; i < (d * surface->pitch + c); i += surface->pitch)
  77.                 {
  78.                         vga[i] = e;
  79.                 }
  80.         } else {
  81.                 printf("!!! WARNING: Rectangle clipped: %d %d %d %d %d\n", a, b, c, d, e);
  82.         }
  83. }
  84.  
  85. void fill_rectangle_xy( SDL_Surface *surface, int x, int y, int x2, int y2, Uint8 color )
  86. {
  87.         SDL_Rect rect = { x, y, x2 - x + 1, y2 - y + 1 };
  88.         SDL_FillRect(surface, &rect, color);
  89. }
  90.  
  91. void JE_barShade( SDL_Surface *surface, int a, int b, int c, int d ) /* x1, y1, x2, y2 */
  92. {
  93.         if (a < surface->pitch && b < surface->h &&
  94.             c < surface->pitch && d < surface->h)
  95.         {
  96.                 Uint8 *vga = surface->pixels;
  97.                 int i, j, width;
  98.  
  99.                 width = c - a + 1;
  100.  
  101.                 for (i = b * surface->pitch + a; i <= d * surface->pitch + a; i += surface->pitch)
  102.                 {
  103.                         for (j = 0; j < width; j++)
  104.                         {
  105.                                 vga[i + j] = ((vga[i + j] & 0x0F) >> 1) | (vga[i + j] & 0xF0);
  106.                         }
  107.                 }
  108.         } else {
  109.                 printf("!!! WARNING: Darker Rectangle clipped: %d %d %d %d\n", a,b,c,d);
  110.         }
  111. }
  112.  
  113. void JE_barBright( SDL_Surface *surface, int a, int b, int c, int d ) /* x1, y1, x2, y2 */
  114. {
  115.         if (a < surface->pitch && b < surface->h &&
  116.             c < surface->pitch && d < surface->h)
  117.         {
  118.                 Uint8 *vga = surface->pixels;
  119.                 int i, j, width;
  120.  
  121.                 width = c-a+1;
  122.  
  123.                 for (i = b * surface->pitch + a; i <= d * surface->pitch + a; i += surface->pitch)
  124.                 {
  125.                         for (j = 0; j < width; j++)
  126.                         {
  127.                                 JE_byte al, ah;
  128.                                 al = ah = vga[i + j];
  129.  
  130.                                 ah &= 0xF0;
  131.                                 al = (al & 0x0F) + 2;
  132.  
  133.                                 if (al > 0x0F)
  134.                                 {
  135.                                         al = 0x0F;
  136.                                 }
  137.  
  138.                                 vga[i + j] = al + ah;
  139.                         }
  140.                 }
  141.         } else {
  142.                 printf("!!! WARNING: Brighter Rectangle clipped: %d %d %d %d\n", a,b,c,d);
  143.         }
  144. }
  145.  
  146. void draw_segmented_gauge( SDL_Surface *surface, int x, int y, Uint8 color, uint segment_width, uint segment_height, uint segment_value, uint value )
  147. {
  148.         assert(segment_width > 0 && segment_height > 0);
  149.  
  150.         const uint segments = value / segment_value,
  151.                    partial_segment = value % segment_value;
  152.  
  153.         for (uint i = 0; i < segments; ++i)
  154.         {
  155.                 fill_rectangle_hw(surface, x, y, segment_width, segment_height, color + 12);
  156.                 x += segment_width + 1;
  157.         }
  158.         if (partial_segment > 0)
  159.                 fill_rectangle_hw(surface, x, y, segment_width, segment_height, color + (12 * partial_segment / segment_value));
  160. }
  161.  
  162.