Remove old functions, implement display copies.

This commit is contained in:
Michael Jumper 2013-04-26 10:36:02 -07:00
parent b64aaa72ee
commit e1b45733a3
3 changed files with 63 additions and 115 deletions

View File

@ -117,12 +117,6 @@ typedef struct guac_terminal_display {
*/
guac_terminal_operation* operations;
/**
* Scratch area of same size as the operations buffer, facilitating copies
* of overlapping regions.
*/
guac_terminal_operation* scratch;
/**
* The width of the screen, in characters.
*/

View File

@ -317,9 +317,6 @@ guac_terminal_display* guac_terminal_display_alloc(guac_client* client, int widt
}
/* Alloc scratch area */
display->scratch = malloc(width * height * sizeof(guac_terminal_operation));
/* Send initial display size */
guac_protocol_send_size(client->socket,
GUAC_DEFAULT_LAYER,
@ -334,7 +331,6 @@ void guac_terminal_display_free(guac_terminal_display* display) {
/* Free operations buffers */
free(display->operations);
free(display->scratch);
/* Free display */
free(display);
@ -343,18 +339,73 @@ void guac_terminal_display_free(guac_terminal_display* display) {
void guac_terminal_display_copy_columns(guac_terminal_display* display, int row,
int start_column, int end_column, int offset) {
/* STUB */
guac_client_log_info(display->client,
"display_copy_columns: row=%i, start=%i, end=%i, offset=%i",
row, start_column, end_column, offset);
int i;
guac_terminal_operation* src_current =
&(display->operations[row * display->width + start_column]);
guac_terminal_operation* current =
&(display->operations[row * display->width + start_column + offset]);
/* Move data */
memmove(current, src_current,
(end_column - start_column + 1) * sizeof(guac_terminal_operation));
/* Update operations */
for (i=start_column; i<=end_column; i++) {
/* If no operation here, set as copy */
if (current->type == GUAC_CHAR_NOP) {
current->type = GUAC_CHAR_COPY;
current->row = row;
current->column = i;
}
/* Next column */
current++;
}
}
void guac_terminal_display_copy_rows(guac_terminal_display* display,
int start_row, int end_row, int offset) {
/* STUB */
guac_client_log_info(display->client,
"display_copy_rows: start=%i, end=%i, offset=%i",
start_row, end_row, offset);
int row, col;
guac_terminal_operation* src_current_row =
&(display->operations[start_row * display->width]);
guac_terminal_operation* current_row =
&(display->operations[(start_row + offset) * display->width]);
/* Move data */
memmove(current_row, src_current_row,
(end_row - start_row + 1) * sizeof(guac_terminal_operation) * display->width);
/* Update operations */
for (row=start_row; row<=end_row; row++) {
guac_terminal_operation* current = current_row;
for (col=0; col<display->width; col++) {
/* If no operation here, set as copy */
if (current->type == GUAC_CHAR_NOP) {
current->type = GUAC_CHAR_COPY;
current->row = row;
current->column = col;
}
/* Next column */
current++;
}
/* Next row */
current_row += display->width;
}
}
void guac_terminal_display_set_columns(guac_terminal_display* display, int row,

View File

@ -227,103 +227,6 @@ int guac_terminal_clear_range(guac_terminal* term,
}
void guac_terminal_display_set(guac_terminal_display* display, int r, int c,
guac_terminal_char* character) {
/* Get operation at coordinate */
guac_terminal_operation* op = &(display->operations[r*display->width + c]);
/* Store operation */
op->type = GUAC_CHAR_SET;
op->character = *character;
}
void guac_terminal_display_copy(guac_terminal_display* display,
int dst_row, int dst_column,
int src_row, int src_column,
int w, int h) {
int row, column;
/* FIXME: Handle intersections between src and dst rects */
memcpy(display->scratch, display->operations,
sizeof(guac_terminal_operation) * display->width * display->height);
guac_terminal_operation* current_row =
&(display->operations[dst_row*display->width + dst_column]);
guac_terminal_operation* src_current_row =
&(display->scratch[src_row*display->width + src_column]);
/* Set rectangle to copy operations */
for (row=0; row<h; row++) {
guac_terminal_operation* current = current_row;
guac_terminal_operation* src_current = src_current_row;
for (column=0; column<w; column++) {
/* If copying existing display operation, just copy that rather
* than create a new copy op */
if (src_current->type != GUAC_CHAR_NOP)
*current = *src_current;
/* Store operation */
else {
current->type = GUAC_CHAR_COPY;
current->row = src_row + row;
current->column = src_column + column;
}
/* Next column */
current++;
src_current++;
}
/* Next row */
current_row += display->width;
src_current_row += display->width;
}
}
void guac_terminal_display_set_rect(guac_terminal_display* display,
int row, int column, int w, int h,
guac_terminal_char* character) {
guac_terminal_operation* current_row =
&(display->operations[row*display->width + column]);
/* Set rectangle contents to given character */
for (row=0; row<h; row++) {
guac_terminal_operation* current = current_row;
for (column=0; column<w; column++) {
/* Store operation */
current->type = GUAC_CHAR_SET;
current->character = *character;
/* Next column */
current++;
}
/* Next row */
current_row += display->width;
}
}
void guac_terminal_scroll_display_down(guac_terminal* terminal,
int scroll_amount) {