📄 progressbar.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"
#define PROGRESSBAR_DEFAULT_FONT F9x15_pwf
extern unsigned char xhuge _HeapGUI[GUI_HEAP_SIZE];
Pw_Timeout ProgressTimeOut;
int ProgressStep;
//------------------------------------------------------
void cbPaintProgressBar (Pw_GC * gc) {
Pw_Window* win;
Pw_Coord w, h, x, y, wt;
int value;
char sv[4];
win = Pw_GCGetWindow(gc);
Pw_WindowGetSize(win, &w, &h);
Pw_DrawFrameRect(gc, 0, 0, w-1, h, 1, NULL);
Pw_GCSetFont(gc, ProgressBarFont);//PROGRESSBAR_DEFAULT_FONT);
value = *(int *)Pw_WindowGetClientData(win);
wt = value* w / 100;
if (wt > w) return;
Pw_DrawGrayTextBackgr(gc, 1, 1 , wt, h-2);
sprintf(sv, "%0d%%", value);
wt = Pw_FontGetStringWidth(gc->font, sv);
x = (w- wt)/2;
y = Pw_GCGetFontHeight(gc)+1;
Pw_GCSetColor(gc, pw_white_pixel);
Pw_DrawString(gc, x, y, sv);
}
//------------------------------------------------------
int cbProgressBar (Pw_Event * ev) {
Pw_Window * win;
//int CtrlType;
win = Pw_EventGetWindow(ev);
// CtrlType = Pw_WindowGetClientDataId(win);
switch (Pw_EventGetType(ev)) {
}
return FALSE;
}
//------------------------------------------------------
void ResetProgressBar(Pw_Window * progbar) {
*(int *)Pw_WindowGetClientData(progbar) = 0;
GUI_TICKER_ON;
// Pw_WindowRepaint(progbar);
}
//------------------------------------------------------
int ProgressBarTime (Pw_Display* dpy, Pw_Pointer data) {
int * t;
Pw_Window* win = (Pw_Window*)data;
dpy = dpy;
t = (int *)Pw_WindowGetClientData(win);
(*t) += ProgressStep; // ~30 sec
if (*t > 100) ResetProgressBar(win);
Pw_WindowRepaint(win); return(TRUE);
}
void SetProgressStep (int step) {
ProgressStep = step;
}
//------------------------------------------------------
Pw_Window * CreateProgressBar (Pw_Window * Parent, Pw_EventCb cb, int * PtrValue, int x, int y, int w, int h) {
Pw_Window * progbar;
progbar = _calloc_boxh (_HeapGUI);
cb = cb;
ProgressStep = 1;
Pw_WindowCreate(Parent, x, y, w, h, progbar);
Pw_WindowSetClientDataId(progbar, PROGRESSBAR_ID);
if (PtrValue) {
*PtrValue = 0;
Pw_WindowSetClientData(progbar, PtrValue);
};
// else Pw_WindowSetClientData(progbar, 0);
if (h >= (PROGRESSBAR_DEFAULT_FONT->ascent + PROGRESSBAR_DEFAULT_FONT->descent))
ProgressBarFont = PROGRESSBAR_DEFAULT_FONT;
else
ProgressBarFont = slkscrb_pwf;
Pw_WindowSetRepaintCallback(progbar, cbPaintProgressBar);
if (NULL == cb) Pw_WindowSetEventCallback(progbar, cbProgressBar);
Pw_WindowMap(progbar);
return progbar;
}
//------------------------------------------------------
void DestroyProgressBar(Pw_Window * progbar) {
Pw_WindowUnmap(progbar);
Pw_WindowDestroy (progbar);
Pw_TimeoutDestroy(&Display, &ProgressTimeOut);
_free_boxh (_HeapGUI, progbar);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -