42 GlyphRenderer::GlyphRenderer() |
41 GlyphRenderer::GlyphRenderer() |
43 : _font_regular(NULL), _font_bold(NULL), _cell_width(0), _cell_height(0), _cache(), _colormap() |
42 : _font_regular(NULL), _font_bold(NULL), _cell_width(0), _cell_height(0), _cache(), _colormap() |
44 { |
43 { |
45 if (TTF_Init() == -1) |
44 if (TTF_Init() == -1) |
46 { |
45 { |
47 printf("TTF_Init: %s\n", TTF_GetError()); |
46 throw SDLTermError(std::string("TTF_Init: ") + TTF_GetError()); |
48 throw std::exception(); |
|
49 } |
47 } |
50 } |
48 } |
51 |
49 |
52 |
50 |
53 GlyphRenderer::~GlyphRenderer() |
51 GlyphRenderer::~GlyphRenderer() |
64 |
62 |
65 // open regular font |
63 // open regular font |
66 _font_regular = TTF_OpenFont(fname_regular, ptsize); |
64 _font_regular = TTF_OpenFont(fname_regular, ptsize); |
67 if (!_font_regular) |
65 if (!_font_regular) |
68 { |
66 { |
69 printf("TTF_OpenFont: %s\n", TTF_GetError()); |
67 throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError()); |
70 throw std::exception(); |
|
71 } |
68 } |
72 |
69 |
73 // open bold font |
70 // open bold font |
74 _font_bold = TTF_OpenFont(fname_bold, ptsize); |
71 _font_bold = TTF_OpenFont(fname_bold, ptsize); |
75 if (!_font_bold) |
72 if (!_font_bold) |
76 { |
73 { |
77 printf("TTF_OpenFont: %s\n", TTF_GetError()); |
74 throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError()); |
78 throw std::exception(); |
|
79 } |
75 } |
80 |
76 |
81 // update metrics for regular font |
77 // update metrics for regular font |
82 int advance; |
78 int advance; |
83 if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1) |
79 if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1) |
84 { |
80 { |
85 printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); |
81 throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError()); |
86 } |
82 } |
87 _cell_width = advance; |
83 _cell_width = advance; |
88 _cell_height = TTF_FontHeight(_font_regular); |
84 _cell_height = TTF_FontHeight(_font_regular); |
89 |
85 |
90 // read metrics for bold font |
86 // read metrics for bold font |
91 if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1) |
87 if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1) |
92 { |
88 { |
93 printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); |
89 throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError()); |
94 } |
90 } |
95 if (advance > _cell_width) |
91 if (advance > _cell_width) |
96 { |
92 { |
97 _cell_width = advance; |
93 _cell_width = advance; |
98 } |
94 } |
219 { |
215 { |
220 _screen_surface = SDL_SetVideoMode(pxwidth, pxheight, 0, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_RESIZABLE); |
216 _screen_surface = SDL_SetVideoMode(pxwidth, pxheight, 0, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_RESIZABLE); |
221 |
217 |
222 if (_screen_surface == NULL) |
218 if (_screen_surface == NULL) |
223 { |
219 { |
224 fprintf(stderr, "Unable to set video: %s\n", SDL_GetError()); |
220 throw SDLTermError(std::string("SDL_SetVideoMode: ") + SDL_GetError()); |
225 throw std::exception(); |
|
226 } |
221 } |
227 |
222 |
228 _pixel_width = pxwidth; |
223 _pixel_width = pxwidth; |
229 _pixel_height = pxheight; |
224 _pixel_height = pxheight; |
230 |
225 |
310 : _screen(), _attr(7), _cursor_x(0), _cursor_y(0), _cursor_visible(false), |
305 : _screen(), _attr(7), _cursor_x(0), _cursor_y(0), _cursor_visible(false), |
311 _mousemove_last_x(-1), _mousemove_last_y(-1) |
306 _mousemove_last_x(-1), _mousemove_last_y(-1) |
312 { |
307 { |
313 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) |
308 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) |
314 { |
309 { |
315 fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); |
310 throw SDLTermError(std::string("SDL_Init: ") + SDL_GetError()); |
316 throw std::exception(); |
|
317 } |
311 } |
318 SDL_EnableUNICODE(1); |
312 SDL_EnableUNICODE(1); |
319 SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); |
313 SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); |
320 SDL_WM_SetCaption("terminal", NULL); |
314 SDL_WM_SetCaption("terminal", NULL); |
321 } |
315 } |