1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-27 19:13:25 +01:00

more fixes

This commit is contained in:
Jfreegman 2014-06-14 02:54:58 -04:00
parent c76b541cb8
commit 1b5da956e5
2 changed files with 15 additions and 12 deletions

View File

@ -156,6 +156,13 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
if (msg) {
snprintf(new_line->msg, sizeof(new_line->msg), "%s", msg);
len += strlen(new_line->msg);
int i;
for (i = 0; msg[i]; ++i) {
if (msg[i] == '\n')
++new_line->newlines;
}
}
if (tmstmp) {
@ -190,10 +197,8 @@ static void line_info_check_queue(ToxWindow *self)
if (line == NULL)
return;
if (++hst->line_items > user_settings->history_size) {
--hst->line_items;
if (hst->start_id > user_settings->history_size)
line_info_root_fwd(hst);
}
line->id = hst->line_end->id + 1;
line->prev = hst->line_end;
@ -208,17 +213,15 @@ static void line_info_check_queue(ToxWindow *self)
return;
int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; /* offset width of groupchat sidebar */
int lines = 1 + (line->len / (x2 - offst));
int lines = 1 + line->newlines + (line->len / (x2 - offst));
int max_y = self->is_prompt ? y2 : y2 - CHATBOX_HEIGHT;
/* move line_start forward proportionate to the number of new lines */
if (y >= max_y) {
while (lines > 0) {
if (y + lines - 1 >= max_y) {
while (lines > 0 && hst->line_start->next) {
lines -= 1 + hst->line_start->newlines + (hst->line_start->len / (x2 - offst));
hst->line_start = hst->line_start->next;
++hst->start_id;
lines -= 1 + (hst->line_start->len / (x2 - offst));
if (hst->line_start->next)
hst->line_start = hst->line_start->next;
}
}
}

View File

@ -50,6 +50,7 @@ struct line_info {
uint8_t colour;
uint32_t id;
uint16_t len; /* combined len of all strings */
uint8_t newlines;
struct line_info *prev;
struct line_info *next;
@ -61,10 +62,9 @@ struct history {
struct line_info *line_start; /* the first line we want to start printing at */
struct line_info *line_end;
uint32_t start_id; /* keeps track of where line_start should be when at bottom of history */
uint32_t line_items;
struct line_info *queue[MAX_QUEUE];
int queue_sz; /* -1 if no queue items */
int queue_sz;
};
/* adds a line to history (also moves line_start and/or line_root forward if necessary) */