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