Skip to content

Commit

Permalink
early Xlib support, note: some things are temporarily disabled for wi…
Browse files Browse the repository at this point in the history
…ndows too
  • Loading branch information
notsecure committed Jun 10, 2014
1 parent 5a334bf commit 34bd9c8
Show file tree
Hide file tree
Showing 20 changed files with 1,171 additions and 352 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Lightweight [Tox](https://github.com/irungentoo/ProjectTox-Core) client for Wind

* Some things are incomplete, but feel free to make any design suggestions (colors, fonts, whatever)

* Xlib support is experimental, many features may be missing

## Screenshots
![test](https://raw.github.com/notsecure/winTox/master/images/winTox.png "winTox early build")

Expand All @@ -14,7 +16,7 @@ Something like this:

>windres icons/icon.rc -O coff -o icon.res
>gcc -o winTox.exe *.c icon.res -lgdi32 -lmsimg32 -ldnsapi -lcomdlg32 -lopenal32 -ltoxav
>gcc -o winTox.exe *.c icon.res -lgdi32 -lmsimg32 -ldnsapi -lcomdlg32 -lopenal32 -ltoxav
## Downloads

Expand Down
2 changes: 1 addition & 1 deletion button.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void button_draw(BUTTON *b, int x, int y, int width, int height)
if(b->bm) {
drawbitmapalpha(b->bm, x, y, 48, 48);
} else {
setfont(FONT_BUTTON);
setfont(FONT_TEXT_LARGE);
setcolor(b->mouseover ? 0x222222 : 0x555555);
drawtext(x + 5, y, b->text, b->text_length);
}
Expand Down
6 changes: 4 additions & 2 deletions dns.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "main.h"
#include <windns.h>

static uint32_t parseargument(uint8_t *dest, uint8_t *src, uint16_t length)
{
Expand Down Expand Up @@ -172,9 +171,10 @@ static void dns_thread(void *data)
uint8_t result[256];

uint32_t pin = parseargument(result, data + 2, length);
_Bool success = 0;

#ifdef WIN32
DNS_RECORD *record = NULL;
_Bool success = 0;
DnsQuery((char*)result, DNS_TYPE_TEXT, 0, NULL, &record, NULL);
while(record) {
/* just take the first successfully parsed record (for now), and only parse the first string (seems to work) */
Expand All @@ -188,6 +188,8 @@ static void dns_thread(void *data)

record = record->pNext;
}
#else
#endif

postmessage(DNS_RESULT, success, 0, data);
}
Expand Down
67 changes: 36 additions & 31 deletions edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ void edit_draw(EDIT *edit, int x, int y, int width, int height)
drawtextrangecut(x + 5, x + width - 5, y + 5, edit->data, edit->length);

if(edit == active_edit) {
SIZE size;
GetTextExtentPoint32(hdc, (char*)edit->data, edit_sel.start, &size);
int x1 = textwidth(edit->data, edit_sel.start);
int w = textwidth(edit->data + edit_sel.start, edit_sel.length);

setbgcolor(TEXT_HIGHLIGHT_BG);
setcolor(TEXT_HIGHLIGHT);

if(edit_sel.length) {
drawtextrangecut(x + 5 + size.cx, x + width - 5, y + 5, edit->data + edit_sel.start, edit_sel.length);
drawrect(x + 5 + x1, y + 5, w, 14, TEXT_HIGHLIGHT_BG);
drawtextrangecut(x + 5 + x1, x + width - 5, y + 5, edit->data + edit_sel.start, edit_sel.length);
} else {
drawvline(x + 5 + size.cx, y + 5, y + 19, BLACK);
drawvline(x + 5 + x1, y + 5, y + 19, BLACK);
}

setbgcolor(~0);
}
}

Expand All @@ -45,19 +43,20 @@ _Bool edit_mmove(EDIT *edit, int x, int y, int dy, int width, int height)
}

