2013-02-04 17:15:13 +04:00
|
|
|
//list_box
|
2015-07-22 21:32:54 +03:00
|
|
|
#ifndef INCLUDE_LIST_BOX_H
|
|
|
|
#define INCLUDE_LIST_BOX_H
|
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
2013-02-04 17:15:13 +04:00
|
|
|
|
|
|
|
struct llist
|
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
int x, y, w, h, item_h, item_w;
|
|
|
|
int count, visible, first, column_max; //visible = row_max
|
|
|
|
int cur_x, cur_y;
|
|
|
|
int text_y;
|
2015-09-01 12:36:58 +03:00
|
|
|
byte font_w, font_h, font_type;
|
2015-08-29 23:14:17 +03:00
|
|
|
byte wheel_size;
|
|
|
|
byte active;
|
|
|
|
byte no_selection;
|
2015-09-09 17:24:42 +03:00
|
|
|
byte horisontal_selelection;
|
2013-02-04 17:15:13 +04:00
|
|
|
void ClearList();
|
2015-09-09 17:24:42 +03:00
|
|
|
void SetSizes(int xx, yy, ww, hh, item_hh);
|
2015-08-10 15:45:00 +03:00
|
|
|
void SetFont(dword font_ww, font_hh, font_tt);
|
2015-09-09 17:24:42 +03:00
|
|
|
int ProcessKey(dword key);
|
|
|
|
int ProcessMouse(int xx, yy);
|
|
|
|
int MouseOver(int xx, yy);
|
2013-02-04 17:15:13 +04:00
|
|
|
int MouseScroll(dword scroll_state);
|
2015-09-09 17:24:42 +03:00
|
|
|
int KeyDown();
|
|
|
|
int KeyUp();
|
|
|
|
int KeyHome();
|
|
|
|
int KeyEnd();
|
|
|
|
int KeyPgDown();
|
|
|
|
int KeyPgUp();
|
|
|
|
int KeyLeft();
|
|
|
|
int KeyRight();
|
|
|
|
void CheckDoesValuesOkey();
|
2016-01-07 16:10:39 +03:00
|
|
|
void debug();
|
2015-09-09 17:24:42 +03:00
|
|
|
};
|
2015-02-18 22:52:40 +03:00
|
|
|
|
2016-01-07 16:10:39 +03:00
|
|
|
void llist::debug()
|
2015-07-25 00:48:31 +03:00
|
|
|
{
|
2015-08-07 17:55:16 +03:00
|
|
|
char yi[128];
|
2015-09-09 17:24:42 +03:00
|
|
|
sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x);
|
2015-08-07 17:55:16 +03:00
|
|
|
debugln(#yi);
|
2015-07-25 00:48:31 +03:00
|
|
|
}
|
2015-02-18 22:52:40 +03:00
|
|
|
|
2014-03-18 03:10:13 +04:00
|
|
|
|
2013-02-04 17:15:13 +04:00
|
|
|
void llist::ClearList()
|
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
count = visible = first = cur_y = cur_x = 0;
|
2013-02-04 17:15:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-09 17:24:42 +03:00
|
|
|
void llist::SetSizes(int xx, yy, ww, hh, item_hh)
|
2013-02-04 17:15:13 +04:00
|
|
|
{
|
|
|
|
x = xx;
|
|
|
|
y = yy;
|
|
|
|
w = ww;
|
|
|
|
h = hh;
|
2015-09-09 17:24:42 +03:00
|
|
|
item_h = item_hh;
|
|
|
|
text_y = item_h - font_h / 2;
|
|
|
|
visible = h / item_h;
|
2015-08-19 18:14:52 +03:00
|
|
|
wheel_size = 3;
|
2015-09-02 16:15:32 +03:00
|
|
|
CheckDoesValuesOkey();
|
2013-02-04 17:15:13 +04:00
|
|
|
}
|
|
|
|
|
2015-08-10 15:45:00 +03:00
|
|
|
void llist::SetFont(dword font_ww, font_hh, font_tt)
|
|
|
|
{
|
|
|
|
font_w = font_ww;
|
|
|
|
font_h = font_hh;
|
|
|
|
font_type = font_tt;
|
|
|
|
}
|
|
|
|
|
2013-02-04 17:15:13 +04:00
|
|
|
|
|
|
|
int llist::MouseScroll(dword scroll_state)
|
|
|
|
{
|
2014-01-27 05:17:07 +04:00
|
|
|
if (count<=visible) return 0;
|
2013-02-04 17:15:13 +04:00
|
|
|
if (scroll_state == 65535)
|
|
|
|
{
|
|
|
|
if (first == 0) return 0;
|
2015-08-19 18:14:52 +03:00
|
|
|
if (first > wheel_size+1) first -= wheel_size; else first=0;
|
2013-02-04 17:15:13 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (scroll_state == 1)
|
|
|
|
{
|
2015-02-18 22:52:40 +03:00
|
|
|
if (visible + first == count) return 0;
|
2015-08-19 18:14:52 +03:00
|
|
|
if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
|
2013-02-04 17:15:13 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2013-10-20 16:20:57 +04:00
|
|
|
}
|
|
|
|
|
2015-07-25 00:48:31 +03:00
|
|
|
|
2013-10-23 23:03:10 +04:00
|
|
|
int llist::MouseOver(int xx, yy)
|
|
|
|
{
|
|
|
|
if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::ProcessMouse(int xx, yy)
|
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
int cur_y_temp, cur_x_temp, ret=0;
|
2013-10-23 23:03:10 +04:00
|
|
|
if (MouseOver(xx, yy))
|
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
cur_y_temp = yy - y / item_h + first;
|
|
|
|
if (cur_y_temp != cur_y) && (cur_y_temp<count)
|
|
|
|
{
|
|
|
|
cur_y = cur_y_temp;
|
|
|
|
ret = 1;
|
|
|
|
}
|
2015-09-14 01:11:52 +03:00
|
|
|
if (horisontal_selelection)
|
|
|
|
{
|
|
|
|
cur_x_temp = xx - x / item_w;
|
|
|
|
if (cur_x_temp != cur_x) && (cur_x_temp<column_max)
|
|
|
|
{
|
|
|
|
cur_x = cur_x_temp;
|
|
|
|
ret = 1;
|
|
|
|
}
|
2013-10-23 23:03:10 +04:00
|
|
|
}
|
|
|
|
}
|
2015-09-09 17:24:42 +03:00
|
|
|
return ret;
|
2013-10-23 23:03:10 +04:00
|
|
|
}
|
|
|
|
|
2013-10-23 01:35:16 +04:00
|
|
|
int llist::ProcessKey(dword key)
|
|
|
|
{
|
|
|
|
switch(key)
|
|
|
|
{
|
2015-08-10 00:59:25 +03:00
|
|
|
case SCAN_CODE_DOWN: return KeyDown();
|
|
|
|
case SCAN_CODE_UP: return KeyUp();
|
|
|
|
case SCAN_CODE_HOME: return KeyHome();
|
|
|
|
case SCAN_CODE_END: return KeyEnd();
|
|
|
|
case SCAN_CODE_PGUP: return KeyPgUp();
|
|
|
|
case SCAN_CODE_PGDN: return KeyPgDown();
|
2013-10-23 01:35:16 +04:00
|
|
|
}
|
2015-09-09 17:24:42 +03:00
|
|
|
if (horisontal_selelection) switch(key)
|
|
|
|
{
|
|
|
|
case SCAN_CODE_LEFT: return KeyLeft();
|
|
|
|
case SCAN_CODE_RIGHT: return KeyRight();
|
|
|
|
}
|
2013-10-23 01:35:16 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-20 16:20:57 +04:00
|
|
|
int llist::KeyDown()
|
|
|
|
{
|
2015-09-01 12:36:58 +03:00
|
|
|
if (no_selection)
|
|
|
|
{
|
|
|
|
if (visible + first >= count) return 0;
|
|
|
|
first++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y-first+1<visible)
|
2013-10-20 16:20:57 +04:00
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y + 1 >= count) return 0;
|
|
|
|
cur_y++;
|
2013-10-20 16:20:57 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-07 17:55:16 +03:00
|
|
|
if (visible + first >= count) return 0;
|
2013-10-20 16:20:57 +04:00
|
|
|
first++;
|
2015-09-09 17:24:42 +03:00
|
|
|
cur_y++;
|
2013-10-20 16:20:57 +04:00
|
|
|
}
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y < first) || (cur_y > first + visible)
|
2015-08-07 17:55:16 +03:00
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
first = cur_y;
|
2015-08-07 17:55:16 +03:00
|
|
|
CheckDoesValuesOkey();
|
|
|
|
}
|
2013-10-20 16:20:57 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyUp()
|
|
|
|
{
|
2015-09-01 12:36:58 +03:00
|
|
|
if (no_selection)
|
|
|
|
{
|
|
|
|
if (first == 0) return 0;
|
|
|
|
first--;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y > first)
|
2013-10-20 16:20:57 +04:00
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
cur_y--;
|
2013-10-20 16:20:57 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-07 17:55:16 +03:00
|
|
|
if (first == 0) return 0;
|
2013-10-20 16:20:57 +04:00
|
|
|
first--;
|
2015-09-09 17:24:42 +03:00
|
|
|
cur_y--;
|
2013-10-20 16:20:57 +04:00
|
|
|
}
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y < first) || (cur_y > first + visible)
|
2015-08-07 17:55:16 +03:00
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
first = cur_y;
|
2015-08-07 17:55:16 +03:00
|
|
|
CheckDoesValuesOkey();
|
|
|
|
}
|
2013-10-20 16:20:57 +04:00
|
|
|
return 1;
|
2013-10-21 02:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyHome()
|
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y==0) && (first==0) return 0;
|
|
|
|
cur_y = first = 0;
|
2013-10-21 02:47:10 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyEnd()
|
|
|
|
{
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y==count-1) && (first==count-visible) return 0;
|
|
|
|
cur_y = count-1;
|
2015-08-07 17:55:16 +03:00
|
|
|
first = count - visible;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyPgUp()
|
|
|
|
{
|
|
|
|
if (count <= visible) return KeyHome();
|
|
|
|
if (first == 0) return 0;
|
|
|
|
first -= visible;
|
2015-12-13 14:05:14 +03:00
|
|
|
cur_y = first;
|
2015-08-07 17:55:16 +03:00
|
|
|
CheckDoesValuesOkey();
|
2013-10-21 02:47:10 +04:00
|
|
|
return 1;
|
2015-07-22 21:32:54 +03:00
|
|
|
}
|
|
|
|
|
2015-08-07 17:55:16 +03:00
|
|
|
int llist::KeyPgDown()
|
|
|
|
{
|
|
|
|
if (count <= visible) return KeyEnd();
|
|
|
|
if (first == count - visible) return 0;
|
|
|
|
first += visible;
|
2015-12-13 14:05:14 +03:00
|
|
|
cur_y = first + visible - 1;
|
2015-08-07 17:55:16 +03:00
|
|
|
CheckDoesValuesOkey();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llist::CheckDoesValuesOkey()
|
|
|
|
{
|
|
|
|
if (visible + first > count) first = count - visible;
|
2015-09-02 16:15:32 +03:00
|
|
|
if (first < 0) first = 0;
|
2015-09-09 17:24:42 +03:00
|
|
|
if (cur_y >= count) cur_y = count - 1;
|
|
|
|
if (cur_y < 0) cur_y = 0;
|
|
|
|
if (cur_x < 0) cur_x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyRight()
|
|
|
|
{
|
|
|
|
if (cur_x < column_max)
|
|
|
|
{
|
|
|
|
cur_x++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!KeyDown()) return 0;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2015-08-07 17:55:16 +03:00
|
|
|
}
|
|
|
|
|
2015-09-09 17:24:42 +03:00
|
|
|
int llist::KeyLeft()
|
|
|
|
{
|
|
|
|
if (cur_x > 0)
|
|
|
|
{
|
|
|
|
cur_x--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!KeyUp()) return 0;
|
|
|
|
cur_x = column_max;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-17 15:45:56 +03:00
|
|
|
void llist_copy(dword dest, src)
|
|
|
|
{
|
|
|
|
EDI = dest;
|
|
|
|
ESI = src;
|
|
|
|
EDI.llist.x = ESI.llist.x;
|
|
|
|
EDI.llist.y = ESI.llist.y;
|
|
|
|
EDI.llist.w = ESI.llist.w;
|
|
|
|
EDI.llist.h = ESI.llist.h;
|
2015-09-09 17:24:42 +03:00
|
|
|
EDI.llist.item_h = ESI.llist.item_h;
|
2015-08-17 15:45:56 +03:00
|
|
|
EDI.llist.text_y = ESI.llist.text_y;
|
|
|
|
EDI.llist.font_w = ESI.llist.font_w;
|
|
|
|
EDI.llist.font_h = ESI.llist.font_h;
|
|
|
|
EDI.llist.font_type = ESI.llist.font_type;
|
|
|
|
EDI.llist.count = ESI.llist.count;
|
|
|
|
EDI.llist.visible = ESI.llist.visible;
|
|
|
|
EDI.llist.first = ESI.llist.first;
|
2015-09-09 17:24:42 +03:00
|
|
|
EDI.llist.cur_y = ESI.llist.cur_y;
|
2015-08-17 15:45:56 +03:00
|
|
|
EDI.llist.column_max = ESI.llist.column_max;
|
|
|
|
EDI.llist.active = ESI.llist.active;
|
|
|
|
}
|
|
|
|
|
2015-07-22 21:32:54 +03:00
|
|
|
#endif
|