📄 listscroll.c
字号:
#include <membox.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "GUI.h"
#include "Globalvars.h"
#include "pwin.h"
#include "guidebug.h"
extern Pw_Bitmap bmDownDir2a;
extern Pw_Bitmap bmUpDir2a;
extern Pw_Bitmap bmPosVisir2;
void ListBoxPaint (Pw_GC * gc) {
Pw_Window * win;
TLISTBOX * listbox;
char * item;
int i, x, y, w, h;
win = Pw_GCGetWindow(gc);
Pw_WindowGetSize(win, &w, &h);
listbox = (TLISTBOX *) win->cdata;
Pw_GCSetFont(gc,listbox ->Font);
Pw_GCSetColor(gc, pw_white_pixel);
x = 4; y = Pw_GCGetFontHeight(gc);
for (i = 0; i < listbox->ScrollPage; i++) {
if (i == listbox->ItemCount) break;
if (listbox->Selected == (listbox->ScrollPos+i)) {
Pw_GCSetColor(gc, pw_white_pixel);
Pw_FillRect(gc, x, y-Pw_GCGetFontHeight(gc)+2, w-12, Pw_GCGetFontHeight(gc)+2);
Pw_GCSetColor(gc, pw_black_pixel);
}
else {
Pw_GCSetColor(gc, pw_black_pixel);
Pw_FillRect(gc, x, y-Pw_GCGetFontHeight(gc)+2, w-12, Pw_GCGetFontHeight(gc)+2);
Pw_GCSetColor(gc, pw_white_pixel);
}
item = listbox->GetItem(i+listbox->ScrollPos);
Pw_DrawString(gc, x, y, item);
y += Pw_GCGetFontHeight(gc);
}
x = w - 11;
Pw_GCSetColor(gc, pw_black_pixel);
Pw_FillRect(gc, x, 0, 9, h);
Pw_GCSetColor(gc, pw_white_pixel);
Pw_DrawLine(gc, x, 0, x, h - 11);
Pw_DrawBitmap(gc, x, 0, &bmUpDir2a);
Pw_DrawBitmap(gc, x, h-11, &bmDownDir2a);
y = (int)((float)h*((float)(listbox->Selected)/(float)(listbox->ItemCount)));
//GUI_Log3("SCROLL ", y, listbox->Selected, listbox->ItemCount);
if (y < 10) y = 10;
if (y > (h-12)) y = h - 24;
Pw_DrawBitmap(gc, x, y, &bmPosVisir2);
}
int ListBoxEventHandler(Pw_Event * ev) {
Pw_Window* win;
Pw_uInt key;
TLISTBOX * listbox;
win = Pw_EventGetWindow(ev);
listbox = (TLISTBOX *) win->cdata;
switch (Pw_EventGetType(ev)) {
case Pw_KeyPressEventType:
key = ev->key.keycode;
switch (key) {
case DOWN_KEY :
if (/*(listbox->Selected < (listbox->ScrollPage-1))|| */
(listbox->Selected < (listbox->ScrollPos + listbox->ScrollPage-1))){
if ((listbox->Selected < (listbox->ItemCount-1))) {
listbox->Selected++;
Pw_WindowRepaint(win);
}
}
else
if (((listbox->ScrollPos + listbox->ScrollPage-1) < (listbox->ItemCount-1))) {
listbox->Selected++;
listbox->ScrollPos++;
Pw_WindowRepaint(win);
}
// GUI_Log1("Selected ", mnu->Selected);
return TRUE;
case UP_KEY :
if (listbox->Selected > listbox->ScrollPos) {
listbox->Selected--;
Pw_WindowRepaint(win);
}
else
if (listbox->Selected > 0) {
listbox->Selected--;
listbox->ScrollPos--;
Pw_WindowRepaint(win);
}
// GUI_Log1("Selected ", mnu->Selected);
return TRUE;
// case ESC_KEY:
// Pw_WindowUnmap(win);
// Pw_WindowDestroy(win);
// return FALSE;
}
}
return FALSE;
}
Pw_Window * CreateListBox(Pw_Window * parent, TLISTBOX * list_box, GetListItem get_item, int count) {
Pw_Window * win;
int x, y, w, h;
x = 0;
y = 2* Pw_FontGetHeight(F9x15_pwf)+4; w = Pw_WindowGetWidth(parent);
h = Pw_WindowGetHeight(parent) - 2* Pw_FontGetHeight(F9x15_pwf)-4; win = Pw_WindowCreate(parent, x, y, w, h, &(list_box->Win));
win->cdata = list_box;
list_box->ItemCount = count;
list_box->ScrollPos = 0;
list_box->Selected = 0;
list_box->GetItem = get_item;
list_box->Font = F9x15_pwf;
list_box->ScrollPage = h / Pw_FontGetHeight(list_box->Font) - 1;
Pw_WindowSetRepaintCallback(win, ListBoxPaint);
Pw_WindowSetEventCallback(win, ListBoxEventHandler);
Pw_WindowSetFocusAccept(win, TRUE);
Pw_WindowMap(win);
Pw_WindowSetFocus(win);
return win;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -