Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Encrypt/uTox
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Privé committed Jan 20, 2015
2 parents 4870d0e + 78f7140 commit 285d7b7
Show file tree
Hide file tree
Showing 16 changed files with 321 additions and 34 deletions.
10 changes: 10 additions & 0 deletions android/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ void flush_file(FILE *file)
fsync(fd);
}



int ch_mod(uint8_t *file){
/* You're probably looking for ./xlib as android isn't working when this was written. */
}

void setscale(void)
{
if(window) {
Expand Down Expand Up @@ -456,6 +462,10 @@ void redraw(void)
{
_redraw = 1;
}
void force_redraw(void)
{
redraw();
}

void update_tray(void)
{
Expand Down
4 changes: 4 additions & 0 deletions button.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ _Bool button_mmove(BUTTON *b, int UNUSED(x), int UNUSED(y), int width, int heigh
_Bool mouseover = inrect(mx, my, real_x, 0, real_w, height);
if(mouseover) {
cursor = CURSOR_HAND;
if(maybe_i18nal_string_is_valid(&b->tooltip_text)) {
tooltip_new(&b->tooltip_text);
}

}
if(mouseover != b->mouseover) {
b->mouseover = mouseover;
Expand Down
1 change: 1 addition & 0 deletions button.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct button {
uint32_t c1, c2, c3;

MAYBE_I18NAL_STRING button_text;
MAYBE_I18NAL_STRING tooltip_text;

_Bool mouseover, mousedown, disabled, nodraw;

Expand Down
2 changes: 1 addition & 1 deletion friend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef struct friend {
int32_t callid;
uint16_t call_width, call_height;

uint8_t cid[TOX_CLIENT_ID_SIZE];
uint8_t cid[TOX_CLIENT_ID_SIZE], tooltip[8];
STRING_IDX name_length, status_length, typed_length;
char_t *name, *status_message, *typed;

Expand Down
9 changes: 7 additions & 2 deletions list.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static void drawname(ITEM *i, int y, char_t *name, char_t *msg, STRING_IDX name_
static void drawitem(ITEM *i, int UNUSED(x), int y)
{
drawitembox(i, y);

switch(i->item) {
case ITEM_FRIEND: {
FRIEND *f = i->data;
Expand All @@ -63,6 +62,7 @@ static void drawitem(ITEM *i, int UNUSED(x), int y)
if(f->notify) {
drawalpha(BM_STATUS_NOTIFY, LIST_RIGHT - SCALE * 13, y + ITEM_HEIGHT / 2 - BM_STATUS_NOTIFY_WIDTH / 2, BM_STATUS_NOTIFY_WIDTH, BM_STATUS_NOTIFY_WIDTH, status_color[status]);
}
// tooltip_new(utf8tonative(snprint_t(f->name, sizeof(char_t)*8));
break;
}

Expand Down Expand Up @@ -119,10 +119,12 @@ void list_scale(void)

static ITEM* item_hit(int mx, int my, int UNUSED(height))
{
/* Mouse is outsite the list */
if(mx < LIST_X || mx >= LIST_RIGHT) {
return NULL;
}

/* Mouse is above the list */
if(my < 0) {
return NULL;
}
Expand Down Expand Up @@ -514,6 +516,8 @@ _Bool list_mmove(void *UNUSED(n), int UNUSED(x), int UNUSED(y), int UNUSED(width
}

draw = 1;
} else {
tooltip_draw();
}

return draw;
Expand All @@ -522,7 +526,7 @@ _Bool list_mmove(void *UNUSED(n), int UNUSED(x), int UNUSED(y), int UNUSED(width
_Bool list_mdown(void *UNUSED(n))
{
_Bool draw = 0;

tooltip_mdown(); /* may need to return on true */
if(mitem) {
if(mitem != sitem) {
selectitem(mitem);
Expand Down Expand Up @@ -601,6 +605,7 @@ _Bool list_mwheel(void *UNUSED(n), int UNUSED(height), double UNUSED(d))
_Bool list_mup(void *UNUSED(n))
{
_Bool draw = 0;
tooltip_mup(); /* may need to return one true */
if(sitem_mousedown && abs(sitem_dy) >= 5) {
if(nitem) {
if(sitem->item == ITEM_FRIEND) {
Expand Down
5 changes: 5 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <limits.h>
#include <ctype.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <tox/tox.h>
#include <tox/toxav.h>
#include <vpx/vpx_codec.h>
Expand Down Expand Up @@ -96,6 +98,7 @@ typedef struct edit_change EDIT_CHANGE;
#include "button.h"
#include "dropdown.h"
#include "contextmenu.h"
#include "tooltip.h"

#include "text.h"
#include "util.h"
Expand Down Expand Up @@ -233,6 +236,7 @@ UTOX_NATIVE_IMAGE png_to_image(const UTOX_PNG_IMAGE, size_t png_size, uint16_t *
void showkeyboard(_Bool show);
void redraw(void);
void update_tray(void);
void force_redraw(void); // TODO: as parameter for redraw()?

int datapath_old(uint8_t *dest);
int datapath(uint8_t *dest);
Expand All @@ -241,6 +245,7 @@ int datapath(uint8_t *dest);
* returns number of characters written */
int datapath_subdir(uint8_t *dest, const char *subdir);
void flush_file(FILE *file);
int ch_mod(uint8_t *file);
void config_osdefaults(UTOX_SAVE *r);

//me
Expand Down
4 changes: 3 additions & 1 deletion messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ void messages_draw(MESSAGES *m, int x, int y, int width, int height)
drawtext(x + width - TIME_WIDTH, y, (char_t*)timestr, len);
}

// Draw the names for groups or friends
if(m->type) {
/* group */
setcolor(0);
setcolor(C_BLUE);
setfont(FONT_TEXT);
drawtextwidth_right(x, MESSAGES_X - NAME_OFFSET, y, &msg->msg[msg->length] + 1, msg->msg[msg->length]);
} else {
Expand Down Expand Up @@ -863,6 +864,7 @@ void message_add(MESSAGES *m, MESSAGE *msg, MSG_DATA *p)
time(&rawtime);
ti = localtime(&rawtime);

// Set the time this message was recived by utox
msg->time = ti->tm_hour * 60 + ti->tm_min;

if(p->n < MAX_BACKLOG_MESSAGES) {
Expand Down
146 changes: 146 additions & 0 deletions tooltip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#include "main.h"

static TOOLTIP tooltip;

#define TOOLTIP_WIDTH (SCALE * 12)
#define TOOLTIP_HEIGHT (SCALE * 12)
#define TOOLTIP_YOFFSET 12

static void calculate_pos_and_width(TOOLTIP *b, int *x, int *w) {
*x = b->x;
*w = b->width;

// Increase width if needed, so that tooltip text fits.
if(maybe_i18nal_string_is_valid(b->tt_text)) {
STRING* s = maybe_i18nal_string_get(b->tt_text);
int needed_w = textwidth(s->str, s->length) + 4 * SCALE;
if(*w < needed_w) {
*w = needed_w;
}
}

// Push away from the right border to fit.
if(*x + *w >= utox_window_width) {
*x -= *w;
}
}

void tooltip_draw(void)
{
TOOLTIP *b = &tooltip;
if(!b->visible) {
return;
}

// Ensure that font is set before calculating position and width.
setfont(FONT_TEXT);
setcolor(COLOR_TEXT);

int x, w;
calculate_pos_and_width(b, &x, &w);

drawrectw(x, b->y, w, b->height, C_YELLOW_LIGHT);

STRING* s = maybe_i18nal_string_get(b->tt_text);
drawtext(x + SCALE * 2, b->y + SCALE * 2, s->str, s->length);

framerect(x, b->y, x + w, b->y + b->height, C_YELLOW);
}

_Bool tooltip_mmove(void)
{
TOOLTIP *b = &tooltip;

b->can_show = 0;

if(!b->visible) {
return 0;
}

b->visible = 0;
return 1;
}

_Bool tooltip_mdown(void)
{
TOOLTIP *b = &tooltip;

b->can_show = 0;
b->mouse_down = 1;

if(!b->visible) {
return 0;
}

b->visible = 0;
return 1;
}
_Bool tooltip_mup(void)
{
TOOLTIP *b = &tooltip;

b->can_show = 0;
b->mouse_down = 0;
return 0;
}

void tooltip_show(void)
{
TOOLTIP *b = &tooltip;

b->y = mouse.y + TOOLTIP_YOFFSET;
b->height = TOOLTIP_HEIGHT;
if(b->y + b->height >= utox_window_height) {
b->y -= (b->height + TOOLTIP_YOFFSET);
}
b->x = mouse.x;
b->width = TOOLTIP_WIDTH;

b->visible = 1;

// Only needed for Xlib to unblock XNextEvent
force_redraw();
}

// This is being called everytime the mouse is moving above a button
void tooltip_new(MAYBE_I18NAL_STRING* text)
{
TOOLTIP *b = &tooltip;

b->can_show = 1;
b->tt_text = text;

if(b->timer_running || b->visible || b->mouse_down) {
return;
}
thread(mouse_pos_check,NULL);
}

void mouse_pos_check(void *UNUSED(args))
{
TOOLTIP *b = &tooltip;
int old_x = 0, old_y = 0, tick = 0;
b->timer_running = 1;
while(1) {
if(mouse.x - old_x == 0 && mouse.y - old_y == 0) {
if(tick >= 5) {
// ~500ms of not moving, show tooltip
if(b->can_show && !b->mouse_down) {
tooltip_show();
}
break;
} else {
tick++;
}
//debug("Mouse stopped. X: %d, Y: %d, OX: %d, OY: %d\n",mouse.x,mouse.y,old_x,old_y);
} else {
old_x = mouse.x;
old_y = mouse.y;
tick = 0;
}
yieldcpu(100);
}
tick = 0;
b->visible = 1;
b->timer_running = 0;
}
20 changes: 20 additions & 0 deletions tooltip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
typedef struct tooltip {
int x, y, width, height;
_Bool visible;

_Bool timer_running;
_Bool can_show;
_Bool mouse_down;

MAYBE_I18NAL_STRING* tt_text;
} TOOLTIP;

void tooltip_draw(void);
_Bool tooltip_mmove(void);
_Bool tooltip_mdown(void);
_Bool tooltip_mup(void);

void tooltip_show(void);
void tooltip_new(MAYBE_I18NAL_STRING* text);

void mouse_pos_check(void *UNUSED(args));
6 changes: 6 additions & 0 deletions tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ static void write_save(Tox *tox)
debug("Saved data\n");
}
}
int ch = ch_mod(path_real);
if(!ch){
debug("CHMOD: success\n");
} else {
debug("CHMOD: failure\n");
}

free(data);
}
Expand Down
10 changes: 9 additions & 1 deletion ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ void ui_scale(uint8_t scale)
.height = BM_LBUTTON_HEIGHT,
},

/* top right chat message window button */
b_chat1 = {
.type = PANEL_BUTTON,
.x = -5 * SCALE - BM_CB_WIDTH,
Expand All @@ -634,6 +635,7 @@ void ui_scale(uint8_t scale)
.width = BM_CB_WIDTH,
},

/* bottom right chat message window button */
b_chat2 = {
.type = PANEL_BUTTON,
.x = -5 * SCALE - BM_CB_WIDTH,
Expand Down Expand Up @@ -1003,6 +1005,7 @@ void panel_draw(PANEL *p, int x, int y, int width, int height)

dropdown_drawactive();
contextmenu_draw();
tooltip_draw();

enddraw(x, y, width, height);
}
Expand Down Expand Up @@ -1034,6 +1037,10 @@ _Bool panel_mmove(PANEL *p, int x, int y, int width, int height, int mx, int my,
}

_Bool draw = p->type ? mmovefunc[p->type - 1](p, x, y, width, height, mx, mmy, dx, dy) : 0;
// Has to be called before children mmove
if(p == &panel_main) {
draw |= tooltip_mmove();
}
PANEL **pp = p->child, *subp;
if(pp) {
while((subp = *pp++)) {
Expand Down Expand Up @@ -1075,7 +1082,7 @@ static _Bool panel_mdown_sub(PANEL *p)

void panel_mdown(PANEL *p)
{
if(contextmenu_mdown()) {
if(contextmenu_mdown() || tooltip_mdown()) {
redraw();
return;
}
Expand Down Expand Up @@ -1180,6 +1187,7 @@ _Bool panel_mup(PANEL *p)

if(p == &panel_main) {
draw |= contextmenu_mup();
tooltip_mup();
if(draw) {
redraw();
}
Expand Down
Loading

0 comments on commit 285d7b7

Please sign in to comment.