~ubuntu-branches/ubuntu/natty/airstrike/natty

« back to all changes in this revision

Viewing changes to src/support/console.c

  • Committer: Bazaar Package Importer
  • Author(s): Sven Velt
  • Date: 2004-02-03 00:25:29 UTC
  • Revision ID: james.westby@ubuntu.com-20040203002529-6n4ejqo7nyqh2hu0
Tags: upstream-0.99+1.0pre6a
ImportĀ upstreamĀ versionĀ 0.99+1.0pre6a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <assert.h>
 
2
#include <SDL_image.h>
 
3
#include "console.h"
 
4
#include "sprite.h"
 
5
#include "text.h"
 
6
 
 
7
static char lines[CONSOLE_LINES][CONSOLE_COLUMNS+1];
 
8
static int firstline;
 
9
static int atline,atcol; /*atline is counted _from fistline_ */
 
10
static int xpos,ypos;
 
11
static SDL_Surface *bg = 0;
 
12
 
 
13
int console_setup()
 
14
{
 
15
  firstline = 0;
 
16
  return 0;
 
17
}
 
18
 
 
19
void console_set_pos(int x, int y)
 
20
{
 
21
  xpos = x;
 
22
  ypos = y;
 
23
}
 
24
 
 
25
void console_load_bg(char *filename)
 
26
{
 
27
  SDL_Surface *tmp;
 
28
  assert(tmp  = IMG_Load(filename));
 
29
  bg = SDL_DisplayFormatAlpha(tmp);
 
30
  SDL_FreeSurface(tmp);
 
31
}
 
32
 
 
33
void console_draw()
 
34
{
 
35
  int row,y = ypos;
 
36
  SDL_Rect r;
 
37
  if (bg)
 
38
    {
 
39
      r.x = xpos - 4;
 
40
      r.y = ypos - 4;
 
41
      r.w = bg->w;
 
42
      r.h = bg->h;
 
43
      SDL_BlitSurface(bg,0,sprite_global.display,&r);
 
44
      sprite_dirty(&r);
 
45
    }
 
46
 
 
47
  r.x = xpos;
 
48
  r.y = ypos;
 
49
  row = firstline;
 
50
  do
 
51
    {
 
52
      text_render(sprite_global.display,&r,big_font,
 
53
                  xpos,y,ALIGN_LEFT,ALIGN_TOP,
 
54
                  lines[row]);
 
55
      y += r.h;
 
56
      row = (row + 1) % CONSOLE_LINES;
 
57
    }
 
58
  while (row != firstline);
 
59
}
 
60
 
 
61
void console_update()
 
62
{
 
63
 
 
64
}
 
65
 
 
66
void console_write(const char *s)
 
67
{
 
68
  while (*s)
 
69
    {
 
70
      assert(atcol <= CONSOLE_COLUMNS);
 
71
      if ((atcol >= CONSOLE_COLUMNS) || (*s == '\n'))
 
72
        {
 
73
          lines[(firstline + atline) % CONSOLE_LINES][atcol] = 0;
 
74
          atline++;
 
75
          atcol = 0;
 
76
          lines[(firstline + atline) % CONSOLE_LINES][atcol] = 0;
 
77
          if (atline >= CONSOLE_LINES)
 
78
            {
 
79
              atline = CONSOLE_LINES - 1;
 
80
              firstline = (firstline + 1) % CONSOLE_LINES;
 
81
            }
 
82
        }
 
83
      else
 
84
        {
 
85
          lines[(firstline + atline) % CONSOLE_LINES][atcol++] = *s;
 
86
        }
 
87
      s++;
 
88
    }
 
89
  lines[(firstline + atline) % CONSOLE_LINES][atcol] = 0;
 
90
}
 
91
 
 
92
void console_clear()
 
93
{
 
94
  int i;
 
95
  firstline = 0;
 
96
  atline = 0;
 
97
  atcol = 0;
 
98
  for (i=0;i<CONSOLE_LINES;i++)
 
99
    {
 
100
      lines[i][0] = 0;
 
101
    }
 
102
}
 
103