add portable sleep_ms() function

This commit is contained in:
stefan schippers 2023-10-29 23:52:33 +01:00
parent 391a744302
commit 52e36cc46b
3 changed files with 33 additions and 65 deletions

View File

@ -2142,82 +2142,37 @@ int rstate; /* (reduced state, without ShiftMask) */
draw();
break;
}
if( 0 && (key=='u') && rstate==ControlMask) /* testmode */
if(0 && (key=='u') && rstate==ControlMask) /* testmode */
{
static int x = 0;
if(x == 0) {
XFillRectangle(display, xctx->window, xctx->gctiled,
xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height);
} else if(x == 1) {
int i;
for(i = xctx->xrect[0].y; i < xctx->xrect[0].height; i++) {
XDrawLine(display, xctx->window, xctx->gctiled,
xctx->xrect[0].x, i, xctx->xrect[0].width, i);
}
} else if(x == 2) {
int i;
XFillRectangle(display, xctx->window, xctx->gc[BACKLAYER], xctx->areax1, xctx->areay1,
xctx->areaw, xctx->areah);
XFlush(display);
sleep_ms(400);
for(i = xctx->xrect[0].x; i < xctx->xrect[0].width; i++) {
XDrawLine(display, xctx->window, xctx->gctiled,
i, xctx->xrect[0].y, i, xctx->xrect[0].height);
XFlush(display);
sleep_ms(4);
}
} else if(x == 3) {
int i, j;
for(i = 0; i < xctx->xrect[0].width; i+=1) {
for(j = 0; j < xctx->xrect[0].height; j+=1) {
XDrawLine(display, xctx->window, xctx->gctiled,
i, xctx->xrect[0].y, xctx->xrect[0].width - i, j);
XDrawLine(display, xctx->window, xctx->gctiled,
xctx->xrect[0].width - i, xctx->xrect[0].y, i, j);
XDrawLine(display, xctx->window, xctx->gctiled,
i, xctx->xrect[0].height, xctx->xrect[0].width - i, j);
XDrawLine(display, xctx->window, xctx->gctiled,
xctx->xrect[0].width - i, xctx->xrect[0].height, i, j);
}
}
} else if(x == 4) {
int i, j;
XPoint p[2];
for(i = 0; i < xctx->xrect[0].width; i+=1) {
for(j = 0; j < xctx->xrect[0].height; j+=1) {
p[0].x = (short int)i;
p[0].y = (short int)(xctx->xrect[0].y);
p[1].x = (short int)(xctx->xrect[0].width - i);
p[1].y = (short int)j;
XDrawLines(display, xctx->window, xctx->gctiled,
p, 2, CoordModeOrigin);
p[0].x = (short int)(xctx->xrect[0].width - i);
p[0].y = (short int)xctx->xrect[0].y;
p[1].x = (short int)i;
p[1].y = (short int)j;
XDrawLines(display, xctx->window, xctx->gctiled,
p, 2, CoordModeOrigin);
p[0].x = (short int)i;
p[0].y = (short int)xctx->xrect[0].height;
p[1].x = (short int)(xctx->xrect[0].width - i);
p[1].y = (short int)j;
XDrawLines(display, xctx->window, xctx->gctiled,
p, 2, CoordModeOrigin);
p[0].x = (short int)(xctx->xrect[0].width - i);
p[0].y = (short int)xctx->xrect[0].height;
p[1].x = (short int)i;
p[1].y = (short int)j;
XDrawLines(display, xctx->window, xctx->gctiled,
p, 2, CoordModeOrigin);
}
} else if(x == 1) {
int i;
XFillRectangle(display, xctx->window, xctx->gc[BACKLAYER], xctx->areax1, xctx->areay1,
xctx->areaw, xctx->areah);
XFlush(display);
sleep_ms(400);
for(i = xctx->xrect[0].x; i < xctx->xrect[0].width; i++) {
XDrawLine(display, xctx->window, xctx->gctiled,
i, xctx->xrect[0].y, i+1, xctx->xrect[0].height);
XFlush(display);
sleep_ms(4);
}
}
here(x);
x++;
x %= 5;
x %= 2;
break;
}
if(key=='u' && rstate==0) /* undo */

View File

@ -21,7 +21,7 @@
*/
#include "xschem.h"
#include <sys/select.h> /* select() */
static int check_includes(double x1a, double y1a, double x2a, double y2a,
double x1b, double y1b, double x2b, double y2b)
{
@ -116,6 +116,18 @@ void update_conn_cues(int layer, int draw_cues, int dr_win)
}
}
void sleep_ms(int milliseconds)
{
#ifdef __unix__
struct timeval tv;
tv.tv_sec = milliseconds / 1000;
tv.tv_usec = milliseconds % 1000 * 1000;
select(0, NULL, NULL, NULL, &tv);
#else
Sleep(milliseconds);
#endif
}
/* start = 0: initialize timer
* start = 1: return elapsed time since previous call
* start = 2: return total time from initialize */

View File

@ -1224,6 +1224,7 @@ extern int find_closest_wave(int i, Graph_ctx *gr);
extern void setup_graph_data(int i, int skip, Graph_ctx *gr);
extern int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset);
extern int graph_fullxzoom(int i, Graph_ctx *gr, int dataset);
extern void sleep_ms(int milliseconds);
extern double timer(int start);
extern void enable_layers(void);
extern void set_snap(double);