if(edit == active_edit && edit_select) {
int fit = 0, extent = x - 5;
SIZE size;
int fit = 0, extent = x - 5, x1, x2;

setfont(FONT_TEXT);

if(extent > 0) {
GetTextExtentExPoint(hdc, (char*)edit->data, edit->length, extent, &fit, NULL, &size);
fit = textfit(edit->data, edit->length, extent);

if(fit != edit->length) {
x1 = textwidth(edit->data, fit);
x2 = textwidth(edit->data, fit + 1);

GetTextExtentPoint32(hdc, (char*)edit->data, fit, &size);
int sx = size.cx;
GetTextExtentPoint32(hdc, (char*)edit->data, fit + 1, &size);
if(fit != edit->length && size.cx - extent < extent - sx) {
fit += 1;
if(x2 - extent < extent - x1) {
fit++;
}
}
}

Expand All @@ -72,19 +71,29 @@ _Bool edit_mmove(EDIT *edit, int x, int y, int dy, int width, int height)

redraw = 1;
} else if(mouseover) {
int fit = 0, extent = x - 5;
SIZE size;
int fit = 0, extent = x - 5, x1, x2;

setfont(FONT_TEXT);
GetTextExtentExPoint(hdc, (char*)edit->data, edit->length, extent, &fit, NULL, &size);
fit = textfit(edit->data, edit->length, extent);

if(fit != edit->length) {
x1 = textwidth(edit->data, fit);
x2 = textwidth(edit->data, fit + 1);

if(x2 - extent < extent - x1) {
fit++;
}
}

/*GetTextExtentExPoint(hdc, (char*)edit->data, edit->length, extent, &fit, NULL, &size);
GetTextExtentPoint32(hdc, (char*)edit->data, fit, &size);
int sx = size.cx;
GetTextExtentPoint32(hdc, (char*)edit->data, fit + 1, &size);
if(fit != edit->length && size.cx - extent < extent - sx) {
fit += 1;
}
}*/

edit->mouseover_char = fit;
}
Expand Down Expand Up @@ -177,7 +186,7 @@ void edit_char(uint32_t ch)
}
} else {
switch(ch) {
case VK_BACK: {
case KEY_BACK: {
if(edit_sel.length == 0) {
if(edit_sel.start != 0) {
memmove(edit->data + edit_sel.start - 1, edit->data + edit_sel.start, edit->length - edit_sel.start);
Expand All @@ -193,7 +202,7 @@ void edit_char(uint32_t ch)
break;
}

case VK_RETURN: {
case KEY_RETURN: {
if(edit->onenter) {
edit->onenter();
}
Expand All @@ -217,38 +226,34 @@ void edit_copy(void)
return;
}

HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, length + 1);
/*HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, length + 1);
uint8_t *p = GlobalLock(hMem);
memcpy(p, active_edit->data + edit_sel.start, length);
p[length] = 0;
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
CloseClipboard();*/
}

void edit_paste(void)
void edit_paste(uint8_t *data, int length)
{
if(!active_edit) {
return;
}

OpenClipboard(NULL);
char *cd = GetClipboardData(CF_TEXT);
int length = strlen(cd);
char str[length], *s = str, c;
uint8_t str[length], *s = str, c;
//paste only allowed characters
while((c = *cd++)) {
while((c = *data++)) {
if(c >= ' ' && c <= 126) {
*s++ = c;
} else {
length--;
}
}
CloseClipboard();

int newlen = (int)active_edit->length + length;
int newlen = active_edit->length + length;
if(newlen > active_edit->maxlength) {
//for now just return if paste doesnt fit
return;
Expand Down
2 changes: 1 addition & 1 deletion edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void edit_char(uint32_t ch);

void edit_cut(void);
void edit_copy(void);
void edit_paste(void);
void edit_paste(uint8_t *data, int len);
void edit_delete(void);
void edit_selectall(void);
void edit_clear(void);
Expand Down
121 changes: 65 additions & 56 deletions icons/misc.c
Original file line number Diff line number Diff line change
@@ -1,75 +1,83 @@
#ifdef WIN32
#define B(x) (x)
#else
#define B(x) (((~x & 0xFF) * 0x0202020202ULL & 0x010884422010ULL) % 1023)
#endif

uint8_t
bm_minimize_bits[] = {
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00001111, 0b11110000,
0b00001111, 0b11110000,
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00000000), B(0b00000000),
B(0b00001111), B(0b11110000),
B(0b00001111), B(0b11110000),
},

bm_maximize_bits[] = {
0b00011111, 0b11111000,
0b00011111, 0b11111000,
0b00011111, 0b11111000,
0b00010000, 0b00001000,
0b00010000, 0b00001000,
0b00010000, 0b00001000,
0b00010000, 0b00001000,
0b00010000, 0b00001000,
0b00010000, 0b00001000,
0b00011111, 0b11111000,
B(0b00011111), B(0b11111000),
B(0b00011111), B(0b11111000),
B(0b00011111), B(0b11111000),
B(0b00010000), B(0b00001000),
B(0b00010000), B(0b00001000),
B(0b00010000), B(0b00001000),
B(0b00010000), B(0b00001000),
B(0b00010000), B(0b00001000),
B(0b00010000), B(0b00001000),
B(0b00011111), B(0b11111000),
},

bm_restore_bits[] = {
0b00000111, 0b11111000,
0b00000111, 0b11111000,
0b00000100, 0b00001000,
0b00011111, 0b11101000,
0b00011111, 0b11101000,
0b00010000, 0b00101000,
0b00010000, 0b00111000,
0b00010000, 0b00100000,
0b00010000, 0b00100000,
0b00011111, 0b11100000,
B(0b00000111), B(0b11111000),
B(0b00000111), B(0b11111000),
B(0b00000100), B(0b00001000),
B(0b00011111), B(0b11101000),
B(0b00011111), B(0b11101000),
B(0b00010000), B(0b00101000),
B(0b00010000), B(0b00111000),
B(0b00010000), B(0b00100000),
B(0b00010000), B(0b00100000),
B(0b00011111), B(0b11100000),
},

bm_exit_bits[] = {
0b00001000, 0b00010000,
0b00011100, 0b00111000,
0b00001110, 0b01110000,
0b00000111, 0b11100000,
0b00000011, 0b11000000,
0b00000011, 0b11000000,
0b00000111, 0b11100000,
0b00001110, 0b01110000,
0b00011100, 0b00111000,
0b00001000, 0b00010000,
B(0b00001000), B(0b00010000),
B(0b00011100), B(0b00111000),
B(0b00001110), B(0b01110000),
B(0b00000111), B(0b11100000),
B(0b00000011), B(0b11000000),
B(0b00000011), B(0b11000000),
B(0b00000111), B(0b11100000),
B(0b00001110), B(0b01110000),
B(0b00011100), B(0b00111000),
B(0b00001000), B(0b00010000),
},

bm_plus_bits[] = {
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0, 0,
0, 0,
0, 0,
0, 0,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
0b11111100, 0b00111111,
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0), B(0),
B(0), B(0),
B(0), B(0),
B(0), B(0),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
B(0b11111100), B(0b00111111),
};

#undef B

#define F(r, g, b, a) (RGB((b * a) / 0xFF, (g * a) / 0xFF, (r * a) / 0xFF) | a << 24)
#define G(x) F(107, 194, 96, x)
uint32_t
Expand Down Expand Up @@ -128,3 +136,4 @@ bm_offline_bits[] = {
G(0 ), G(0 ), G(83 ), G(194), G(238), G(238), G(194), G(83 ), G(0 ), G(0 ),
};
#undef G
#undef F
4 changes: 2 additions & 2 deletions list.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void drawname(ITEM *i, int x, int y, uint8_t *name, uint8_t *msg, uint16_
setfont(FONT_MED);
drawtextwidth(x + 50, ITEM_WIDTH - 50, y + 6, name, name_length);

setcolor((sitem == i) ? 0xFFE6C5 : 0x999999);
setcolor((sitem == i) ? RGB(0xC5, 0xE6, 0xFF) : 0x999999);
setfont(FONT_TEXT_LARGE);
drawtextwidth(x + 50, ITEM_WIDTH - 50, y + 25, msg, msg_length);
}
Expand All @@ -58,7 +58,7 @@ static void drawitem(ITEM *i, int x, int y)
{
drawitembox(i, x, y);

SetBkMode(hdc, TRANSPARENT);
setbgcolor(~0);

switch(i->item)
{
Expand Down
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

#ifdef WIN32
#include "win32/main.c"
#else
#include "xlib/main.c"
#endif
Loading

0 comments on commit 34bd9c8

Please sign in to comment.