Skip to content

Commit

Permalink
inline images
Browse files Browse the repository at this point in the history
  • Loading branch information
notsecure committed Jul 17, 2014
1 parent 77a62e3 commit 0ae8b94
Show file tree
Hide file tree
Showing 22 changed files with 7,377 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LDFLAGS += -lX11 -lXft -lXrender -ltoxcore -ltoxav -ltoxdns -lopenal -pthread -l

DESTDIR=/usr/local

SRC = $(wildcard *.c)
SRC = $(wildcard *.c) png/png.c
OBJ = $(SRC:.c=.o)

all: uTox
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,48 @@

Lightweight [Tox](https://github.com/irungentoo/ProjectTox-Core) client.

* Some things are incomplete, but feel free to make any design suggestions (colors, fonts, whatever)
* Some things are incomplete and there may be some bugs: feel free to make issues/suggestions

* Xlib support is experimental, many features may be missing
* Xlib support is mostly complete, but may have some small bugs (no right click menus, lags)

## Screenshots

uTox running on Windows 8

![test](https://raw.github.com/notsecure/uTox/master/images/uTox-win32.png "uTox running on Windows 8")

uTox running on lubuntu:

![test](https://raw.github.com/notsecure/uTox/master/images/uTox.png "uTox running on lubuntu")
![test](https://raw.github.com/notsecure/uTox/master/images/uTox-xlib.png "uTox running on lubuntu")


## Building

Something like this:
Something like this (these commands may sometimes be outdated, try the makefile or make an issue if they do not work):

Windows, using prebuilt toxav dll from Jenkins [32-bit](https://jenkins.libtoxcore.so/job/toxcore_win32_dll/) | [64-bit](https://jenkins.libtoxcore.so/job/toxcore_win64_dll/):

Windows:
Note: building for Windows requires mingw-w64 (mingw lacks some header files), other compilers (not tested) may work with some tweaks

> windres icons/icon.rc -O coff -o icon.res
> cc -o uTox.exe *.c icon.res -lgdi32 -lmsimg32 -ldnsapi -lcomdlg32 -lopenal32 -ltoxav
> gcc -o uTox.exe *.c ./png/png.c icon.res -lgdi32 -lmsimg32 -ldnsapi -lcomdlg32 -lopenal32 -lole32 -lstrmiids -loleaut32 -lvpx -ltoxav
Xlib:

> cc -o uTox.o *.c -lX11 -lXft -lXrender -ltoxcore -ltoxav -ltoxdns -lopenal -pthread -lresolv -ldl -lm -lfontconfig -lv4lconvert -lvpx -I/usr/include/freetype2 -DV4L
> cc -o uTox.o *.c ./png/png.c -lX11 -lXft -lXrender -ltoxcore -ltoxav -ltoxdns -lopenal -pthread -lresolv -ldl -lm -lfontconfig -lv4lconvert -lvpx -I/usr/include/freetype2 -ldbus-1
or if you built toxcore statically:

> cc -o uTox.o *.c -lX11 -lXft -lXrender -ltoxcore -ltoxav -ltoxdns -lopenal -lsodium -lopus -lvpx -lm -pthread -lresolv -ldl -lfontconfig -lv4lconvert -DV4L -I/usr/include/freetype2
> cc -o uTox.o *.c ./png/png.c -lX11 -lXft -lXrender -ltoxcore -ltoxav -ltoxdns -lopenal -lsodium -lopus -lvpx -lm -pthread -lresolv -ldl -lfontconfig -lv4lconvert -I/usr/include/freetype2 -ldbus-1
OS X (you need XQuartz on 10.8+, no video yet):

> cc -o uTox.o *.c -I/opt/X11/include -L/opt/X11/lib -lX11 -lXft -lXrender -lXext -ltoxcore -ltoxav -ltoxdns -framework OpenAL -pthread -lresolv -ldl -lm -lfontconfig -lvpx -I/opt/X11/include/freetype2



## Downloads

[https://wiki.tox.im/Binaries](https://wiki.tox.im/Binaries)
[Up to date download links on utox.org](http://utox.org)

## Info

Expand Down
32 changes: 32 additions & 0 deletions friend.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ void friend_setname(FRIEND *f, char_t *name, uint16_t length)
f->name[f->name_length] = 0;
}

void friend_sendimage(FRIEND *f, void *data, void *pngdata, uint16_t width, uint16_t height)
{
MSG_IMG *msg = malloc(sizeof(MSG_IMG));
msg->flags = 5;
msg->w = width;
msg->h = height;
msg->zoom = 0;
msg->data = data;

message_add(&messages_friend, (void*)msg, &f->msg);

tox_postmessage(TOX_SEND_INLINE, f - friend, 0, pngdata);
}

void friend_recvimage(FRIEND *f, void *pngdata, uint32_t size)
{
uint16_t width, height;
void *data = png_to_image(pngdata, &width, &height, size);
if(!data) {
return;
}

MSG_IMG *msg = malloc(sizeof(MSG_IMG));
msg->flags = 4;
msg->w = width;
msg->h = height;
msg->zoom = 0;
msg->data = data;

message_add(&messages_friend, (void*)msg, &f->msg);
}

void friend_notify(FRIEND *f, uint8_t *str, uint16_t str_length, uint8_t *msg, uint16_t msg_length)
{
int len = f->name_length + str_length + 3;
Expand Down
4 changes: 3 additions & 1 deletion friend.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum {
typedef struct {
/* used by the tox thread */
uint8_t status, filenumber, name_length;
_Bool finish;
_Bool finish, inline_png;
uint16_t sendsize, buffer_bytes;
uint32_t fid;
void *data, *buffer;
Expand Down Expand Up @@ -58,6 +58,8 @@ struct friend {

void friend_setname(FRIEND *f, uint8_t *name, uint16_t length);
void friend_addmessage(FRIEND *f, void *data);
void friend_sendimage(FRIEND *f, void *data, void *pngdata, uint16_t width, uint16_t height);
void friend_recvimage(FRIEND *f, void *pngdata, uint32_t size);

void friend_notify(FRIEND *f, uint8_t *str, uint16_t str_length, uint8_t *msg, uint16_t msg_length);
#define friend_notifystr(f, str, msg, mlen) friend_notify(f, (uint8_t*)str, sizeof(str) - 1, msg, mlen)
Expand Down
Binary file removed images/uTox.png
Binary file not shown.
13 changes: 12 additions & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef struct msg_file MSG_FILE;

typedef uint8_t char_t;

#include "png/png.h"

#include "tox.h"
#include "dns.h"
#include "friend.h"
Expand Down Expand Up @@ -108,6 +110,8 @@ enum
CURSOR_TEXT,
CURSOR_HAND,
CURSOR_SELECT,
CURSOR_ZOOM_IN,
CURSOR_ZOOM_OUT,
};
uint8_t cursor;

Expand Down Expand Up @@ -172,6 +176,10 @@ enum
BM_SCROLLHALFTOP,
BM_SCROLLHALFBOT,
BM_STATUSAREA,

BM_CB1,
BM_CB2,
BM_CI1
};

#define isdesktop(x) ((size_t)(x) == 1)
Expand All @@ -180,9 +188,11 @@ void drawalpha(int bm, int x, int y, int width, int height, uint32_t color);
void loadalpha(int bm, void *data, int width, int height);
void* loadsavedata(uint32_t *len);
void writesavedata(void *data, uint32_t len);
void desktopgrab(void);
void desktopgrab(_Bool video);
void notify(uint8_t *title, uint16_t title_length, uint8_t *msg, uint16_t msg_length);
void setscale(void);
void drawimage(void *data, int x, int y, int width, int height, int maxwidth, _Bool zoom);
void* png_to_image(void *data, uint16_t *w, uint16_t *h, uint32_t size);

//me
struct
Expand Down Expand Up @@ -246,6 +256,7 @@ void listpopup(uint8_t item);
void openurl(char_t *str);
void openfilesend(void);
void savefilerecv(uint32_t fid, MSG_FILE *file);
void savefiledata(MSG_FILE *file);

void sysmexit(void);
void sysmsize(void);
Expand Down
67 changes: 59 additions & 8 deletions messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@ void messages_draw(MESSAGES *m, int x, int y, int width, int height)
case 5: {
/* image */
MSG_IMG *img = (void*)msg;
//SIZE size;

//SelectObject(hdcMem, img->bitmap);
//GetBitmapDimensionEx(img->bitmap, &size);
//BitBlt(hdc, x, y, size.cx, size.cy, hdcMem, 0, 0, SRCCOPY);
y += img->height;
int maxwidth = width - MESSAGES_X - TIME_WIDTH;
drawimage(img->data, x + MESSAGES_X, y, img->w, img->h, maxwidth, img->zoom);
y += (img->zoom || img->w <= maxwidth) ? img->h : img->h * maxwidth / img->w;
break;
}

Expand All @@ -119,7 +116,11 @@ void messages_draw(MESSAGES *m, int x, int y, int width, int height)
if(file->status == FILE_DONE) {
drawalpha(BM_FT, xx, y, BM_FT_WIDTH, BM_FT_HEIGHT, (mo && m->over) ? C_GREEN_LIGHT : C_GREEN);
drawalpha(BM_YES, xx + BM_FTM_WIDTH + SCALE + (BM_FTB_WIDTH - BM_FB_WIDTH) / 2, y + SCALE * 4, BM_FB_WIDTH, BM_FB_HEIGHT, WHITE);
drawstr(xx + 5 * SCALE, y + 17 * SCALE, "Click to open");
if(file->inline_png) {
drawstr(xx + 5 * SCALE, y + 17 * SCALE, "Click to save");
} else {
drawstr(xx + 5 * SCALE, y + 17 * SCALE, "Click to open");
}
} else if(file->status == FILE_KILLED) {
drawalpha(BM_FT, xx, y, BM_FT_WIDTH, BM_FT_HEIGHT, C_RED);
drawalpha(BM_NO, xx + BM_FTM_WIDTH + SCALE + (BM_FTB_WIDTH - BM_FB_WIDTH) / 2, y + SCALE * 4, BM_FB_WIDTH, BM_FB_HEIGHT, WHITE);
Expand Down Expand Up @@ -260,6 +261,19 @@ _Bool messages_mmove(MESSAGES *m, int px, int py, int width, int height, int mx,
case 4:
case 5: {
m->over = 0;

MSG_IMG *img = (void*)msg;
int maxwidth = width - MESSAGES_X - TIME_WIDTH;

if(img->w > maxwidth) {
mx -= MESSAGES_X;
int w = img->w > maxwidth ? maxwidth : img->w;
int h = (img->zoom || img->w <= maxwidth) ? img->h : img->h * maxwidth / img->w;
if(mx >= 0 && my >= 0 && mx < w && my < h) {
m->over = 1;
cursor = CURSOR_ZOOM_IN + img->zoom;
}
}
break;
}

Expand Down Expand Up @@ -390,6 +404,16 @@ _Bool messages_mdown(MESSAGES *m)
break;
}

case 4:
case 5: {
MSG_IMG *img = (void*)msg;
if(m->over) {
img->zoom = !img->zoom;
message_updateheight(m, msg, m->data);
}
break;
}

case 6 ... 7: {
MSG_FILE *file = (void*)msg;
if(m->over == 0) {
Expand Down Expand Up @@ -447,7 +471,11 @@ _Bool messages_mdown(MESSAGES *m)

case FILE_DONE: {
if(m->over) {
openurl(file->path);
if(file->inline_png) {
savefiledata(file);
} else {
openurl(file->path);
}
}
break;
}
Expand Down Expand Up @@ -590,6 +618,13 @@ static int msgheight(MESSAGE *msg, int width)
return text_height(width - MESSAGES_X - TIME_WIDTH, font_msg_lineheight, msg->msg, msg->length) + MESSAGES_SPACING;
}

case 4:
case 5: {
MSG_IMG *img = (void*)msg;
int maxwidth = width - MESSAGES_X - TIME_WIDTH;
return ((img->zoom || img->w <= maxwidth) ? img->h : img->h * maxwidth / img->w) + MESSAGES_SPACING;
}

case 6:
case 7: {
return BM_FT_HEIGHT + MESSAGES_SPACING;
Expand Down Expand Up @@ -639,6 +674,22 @@ static void message_setheight(MESSAGES *m, MESSAGE *msg, MSG_DATA *p)
}
}

void message_updateheight(MESSAGES *m, MESSAGE *msg, MSG_DATA *p)
{
if(m->width == 0) {
return;
}

setfont(FONT_MSG);

p->height -= msg->height;
msg->height = msgheight(msg, m->width);
p->height += msg->height;
if(m->data == p) {
m->panel.content_scroll->content_height = p->height;
}
}

void message_add(MESSAGES *m, MESSAGE *msg, MSG_DATA *p)
{
time_t rawtime;
Expand Down
8 changes: 6 additions & 2 deletions messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ typedef struct {
uint16_t flags;
uint32_t height;
uint32_t time;
//HBITMAP bitmap;
uint16_t w, h;
_Bool zoom;
void *data;
} MSG_IMG;

struct msg_file {
Expand All @@ -29,6 +31,7 @@ struct msg_file {
uint32_t time, speed;
uint8_t filenumber, status, name_length;
uint64_t size, progress;
_Bool inline_png;
uint8_t *path;
uint8_t name[64];
};
Expand All @@ -46,5 +49,6 @@ int messages_selection(MESSAGES *m, void *data, uint32_t len);

_Bool messages_char(uint32_t ch);

void messages_updateheight(MESSAGES *m) ;
void messages_updateheight(MESSAGES *m);
void message_updateheight(MESSAGES *m, MESSAGE *msg, MSG_DATA *p);
void message_add(MESSAGES *m, MESSAGE *msg, MSG_DATA *p);
Loading

0 comments on commit 0ae8b94

Please sign in to comment.