Skip to content

Commit

Permalink
upsidedown dropdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
notsecure committed Aug 14, 2014
1 parent 717eba6 commit 1548596
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion android/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static void android_main(void) /* main thread */
ui_scale(3);

LANG = LANG_EN;
dropdown_language.selected = LANG;
dropdown_language.selected = dropdown_language.over = LANG;

while(!tox_thread_init) {
yieldcpu(1);
Expand Down
45 changes: 31 additions & 14 deletions dropdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@ void dropdown_drawactive(void)
return;
}

int x = active_x, y = active_y, width = active_width, height = active_height;
int x = active_x, y = active_y, w = active_width, h = active_height;

setfont(FONT_TEXT);
setcolor(COLOR_TEXT);
framerect(x, y, x + width, y + height * b->dropcount, BLUE);
drawrect(x + 1, y + 1, x + width - 1, y + height * b->dropcount - 1, WHITE);
int i;

int i, sign = 1;

if(y + h * b->dropcount > height) {
y -= h * (b->dropcount - 1);
sign = -1;
}

drawrect(x, y, x + w, y + h * b->dropcount, WHITE);
framerect(x, y, x + w, y + h * b->dropcount, BLUE);

if(sign == -1) {
y += h * (b->dropcount - 1);
}

for(i = 0; i != b->dropcount; i++) {
int j = index(b, i);
DROP_ELEMENT *e = &b->drop[j];
if(j == b->over) {
drawrectw(x + 1, y + 1 + i * height, width - 2, height - 2, C_GRAY);
drawrectw(x + 1, y + 1, w - 2, h - 2, C_GRAY);
}
drawtextwidth(x + 2 * SCALE, width - 4 * SCALE, y + 2 * SCALE + i * height, e->name, strlen((char*)e->name));
drawtextwidth(x + 2 * SCALE, w - 4 * SCALE, y + 2 * SCALE, e->name, strlen((char*)e->name));

y += sign * h;
}
}

Expand All @@ -49,23 +63,26 @@ void dropdown_draw(DROPDOWN *b, int x, int y, int width, int height)
}
}

_Bool dropdown_mmove(DROPDOWN *b, int x, int y, int width, int height, int mx, int my, int dx, int dy)
_Bool dropdown_mmove(DROPDOWN *b, int x, int y, int w, int h, int mx, int my, int dx, int dy)
{
_Bool mouseover = inrect(mx, my, 0, 0, width, height);
if(mouseover != b->mouseover) {
b->mouseover = mouseover;
return 1;
}

if(b->open) {
int over = my / height;
int over = my / h;
if(y + h * b->dropcount > height) {
over = my > 0 ? 0 : ((-my) / h + 1);
}
if(over < b->dropcount) {
over = index(b, over);
if(over != b->over) {
b->over = over;
return 1;
}
}
} else {
_Bool mouseover = inrect(mx, my, 0, 0, w, h);
if(mouseover != b->mouseover) {
b->mouseover = mouseover;
return 1;
}
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion win32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int n
break;
}

dropdown_language.selected = LANG;
dropdown_language.selected = dropdown_language.over = LANG;

//wait for tox_thread init
while(!tox_thread_init) {
Expand Down
2 changes: 1 addition & 1 deletion xlib/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ int main(int argc, char *argv[])
XftColorAllocValue(display, visual, cmap, &xrcolor, &xftcolor);*/

LANG = systemlang();
dropdown_language.selected = LANG;
dropdown_language.selected = dropdown_language.over = LANG;

/* set-up desktop video input */
dropdown_add(&dropdown_video, (uint8_t*)"None", NULL);
Expand Down

0 comments on commit 1548596

Please sign in to comment.