direct cv->chars and cv->attrs access by display drivers.tags/v0.99.beta14
@@ -33,7 +33,6 @@ | |||||
#endif | #endif | ||||
#include "cucul.h" | #include "cucul.h" | ||||
#include "cucul_internals.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
@@ -129,8 +128,8 @@ caca_display_t * caca_create_display(cucul_canvas_t *cv) | |||||
dp->lastticks = 0; | dp->lastticks = 0; | ||||
/* Mouse position */ | /* Mouse position */ | ||||
dp->mouse.x = dp->cv->width / 2; | |||||
dp->mouse.y = dp->cv->height / 2; | |||||
dp->mouse.x = cucul_get_canvas_width(dp->cv) / 2; | |||||
dp->mouse.y = cucul_get_canvas_height(dp->cv) / 2; | |||||
/* Resize events */ | /* Resize events */ | ||||
dp->resize.resized = 0; | dp->resize.resized = 0; | ||||
@@ -23,10 +23,9 @@ | |||||
#import <Cocoa/Cocoa.h> | #import <Cocoa/Cocoa.h> | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
//#define COCOA_DEBUG | //#define COCOA_DEBUG | ||||
@@ -196,13 +195,14 @@ static BOOL s_quitting = NO; | |||||
- (void)resizeIfNeeded:(caca_display_t *)dp | - (void)resizeIfNeeded:(caca_display_t *)dp | ||||
{ | { | ||||
if( _w != dp->cv->width || _h != dp->cv->height | |||||
|| !_attrs || !_bkg_rects || !_bkg_colors) | |||||
if(_w != cucul_get_canvas_width(dp->cv) | |||||
|| _h != cucul_get_canvas_height(dp->cv) | |||||
|| !_attrs || !_bkg_rects || !_bkg_colors) | |||||
{ | { | ||||
debug_log(@"%s resize to %ux%u", _cmd, _w, _h); | debug_log(@"%s resize to %ux%u", _cmd, _w, _h); | ||||
_w = dp->cv->width; | |||||
_h = dp->cv->height; | |||||
_w = cucul_get_canvas_width(dp->cv); | |||||
_h = cucul_get_canvas_height(dp->cv); | |||||
if(_attrs) | if(_attrs) | ||||
free(_attrs); | free(_attrs); | ||||
@@ -216,8 +216,8 @@ static BOOL s_quitting = NO; | |||||
free(_bkg_colors); | free(_bkg_colors); | ||||
_bkg_colors = malloc(_w * _h * sizeof(NSColor*)); | _bkg_colors = malloc(_w * _h * sizeof(NSColor*)); | ||||
[[self window] setContentSize: NSMakeSize(dp->cv->width * _font_rect.size.width, | |||||
dp->cv->height * _font_rect.size.height)]; | |||||
[[self window] setContentSize: NSMakeSize(cucul_get_canvas_width(dp->cv) * _font_rect.size.width, | |||||
cucul_get_canvas_height(dp->cv) * _font_rect.size.height)]; | |||||
} | } | ||||
} | } | ||||
@@ -228,8 +228,10 @@ static BOOL s_quitting = NO; | |||||
if(_attrs) | if(_attrs) | ||||
{ | { | ||||
_chars = _attrs + _w * _h; | _chars = _attrs + _w * _h; | ||||
memcpy(_attrs, dp->cv->attrs, _w * _h * sizeof(uint32_t)); | |||||
memcpy(_chars, dp->cv->chars, _w * _h * sizeof(uint32_t)); | |||||
memcpy(_attrs, cucul_get_canvas_attrs(dp->cv), | |||||
_w * _h * sizeof(uint32_t)); | |||||
memcpy(_chars, cucul_get_canvas_chars(dp->cv), | |||||
_w * _h * sizeof(uint32_t)); | |||||
[self setNeedsDisplay:TRUE]; | [self setNeedsDisplay:TRUE]; | ||||
} | } | ||||
@@ -570,8 +572,8 @@ static void create_first_window(caca_display_t *dp) | |||||
NSFont* font = [NSFont fontWithName:@"Monaco" size:10]; | NSFont* font = [NSFont fontWithName:@"Monaco" size:10]; | ||||
NSRect fontRect = [font boundingRectForFont]; | NSRect fontRect = [font boundingRectForFont]; | ||||
fontRect = NSMakeRect(0, 0, ceilf(fontRect.size.width), ceilf(fontRect.size.height)); | fontRect = NSMakeRect(0, 0, ceilf(fontRect.size.width), ceilf(fontRect.size.height)); | ||||
NSRect windowRect = NSMakeRect(20, 20, dp->cv->width * fontRect.size.width, | |||||
dp->cv->height * fontRect.size.height); | |||||
NSRect windowRect = NSMakeRect(20, 20, cucul_get_canvas_width(dp->cv) * fontRect.size.width, | |||||
cucul_get_canvas_height(dp->cv) * fontRect.size.height); | |||||
convert_NSRect(&windowRect); | convert_NSRect(&windowRect); | ||||
CacaView* view = [[CacaView alloc] initWithFrame:windowRect]; | CacaView* view = [[CacaView alloc] initWithFrame:windowRect]; | ||||
@@ -824,8 +826,10 @@ static BOOL handle_mouse_event(caca_display_t *dp, struct caca_event *ev, | |||||
static int cocoa_init_graphics(caca_display_t *dp) | static int cocoa_init_graphics(caca_display_t *dp) | ||||
{ | { | ||||
debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, | |||||
dp->cv->width, dp->cv->height); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, width, height); | |||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | ||||
@@ -833,7 +837,6 @@ static int cocoa_init_graphics(caca_display_t *dp) | |||||
if(dp->drv.p == NULL) | if(dp->drv.p == NULL) | ||||
return -1; | return -1; | ||||
unsigned int width = dp->cv->width, height = dp->cv->height; | |||||
dp->resize.allow = 1; | dp->resize.allow = 1; | ||||
cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); | cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); | ||||
dp->resize.allow = 0; | dp->resize.allow = 0; | ||||
@@ -855,7 +858,7 @@ static int cocoa_init_graphics(caca_display_t *dp) | |||||
static int cocoa_end_graphics(caca_display_t *dp) | static int cocoa_end_graphics(caca_display_t *dp) | ||||
{ | { | ||||
debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, | debug_log(@"%s dp->cv: %ux%u", __PRETTY_FUNCTION__, | ||||
dp->cv->width, dp->cv->height); | |||||
cucul_get_canvas_width(dp->cv), cucul_get_canvas_height(dp->cv)); | |||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | ||||
[dp->drv.p->window close]; | [dp->drv.p->window close]; | ||||
@@ -955,8 +958,8 @@ static int cocoa_get_event(caca_display_t *dp, struct caca_event *ev) | |||||
static void cocoa_handle_resize(caca_display_t *dp) | static void cocoa_handle_resize(caca_display_t *dp) | ||||
{ | { | ||||
debug_log(@"%s", __PRETTY_FUNCTION__); | debug_log(@"%s", __PRETTY_FUNCTION__); | ||||
dp->resize.w = dp->cv->width; | |||||
dp->resize.h = dp->cv->height; | |||||
dp->resize.w = cucul_get_canvas_width(dp->cv); | |||||
dp->resize.h = cucul_get_canvas_height(dp->cv); | |||||
} | } | ||||
static int cocoa_set_display_title(caca_display_t *dp, char const *title) | static int cocoa_set_display_title(caca_display_t *dp, char const *title) | ||||
@@ -29,10 +29,9 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
struct driver_private | struct driver_private | ||||
{ | { | ||||
@@ -71,7 +70,7 @@ static int conio_end_graphics(caca_display_t *dp) | |||||
_wscroll = 1; | _wscroll = 1; | ||||
textcolor((enum COLORS)WHITE); | textcolor((enum COLORS)WHITE); | ||||
textbackground((enum COLORS)BLACK); | textbackground((enum COLORS)BLACK); | ||||
gotoxy(dp->cv->width, dp->cv->height); | |||||
gotoxy(cucul_get_canvas_width(dp->cv), cucul_get_canvas_height(dp->cv)); | |||||
cputs("\r\n"); | cputs("\r\n"); | ||||
_setcursortype(_NORMALCURSOR); | _setcursortype(_NORMALCURSOR); | ||||
@@ -89,23 +88,25 @@ static int conio_set_display_title(caca_display_t *dp, char const *title) | |||||
static unsigned int conio_get_display_width(caca_display_t const *dp) | static unsigned int conio_get_display_width(caca_display_t const *dp) | ||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->width * 6; | |||||
return cucul_get_canvas_width(dp->cv) * 6; | |||||
} | } | ||||
static unsigned int conio_get_display_height(caca_display_t const *dp) | static unsigned int conio_get_display_height(caca_display_t const *dp) | ||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->height * 10; | |||||
return cucul_get_canvas_height(dp->cv) * 10; | |||||
} | } | ||||
static void conio_display(caca_display_t *dp) | static void conio_display(caca_display_t *dp) | ||||
{ | { | ||||
char *screen = dp->drv.p->screen; | char *screen = dp->drv.p->screen; | ||||
uint32_t *attrs = dp->cv->attrs; | |||||
uint32_t *chars = dp->cv->chars; | |||||
uint32_t const *chars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *attrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
unsigned int n; | unsigned int n; | ||||
for(n = dp->cv->height * dp->cv->width; n--; ) | |||||
for(n = height * width; n--; ) | |||||
{ | { | ||||
char ch = cucul_utf32_to_cp437(*chars++); | char ch = cucul_utf32_to_cp437(*chars++); | ||||
if(n && *chars == CUCUL_MAGIC_FULLWIDTH) | if(n && *chars == CUCUL_MAGIC_FULLWIDTH) | ||||
@@ -129,8 +130,8 @@ static void conio_display(caca_display_t *dp) | |||||
static void conio_handle_resize(caca_display_t *dp) | static void conio_handle_resize(caca_display_t *dp) | ||||
{ | { | ||||
/* We know nothing about our window */ | /* We know nothing about our window */ | ||||
dp->resize.w = dp->cv->width; | |||||
dp->resize.h = dp->cv->height; | |||||
dp->resize.w = cucul_get_canvas_width(dp->cv); | |||||
dp->resize.h = cucul_get_canvas_height(dp->cv); | |||||
} | } | ||||
static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev) | static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
@@ -36,11 +36,10 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include "caca.h" | |||||
#include "caca_internals.h" | |||||
#include "cucul.h" | #include "cucul.h" | ||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
#include "caca.h" | |||||
#include "caca_internals.h" | |||||
/* | /* | ||||
* Global variables | * Global variables | ||||
@@ -89,7 +88,8 @@ static int gl_init_graphics(caca_display_t *dp) | |||||
char const *geometry; | char const *geometry; | ||||
char *argv[2] = { "", NULL }; | char *argv[2] = { "", NULL }; | ||||
char const * const * fonts; | char const * const * fonts; | ||||
unsigned int width = dp->cv->width, height = dp->cv->height; | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int argc = 1; | int argc = 1; | ||||
dp->drv.p = malloc(sizeof(struct driver_private)); | dp->drv.p = malloc(sizeof(struct driver_private)); | ||||
@@ -123,8 +123,8 @@ static int gl_init_graphics(caca_display_t *dp) | |||||
dp->drv.p->font_width = cucul_get_font_width(dp->drv.p->f); | dp->drv.p->font_width = cucul_get_font_width(dp->drv.p->f); | ||||
dp->drv.p->font_height = cucul_get_font_height(dp->drv.p->f); | dp->drv.p->font_height = cucul_get_font_height(dp->drv.p->f); | ||||
dp->drv.p->width = dp->cv->width * dp->drv.p->font_width; | |||||
dp->drv.p->height = dp->cv->height * dp->drv.p->font_height; | |||||
dp->drv.p->width = cucul_get_canvas_width(dp->cv) * dp->drv.p->font_width; | |||||
dp->drv.p->height = cucul_get_canvas_height(dp->cv) * dp->drv.p->font_height; | |||||
#ifdef HAVE_GLUTCLOSEFUNC | #ifdef HAVE_GLUTCLOSEFUNC | ||||
dp->drv.p->close = 0; | dp->drv.p->close = 0; | ||||
@@ -211,6 +211,9 @@ static unsigned int gl_get_display_height(caca_display_t const *dp) | |||||
static void gl_display(caca_display_t *dp) | static void gl_display(caca_display_t *dp) | ||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int x, y, line; | unsigned int x, y, line; | ||||
glClear(GL_COLOR_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT); | ||||
@@ -219,7 +222,7 @@ static void gl_display(caca_display_t *dp) | |||||
line = 0; | line = 0; | ||||
for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height) | for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height) | ||||
{ | { | ||||
uint32_t *attrs = dp->cv->attrs + line * dp->cv->width; | |||||
uint32_t const *attrs = cvattrs + line * width; | |||||
/* FIXME: optimise using stride */ | /* FIXME: optimise using stride */ | ||||
for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width) | for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width) | ||||
@@ -249,8 +252,8 @@ static void gl_display(caca_display_t *dp) | |||||
line = 0; | line = 0; | ||||
for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height, line++) | for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height, line++) | ||||
{ | { | ||||
uint32_t *attrs = dp->cv->attrs + line * dp->cv->width; | |||||
uint32_t *chars = dp->cv->chars + line * dp->cv->width; | |||||
uint32_t const *attrs = cvattrs + line * width; | |||||
uint32_t const *chars = cvchars + line * width; | |||||
for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width, attrs++) | for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width, attrs++) | ||||
{ | { | ||||
@@ -344,8 +347,8 @@ static int gl_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
if(dp->resize.resized) | if(dp->resize.resized) | ||||
{ | { | ||||
ev->type = CACA_EVENT_RESIZE; | ev->type = CACA_EVENT_RESIZE; | ||||
ev->data.resize.w = dp->cv->width; | |||||
ev->data.resize.h = dp->cv->height; | |||||
ev->data.resize.w = cucul_get_canvas_width(dp->cv); | |||||
ev->data.resize.h = cucul_get_canvas_height(dp->cv); | |||||
return 1; | return 1; | ||||
} | } | ||||
@@ -51,10 +51,9 @@ | |||||
# include <termios.h> | # include <termios.h> | ||||
#endif | #endif | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
/* | /* | ||||
* Emulation for missing ACS_* in older curses | * Emulation for missing ACS_* in older curses | ||||
@@ -331,27 +330,30 @@ static int ncurses_set_display_title(caca_display_t *dp, char const *title) | |||||
static unsigned int ncurses_get_display_width(caca_display_t const *dp) | static unsigned int ncurses_get_display_width(caca_display_t const *dp) | ||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->width * 6; | |||||
return cucul_get_canvas_width(dp->cv) * 6; | |||||
} | } | ||||
static unsigned int ncurses_get_display_height(caca_display_t const *dp) | static unsigned int ncurses_get_display_height(caca_display_t const *dp) | ||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->height * 10; | |||||
return cucul_get_canvas_height(dp->cv) * 10; | |||||
} | } | ||||
static void ncurses_display(caca_display_t *dp) | static void ncurses_display(caca_display_t *dp) | ||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int x, y; | int x, y; | ||||
uint32_t *attrs = dp->cv->attrs; | |||||
uint32_t *chars = dp->cv->chars; | |||||
for(y = 0; y < (int)dp->cv->height; y++) | |||||
for(y = 0; y < (int)height; y++) | |||||
{ | { | ||||
move(y, 0); | move(y, 0); | ||||
for(x = dp->cv->width; x--; ) | |||||
for(x = width; x--; ) | |||||
{ | { | ||||
attrset(dp->drv.p->attr[cucul_attr_to_ansi(*attrs++)]); | |||||
ncurses_write_utf32(*chars++); | |||||
attrset(dp->drv.p->attr[cucul_attr_to_ansi(*cvattrs++)]); | |||||
ncurses_write_utf32(*cvchars++); | |||||
} | } | ||||
} | } | ||||
@@ -382,8 +384,8 @@ static void ncurses_handle_resize(caca_display_t *dp) | |||||
#endif | #endif | ||||
/* Fallback */ | /* Fallback */ | ||||
dp->resize.w = dp->cv->width; | |||||
dp->resize.h = dp->cv->height; | |||||
dp->resize.w = cucul_get_canvas_width(dp->cv); | |||||
dp->resize.h = cucul_get_canvas_height(dp->cv); | |||||
} | } | ||||
static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) | static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
@@ -24,14 +24,14 @@ | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
static int raw_init_graphics(caca_display_t *dp) | static int raw_init_graphics(caca_display_t *dp) | ||||
{ | { | ||||
unsigned int width = dp->cv->width, height = dp->cv->height; | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
char const *geometry; | char const *geometry; | ||||
#if defined(HAVE_GETENV) | #if defined(HAVE_GETENV) | ||||
@@ -34,10 +34,9 @@ | |||||
# include <signal.h> | # include <signal.h> | ||||
#endif | #endif | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
/* | /* | ||||
* Global variables | * Global variables | ||||
@@ -198,26 +197,29 @@ static int slang_set_display_title(caca_display_t *dp, char const *title) | |||||
static unsigned int slang_get_display_width(caca_display_t const *dp) | static unsigned int slang_get_display_width(caca_display_t const *dp) | ||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->width * 6; | |||||
return cucul_get_canvas_width(dp->cv) * 6; | |||||
} | } | ||||
static unsigned int slang_get_display_height(caca_display_t const *dp) | static unsigned int slang_get_display_height(caca_display_t const *dp) | ||||
{ | { | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->height * 10; | |||||
return cucul_get_canvas_height(dp->cv) * 10; | |||||
} | } | ||||
static void slang_display(caca_display_t *dp) | static void slang_display(caca_display_t *dp) | ||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int x, y; | int x, y; | ||||
uint32_t *attrs = dp->cv->attrs; | |||||
uint32_t *chars = dp->cv->chars; | |||||
for(y = 0; y < (int)dp->cv->height; y++) | |||||
for(y = 0; y < (int)height; y++) | |||||
{ | { | ||||
SLsmg_gotorc(y, 0); | SLsmg_gotorc(y, 0); | ||||
for(x = dp->cv->width; x--; ) | |||||
for(x = width; x--; ) | |||||
{ | { | ||||
uint32_t ch = *chars++; | |||||
uint32_t ch = *cvchars++; | |||||
#if defined(OPTIMISE_SLANG_PALETTE) | #if defined(OPTIMISE_SLANG_PALETTE) | ||||
/* If foreground == background, just don't use this colour | /* If foreground == background, just don't use this colour | ||||
@@ -226,8 +228,8 @@ static void slang_display(caca_display_t *dp) | |||||
* here for, and in cases where SLang does not render | * here for, and in cases where SLang does not render | ||||
* bright backgrounds, it's just fucked up. */ | * bright backgrounds, it's just fucked up. */ | ||||
#if 0 | #if 0 | ||||
uint8_t fgcolor = cucul_attr_to_ansi_fg(*attrs); | |||||
uint8_t bgcolor = cucul_attr_to_ansi_bg(*attrs); | |||||
uint8_t fgcolor = cucul_attr_to_ansi_fg(*cvattrs); | |||||
uint8_t bgcolor = cucul_attr_to_ansi_bg(*cvattrs); | |||||
if(fgcolor >= 0x10) | if(fgcolor >= 0x10) | ||||
fgcolor = CUCUL_LIGHTGRAY; | fgcolor = CUCUL_LIGHTGRAY; | ||||
@@ -246,16 +248,16 @@ static void slang_display(caca_display_t *dp) | |||||
fgcolor = CUCUL_WHITE; | fgcolor = CUCUL_WHITE; | ||||
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]); | SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]); | ||||
SLsmg_write_char(' '); | SLsmg_write_char(' '); | ||||
attrs++; | |||||
cvattrs++; | |||||
} | } | ||||
else | else | ||||
#endif | #endif | ||||
{ | { | ||||
SLsmg_set_color(slang_assoc[cucul_attr_to_ansi(*attrs++)]); | |||||
SLsmg_set_color(slang_assoc[cucul_attr_to_ansi(*cvattrs++)]); | |||||
slang_write_utf32(ch); | slang_write_utf32(ch); | ||||
} | } | ||||
#else | #else | ||||
SLsmg_set_color(cucul_attr_to_ansi(*attrs++)); | |||||
SLsmg_set_color(cucul_attr_to_ansi(*cvattrs++)); | |||||
slang_write_utf32(ch); | slang_write_utf32(ch); | ||||
#endif | #endif | ||||
} | } | ||||
@@ -270,7 +272,8 @@ static void slang_handle_resize(caca_display_t *dp) | |||||
dp->resize.w = SLtt_Screen_Cols; | dp->resize.w = SLtt_Screen_Cols; | ||||
dp->resize.h = SLtt_Screen_Rows; | dp->resize.h = SLtt_Screen_Rows; | ||||
if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height) | |||||
if(dp->resize.w != cucul_get_canvas_width(dp->cv) | |||||
|| dp->resize.h != cucul_get_canvas_height(dp->cv)) | |||||
SLsmg_reinit_smg(); | SLsmg_reinit_smg(); | ||||
} | } | ||||
@@ -21,10 +21,9 @@ | |||||
#if defined(USE_VGA) | #if defined(USE_VGA) | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
/* Address of the VGA screen */ | /* Address of the VGA screen */ | ||||
#define VGA_SCREEN ((char *)(intptr_t)0x000b8000) | #define VGA_SCREEN ((char *)(intptr_t)0x000b8000) | ||||
@@ -118,31 +117,33 @@ static unsigned int vga_get_display_height(caca_display_t const *dp) | |||||
static void vga_display(caca_display_t *dp) | static void vga_display(caca_display_t *dp) | ||||
{ | { | ||||
char *screen = (char *)(intptr_t)0x000b8000; | char *screen = (char *)(intptr_t)0x000b8000; | ||||
uint32_t *attrs = dp->cv->attrs; | |||||
uint32_t *chars = dp->cv->chars; | |||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int n; | int n; | ||||
for(n = dp->cv->height * dp->cv->width; n--; ) | |||||
for(n = height * width; n--; ) | |||||
{ | { | ||||
char ch = cucul_utf32_to_cp437(*chars++); | |||||
if(n && *chars == CUCUL_MAGIC_FULLWIDTH) | |||||
char ch = cucul_utf32_to_cp437(*cvchars++); | |||||
if(n && *cvchars == CUCUL_MAGIC_FULLWIDTH) | |||||
{ | { | ||||
*screen++ = '['; | *screen++ = '['; | ||||
*screen++ = cucul_attr_to_ansi(*attrs++); | |||||
*screen++ = cucul_attr_to_ansi(*cvattrs++); | |||||
ch = ']'; | ch = ']'; | ||||
chars++; | |||||
cvchars++; | |||||
n--; | n--; | ||||
} | } | ||||
*screen++ = ch; | *screen++ = ch; | ||||
*screen++ = cucul_attr_to_ansi(*attrs++); | |||||
*screen++ = cucul_attr_to_ansi(*cvattrs++); | |||||
} | } | ||||
} | } | ||||
static void vga_handle_resize(caca_display_t *dp) | static void vga_handle_resize(caca_display_t *dp) | ||||
{ | { | ||||
/* We know nothing about our window */ | /* We know nothing about our window */ | ||||
dp->resize.w = dp->cv->width; | |||||
dp->resize.h = dp->cv->height; | |||||
dp->resize.w = cucul_get_canvas_width(dp->cv); | |||||
dp->resize.h = cucul_get_canvas_height(dp->cv); | |||||
} | } | ||||
static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev) | static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
@@ -26,10 +26,9 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
/* | /* | ||||
* Global variables | * Global variables | ||||
@@ -84,6 +83,8 @@ struct driver_private | |||||
static int win32_init_graphics(caca_display_t *dp) | static int win32_init_graphics(caca_display_t *dp) | ||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
CONSOLE_SCREEN_BUFFER_INFO csbi; | CONSOLE_SCREEN_BUFFER_INFO csbi; | ||||
SMALL_RECT rect; | SMALL_RECT rect; | ||||
COORD size; | COORD size; | ||||
@@ -113,13 +114,13 @@ static int win32_init_graphics(caca_display_t *dp) | |||||
return -1; | return -1; | ||||
/* Set the new console size */ | /* Set the new console size */ | ||||
size.X = dp->cv->width ? dp->cv->width : 80; | |||||
size.Y = dp->cv->height ? dp->cv->height : 25; | |||||
size.X = width ? width : 80; | |||||
size.Y = height ? height : 25; | |||||
SetConsoleScreenBufferSize(dp->drv.p->screen, size); | SetConsoleScreenBufferSize(dp->drv.p->screen, size); | ||||
rect.Left = rect.Top = 0; | rect.Left = rect.Top = 0; | ||||
rect.Right = dp->cv->width - 1; | |||||
rect.Bottom = dp->cv->height - 1; | |||||
rect.Right = size.X - 1; | |||||
rect.Bottom = size.Y - 1; | |||||
SetConsoleWindowInfo(dp->drv.p->screen, TRUE, &rect); | SetConsoleWindowInfo(dp->drv.p->screen, TRUE, &rect); | ||||
/* Report our new size to libcucul */ | /* Report our new size to libcucul */ | ||||
@@ -130,6 +131,8 @@ static int win32_init_graphics(caca_display_t *dp) | |||||
cucul_set_canvas_size(dp->cv, | cucul_set_canvas_size(dp->cv, | ||||
csbi.srWindow.Right - csbi.srWindow.Left + 1, | csbi.srWindow.Right - csbi.srWindow.Left + 1, | ||||
csbi.srWindow.Bottom - csbi.srWindow.Top + 1); | csbi.srWindow.Bottom - csbi.srWindow.Top + 1); | ||||
width = cucul_get_canvas_width(dp->cv); | |||||
height = cucul_get_canvas_height(dp->cv); | |||||
dp->resize.allow = 0; | dp->resize.allow = 0; | ||||
SetConsoleMode(dp->drv.p->screen, 0); | SetConsoleMode(dp->drv.p->screen, 0); | ||||
@@ -141,7 +144,7 @@ static int win32_init_graphics(caca_display_t *dp) | |||||
SetConsoleActiveScreenBuffer(dp->drv.p->screen); | SetConsoleActiveScreenBuffer(dp->drv.p->screen); | ||||
dp->drv.p->buffer = malloc(dp->cv->width * dp->cv->height | |||||
dp->drv.p->buffer = malloc(width * height | |||||
* sizeof(CHAR_INFO)); | * sizeof(CHAR_INFO)); | ||||
if(dp->drv.p->buffer == NULL) | if(dp->drv.p->buffer == NULL) | ||||
return -1; | return -1; | ||||
@@ -178,7 +181,7 @@ static unsigned int win32_get_display_width(caca_display_t const *dp) | |||||
/* FIXME */ | /* FIXME */ | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->width * 6; | |||||
return cucul_get_canvas_width(dp->cv) * 6; | |||||
} | } | ||||
static unsigned int win32_get_display_height(caca_display_t const *dp) | static unsigned int win32_get_display_height(caca_display_t const *dp) | ||||
@@ -186,7 +189,7 @@ static unsigned int win32_get_display_height(caca_display_t const *dp) | |||||
/* FIXME */ | /* FIXME */ | ||||
/* Fallback to a 6x10 font */ | /* Fallback to a 6x10 font */ | ||||
return dp->cv->height * 10; | |||||
return cucul_get_canvas_height(dp->cv) * 10; | |||||
} | } | ||||
static void win32_display(caca_display_t *dp) | static void win32_display(caca_display_t *dp) | ||||
@@ -194,16 +197,18 @@ static void win32_display(caca_display_t *dp) | |||||
COORD size, pos; | COORD size, pos; | ||||
SMALL_RECT rect; | SMALL_RECT rect; | ||||
CHAR_INFO *buffer = dp->drv.p->buffer; | CHAR_INFO *buffer = dp->drv.p->buffer; | ||||
uint32_t *attrs = dp->cv->attrs; | |||||
uint32_t *chars = dp->cv->chars; | |||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
unsigned int n; | unsigned int n; | ||||
/* Render everything to our screen buffer */ | /* Render everything to our screen buffer */ | ||||
for(n = dp->cv->height * dp->cv->width; n--; ) | |||||
for(n = height * width; n--; ) | |||||
{ | { | ||||
uint32_t ch = *chars++; | |||||
uint8_t fg = cucul_attr_to_ansi_fg(*attrs); | |||||
uint8_t bg = cucul_attr_to_ansi_bg(*attrs); | |||||
uint32_t ch = *cvchars++; | |||||
uint8_t fg = cucul_attr_to_ansi_fg(*cvattrs); | |||||
uint8_t bg = cucul_attr_to_ansi_bg(*cvattrs); | |||||
#if 0 | #if 0 | ||||
if(ch > 0x00000020 && ch < 0x00000080) | if(ch > 0x00000020 && ch < 0x00000080) | ||||
@@ -211,7 +216,7 @@ static void win32_display(caca_display_t *dp) | |||||
else | else | ||||
dp->drv.p->buffer[i].Char.AsciiChar = ' '; | dp->drv.p->buffer[i].Char.AsciiChar = ' '; | ||||
#else | #else | ||||
if(n && *chars == CUCUL_MAGIC_FULLWIDTH) | |||||
if(n && *cvchars == CUCUL_MAGIC_FULLWIDTH) | |||||
; | ; | ||||
else if(ch > 0x00000020 && ch < 0x00010000) | else if(ch > 0x00000020 && ch < 0x00010000) | ||||
buffer->Char.UnicodeChar = (uint16_t)ch; | buffer->Char.UnicodeChar = (uint16_t)ch; | ||||
@@ -221,17 +226,17 @@ static void win32_display(caca_display_t *dp) | |||||
buffer->Attributes = win32_fg_palette[fg < 0x10 ? fg : CUCUL_LIGHTGRAY] | buffer->Attributes = win32_fg_palette[fg < 0x10 ? fg : CUCUL_LIGHTGRAY] | ||||
| win32_bg_palette[bg < 0x10 ? bg : CUCUL_BLACK]; | | win32_bg_palette[bg < 0x10 ? bg : CUCUL_BLACK]; | ||||
attrs++; | |||||
cvattrs++; | |||||
buffer++; | buffer++; | ||||
} | } | ||||
/* Blit the screen buffer */ | /* Blit the screen buffer */ | ||||
size.X = dp->cv->width; | |||||
size.Y = dp->cv->height; | |||||
size.X = width; | |||||
size.Y = height; | |||||
pos.X = pos.Y = 0; | pos.X = pos.Y = 0; | ||||
rect.Left = rect.Top = 0; | rect.Left = rect.Top = 0; | ||||
rect.Right = dp->cv->width - 1; | |||||
rect.Bottom = dp->cv->height - 1; | |||||
rect.Right = width - 1; | |||||
rect.Bottom = height - 1; | |||||
#if 0 | #if 0 | ||||
WriteConsoleOutput(dp->drv.p->screen, dp->drv.p->buffer, size, pos, &rect); | WriteConsoleOutput(dp->drv.p->screen, dp->drv.p->buffer, size, pos, &rect); | ||||
#else | #else | ||||
@@ -242,8 +247,8 @@ static void win32_display(caca_display_t *dp) | |||||
static void win32_handle_resize(caca_display_t *dp) | static void win32_handle_resize(caca_display_t *dp) | ||||
{ | { | ||||
/* FIXME: I don't know what to do here. */ | /* FIXME: I don't know what to do here. */ | ||||
dp->resize.w = dp->cv->width; | |||||
dp->resize.h = dp->cv->height; | |||||
dp->resize.w = cucul_get_canvas_width(dp->cv); | |||||
dp->resize.h = cucul_get_canvas_height(dp->cv); | |||||
} | } | ||||
static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev) | static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
@@ -33,10 +33,10 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "caca.h" | |||||
#include "caca_internals.h" | |||||
#include "cucul.h" | #include "cucul.h" | ||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
#include "caca.h" | |||||
#include "caca_internals.h" | |||||
/* | /* | ||||
* Local functions | * Local functions | ||||
@@ -77,7 +77,8 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
int (*old_error_handler)(Display *, XErrorEvent *); | int (*old_error_handler)(Display *, XErrorEvent *); | ||||
char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; | char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; | ||||
char const *geometry; | char const *geometry; | ||||
unsigned int width = dp->cv->width, height = dp->cv->height; | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
int i; | int i; | ||||
dp->drv.p = malloc(sizeof(struct driver_private)); | dp->drv.p = malloc(sizeof(struct driver_private)); | ||||
@@ -90,6 +91,8 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
dp->resize.allow = 1; | dp->resize.allow = 1; | ||||
cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); | cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); | ||||
width = cucul_get_canvas_width(dp->cv); | |||||
height = cucul_get_canvas_height(dp->cv); | |||||
dp->resize.allow = 0; | dp->resize.allow = 0; | ||||
dp->drv.p->dpy = XOpenDisplay(NULL); | dp->drv.p->dpy = XOpenDisplay(NULL); | ||||
@@ -192,8 +195,8 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
dp->drv.p->window = | dp->drv.p->window = | ||||
XCreateWindow(dp->drv.p->dpy, DefaultRootWindow(dp->drv.p->dpy), 0, 0, | XCreateWindow(dp->drv.p->dpy, DefaultRootWindow(dp->drv.p->dpy), 0, 0, | ||||
dp->cv->width * dp->drv.p->font_width, | |||||
dp->cv->height * dp->drv.p->font_height, | |||||
width * dp->drv.p->font_width, | |||||
height * dp->drv.p->font_height, | |||||
0, 0, InputOutput, 0, | 0, 0, InputOutput, 0, | ||||
CWBackingStore | CWBackPixel | CWEventMask, | CWBackingStore | CWBackPixel | CWEventMask, | ||||
&x11_winattr); | &x11_winattr); | ||||
@@ -240,10 +243,10 @@ static int x11_init_graphics(caca_display_t *dp) | |||||
XSync(dp->drv.p->dpy, False); | XSync(dp->drv.p->dpy, False); | ||||
dp->drv.p->pixmap = XCreatePixmap(dp->drv.p->dpy, dp->drv.p->window, | dp->drv.p->pixmap = XCreatePixmap(dp->drv.p->dpy, dp->drv.p->window, | ||||
dp->cv->width * dp->drv.p->font_width, | |||||
dp->cv->height * dp->drv.p->font_height, | |||||
DefaultDepth(dp->drv.p->dpy, | |||||
DefaultScreen(dp->drv.p->dpy))); | |||||
width * dp->drv.p->font_width, | |||||
height * dp->drv.p->font_height, | |||||
DefaultDepth(dp->drv.p->dpy, | |||||
DefaultScreen(dp->drv.p->dpy))); | |||||
dp->drv.p->pointer = None; | dp->drv.p->pointer = None; | ||||
dp->drv.p->cursor_flags = 0; | dp->drv.p->cursor_flags = 0; | ||||
@@ -278,29 +281,33 @@ static int x11_set_display_title(caca_display_t *dp, char const *title) | |||||
static unsigned int x11_get_display_width(caca_display_t const *dp) | static unsigned int x11_get_display_width(caca_display_t const *dp) | ||||
{ | { | ||||
return dp->cv->width * dp->drv.p->font_width; | |||||
return cucul_get_canvas_width(dp->cv) * dp->drv.p->font_width; | |||||
} | } | ||||
static unsigned int x11_get_display_height(caca_display_t const *dp) | static unsigned int x11_get_display_height(caca_display_t const *dp) | ||||
{ | { | ||||
return dp->cv->height * dp->drv.p->font_height; | |||||
return cucul_get_canvas_height(dp->cv) * dp->drv.p->font_height; | |||||
} | } | ||||
static void x11_display(caca_display_t *dp) | static void x11_display(caca_display_t *dp) | ||||
{ | { | ||||
uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv); | |||||
uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv); | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
unsigned int x, y, len; | unsigned int x, y, len; | ||||
/* First draw the background colours. Splitting the process in two | /* First draw the background colours. Splitting the process in two | ||||
* loops like this is actually slightly faster. */ | * loops like this is actually slightly faster. */ | ||||
for(y = 0; y < dp->cv->height; y++) | |||||
for(y = 0; y < height; y++) | |||||
{ | { | ||||
for(x = 0; x < dp->cv->width; x += len) | |||||
for(x = 0; x < width; x += len) | |||||
{ | { | ||||
uint32_t *attrs = dp->cv->attrs + x + y * dp->cv->width; | |||||
uint32_t const *attrs = cvattrs + x + y * width; | |||||
uint16_t bg = _cucul_attr_to_rgb12bg(*attrs); | uint16_t bg = _cucul_attr_to_rgb12bg(*attrs); | ||||
len = 1; | len = 1; | ||||
while(x + len < dp->cv->width | |||||
while(x + len < width | |||||
&& _cucul_attr_to_rgb12bg(attrs[len]) == bg) | && _cucul_attr_to_rgb12bg(attrs[len]) == bg) | ||||
len++; | len++; | ||||
@@ -315,14 +322,14 @@ static void x11_display(caca_display_t *dp) | |||||
} | } | ||||
/* Then print the foreground characters */ | /* Then print the foreground characters */ | ||||
for(y = 0; y < dp->cv->height; y++) | |||||
for(y = 0; y < height; y++) | |||||
{ | { | ||||
unsigned int yoff = (y + 1) * dp->drv.p->font_height | unsigned int yoff = (y + 1) * dp->drv.p->font_height | ||||
- dp->drv.p->font_offset; | - dp->drv.p->font_offset; | ||||
uint32_t *chars = dp->cv->chars + y * dp->cv->width; | |||||
uint32_t *attrs = dp->cv->attrs + y * dp->cv->width; | |||||
uint32_t const *chars = cvchars + y * width; | |||||
uint32_t const *attrs = cvattrs + y * width; | |||||
for(x = 0; x < dp->cv->width; x++, chars++, attrs++) | |||||
for(x = 0; x < width; x++, chars++, attrs++) | |||||
{ | { | ||||
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, | XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, | ||||
dp->drv.p->colors[_cucul_attr_to_rgb12fg(*attrs)]); | dp->drv.p->colors[_cucul_attr_to_rgb12fg(*attrs)]); | ||||
@@ -348,8 +355,8 @@ static void x11_display(caca_display_t *dp) | |||||
XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->window, | XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->window, | ||||
dp->drv.p->gc, 0, 0, | dp->drv.p->gc, 0, 0, | ||||
dp->cv->width * dp->drv.p->font_width, | |||||
dp->cv->height * dp->drv.p->font_height, | |||||
width * dp->drv.p->font_width, | |||||
height * dp->drv.p->font_height, | |||||
0, 0); | 0, 0); | ||||
XFlush(dp->drv.p->dpy); | XFlush(dp->drv.p->dpy); | ||||
} | } | ||||
@@ -373,6 +380,8 @@ static void x11_handle_resize(caca_display_t *dp) | |||||
static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | ||||
{ | { | ||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
XEvent xevent; | XEvent xevent; | ||||
char key; | char key; | ||||
@@ -386,8 +395,8 @@ static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
{ | { | ||||
XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap, | XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap, | ||||
dp->drv.p->window, dp->drv.p->gc, 0, 0, | dp->drv.p->window, dp->drv.p->gc, 0, 0, | ||||
dp->cv->width * dp->drv.p->font_width, | |||||
dp->cv->height * dp->drv.p->font_height, 0, 0); | |||||
width * dp->drv.p->font_width, | |||||
height * dp->drv.p->font_height, 0, 0); | |||||
continue; | continue; | ||||
} | } | ||||
@@ -401,7 +410,7 @@ static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
h = (xevent.xconfigure.height + dp->drv.p->font_height / 3) | h = (xevent.xconfigure.height + dp->drv.p->font_height / 3) | ||||
/ dp->drv.p->font_height; | / dp->drv.p->font_height; | ||||
if(!w || !h || (w == dp->cv->width && h == dp->cv->height)) | |||||
if(!w || !h || (w == width && h == height)) | |||||
continue; | continue; | ||||
dp->resize.w = w; | dp->resize.w = w; | ||||
@@ -417,10 +426,10 @@ static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
unsigned int newx = xevent.xmotion.x / dp->drv.p->font_width; | unsigned int newx = xevent.xmotion.x / dp->drv.p->font_width; | ||||
unsigned int newy = xevent.xmotion.y / dp->drv.p->font_height; | unsigned int newy = xevent.xmotion.y / dp->drv.p->font_height; | ||||
if(newx >= dp->cv->width) | |||||
newx = dp->cv->width - 1; | |||||
if(newy >= dp->cv->height) | |||||
newy = dp->cv->height - 1; | |||||
if(newx >= width) | |||||
newx = width - 1; | |||||
if(newy >= height) | |||||
newy = height - 1; | |||||
if(dp->mouse.x == newx && dp->mouse.y == newy) | if(dp->mouse.x == newx && dp->mouse.y == newy) | ||||
continue; | continue; | ||||
@@ -25,7 +25,6 @@ | |||||
#endif | #endif | ||||
#include "cucul.h" | #include "cucul.h" | ||||
#include "cucul_internals.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
@@ -131,8 +130,10 @@ int caca_get_event(caca_display_t *dp, unsigned int event_mask, | |||||
*/ | */ | ||||
unsigned int caca_get_mouse_x(caca_display_t const *dp) | unsigned int caca_get_mouse_x(caca_display_t const *dp) | ||||
{ | { | ||||
if(dp->mouse.x >= dp->cv->width) | |||||
return dp->cv->width - 1; | |||||
unsigned int width = cucul_get_canvas_width(dp->cv); | |||||
if(dp->mouse.x >= width) | |||||
return width - 1; | |||||
return dp->mouse.x; | return dp->mouse.x; | ||||
} | } | ||||
@@ -151,8 +152,10 @@ unsigned int caca_get_mouse_x(caca_display_t const *dp) | |||||
*/ | */ | ||||
unsigned int caca_get_mouse_y(caca_display_t const *dp) | unsigned int caca_get_mouse_y(caca_display_t const *dp) | ||||
{ | { | ||||
if(dp->mouse.y >= dp->cv->height) | |||||
return dp->cv->height - 1; | |||||
unsigned int height = cucul_get_canvas_height(dp->cv); | |||||
if(dp->mouse.y >= height) | |||||
return height - 1; | |||||
return dp->mouse.y; | return dp->mouse.y; | ||||
} | } | ||||
@@ -333,8 +336,8 @@ static int _get_next_event(caca_display_t *dp, caca_privevent_t *ev) | |||||
dp->resize.resized = 0; | dp->resize.resized = 0; | ||||
_caca_handle_resize(dp); | _caca_handle_resize(dp); | ||||
ev->type = CACA_EVENT_RESIZE; | ev->type = CACA_EVENT_RESIZE; | ||||
ev->data.resize.w = dp->cv->width; | |||||
ev->data.resize.h = dp->cv->height; | |||||
ev->data.resize.w = cucul_get_canvas_width(dp->cv); | |||||
ev->data.resize.h = cucul_get_canvas_height(dp->cv); | |||||
return 1; | return 1; | ||||
} | } | ||||
@@ -25,10 +25,9 @@ | |||||
# include <string.h> | # include <string.h> | ||||
#endif | #endif | ||||
#include "cucul.h" | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
#include "cucul.h" | |||||
#include "cucul_internals.h" | |||||
/** \brief Set the display title. | /** \brief Set the display title. | ||||
* | * | ||||
@@ -237,7 +236,8 @@ void _caca_handle_resize(caca_display_t *dp) | |||||
dp->drv.handle_resize(dp); | dp->drv.handle_resize(dp); | ||||
/* Tell libcucul we changed size */ | /* Tell libcucul we changed size */ | ||||
if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height) | |||||
if(dp->resize.w != cucul_get_canvas_width(dp->cv) | |||||
|| dp->resize.h != cucul_get_canvas_height(dp->cv)) | |||||
{ | { | ||||
dp->resize.allow = 1; | dp->resize.allow = 1; | ||||
cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h); | cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h); | ||||
@@ -237,6 +237,44 @@ unsigned int cucul_get_canvas_height(cucul_canvas_t const *cv) | |||||
return cv->height; | return cv->height; | ||||
} | } | ||||
/** \brief Get the canvas character array. | |||||
* | |||||
* Return the current canvas' internal character array. The array elements | |||||
* consist in native endian 32-bit Unicode values as returned by | |||||
* cucul_get_char(). | |||||
* | |||||
* This function is only useful for display drivers such as the \e libcaca | |||||
* library. | |||||
* | |||||
* This function never fails. | |||||
* | |||||
* \param cv A libcucul canvas. | |||||
* \return The canvas character array. | |||||
*/ | |||||
unsigned char const * cucul_get_canvas_chars(cucul_canvas_t const *cv) | |||||
{ | |||||
return (unsigned char const *)cv->chars; | |||||
} | |||||
/** \brief Get the canvas attribute array. | |||||
* | |||||
* Returns the current canvas' internal attribute array. The array elements | |||||
* consist in native endian 32-bit attribute values as returned by | |||||
* cucul_get_attr(). | |||||
* | |||||
* This function is only useful for display drivers such as the \e libcaca | |||||
* library. | |||||
* | |||||
* This function never fails. | |||||
* | |||||
* \param cv A libcucul canvas. | |||||
* \return The canvas attribute array. | |||||
*/ | |||||
unsigned char const * cucul_get_canvas_attrs(cucul_canvas_t const *cv) | |||||
{ | |||||
return (unsigned char const *)cv->attrs; | |||||
} | |||||
/** \brief Uninitialise \e libcucul. | /** \brief Uninitialise \e libcucul. | ||||
* | * | ||||
* Free all resources allocated by cucul_create_canvas(). After | * Free all resources allocated by cucul_create_canvas(). After | ||||
@@ -90,6 +90,8 @@ __extern int cucul_set_canvas_size(cucul_canvas_t *, unsigned int, | |||||
unsigned int); | unsigned int); | ||||
__extern unsigned int cucul_get_canvas_width(cucul_canvas_t const *); | __extern unsigned int cucul_get_canvas_width(cucul_canvas_t const *); | ||||
__extern unsigned int cucul_get_canvas_height(cucul_canvas_t const *); | __extern unsigned int cucul_get_canvas_height(cucul_canvas_t const *); | ||||
__extern unsigned char const * cucul_get_canvas_chars(cucul_canvas_t const *); | |||||
__extern unsigned char const * cucul_get_canvas_attrs(cucul_canvas_t const *); | |||||
__extern int cucul_free_canvas(cucul_canvas_t *); | __extern int cucul_free_canvas(cucul_canvas_t *); | ||||
__extern int cucul_rand(int, int); | __extern int cucul_rand(int, int); | ||||
/* @} */ | /* @} */ | ||||