|
@@ -61,8 +61,8 @@ void loadFont(struct printerEnv *env, XFontStruct **font, char* fontname)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-struct printerEnv printerOpenWindow(int width, int height, int margin_bottom,
|
|
|
|
- char *font, char *font_i, char *font_b, char *font_bi)
|
|
|
|
|
|
+struct printerEnv printerOpenWindow(int margin_bottom, char *font, char *font_i,
|
|
|
|
+ char *font_b, char *font_bi)
|
|
{
|
|
{
|
|
struct printerEnv env;
|
|
struct printerEnv env;
|
|
|
|
|
|
@@ -99,12 +99,13 @@ struct printerEnv printerOpenWindow(int width, int height, int margin_bottom,
|
|
//env.color_background = a*256*256*256 + r*256*256 + g*256 + b;
|
|
//env.color_background = a*256*256*256 + r*256*256 + g*256 + b;
|
|
|
|
|
|
// create the window
|
|
// create the window
|
|
- env.width = (width < 0) ? RootAttr.width : width;
|
|
|
|
- env.height = height;
|
|
|
|
- env.w = XCreateWindow(env.d, RootWindow(env.d, env.s),
|
|
|
|
- (RootAttr.width - env.width)/2,
|
|
|
|
- RootAttr.height - env.height - margin_bottom, env.width, env.height, 0,
|
|
|
|
- vinfo.depth, InputOutput, vinfo.visual,
|
|
|
|
|
|
+ env.margin_bottom = margin_bottom;
|
|
|
|
+ env.root_width = RootAttr.width;
|
|
|
|
+ env.root_height = RootAttr.height;
|
|
|
|
+ env.width = 1;
|
|
|
|
+ env.height = 1;
|
|
|
|
+ env.w = XCreateWindow(env.d, RootWindow(env.d, env.s), 0, 0, env.width,
|
|
|
|
+ env.height, 0, vinfo.depth, InputOutput, vinfo.visual,
|
|
CWColormap | CWBorderPixel | CWBackPixel | CWOverrideRedirect, &attr);
|
|
CWColormap | CWBorderPixel | CWBackPixel | CWOverrideRedirect, &attr);
|
|
|
|
|
|
// setting fonts
|
|
// setting fonts
|
|
@@ -312,11 +313,10 @@ int printLines(struct printerEnv env, char *text, int gap, int y,
|
|
return width;
|
|
return width;
|
|
}
|
|
}
|
|
|
|
|
|
-void printerShow(struct printerEnv env, char* text, enum t_type font)
|
|
|
|
|
|
+void printerShow(struct printerEnv *env, char* text, enum t_type font)
|
|
{
|
|
{
|
|
int gap = 5, padding = 5;
|
|
int gap = 5, padding = 5;
|
|
- int nlines = 1,
|
|
|
|
- width, height;
|
|
|
|
|
|
+ int nlines = 1;
|
|
char *p = text;
|
|
char *p = text;
|
|
while((p = strchr(p, '\n')) != NULL)
|
|
while((p = strchr(p, '\n')) != NULL)
|
|
{
|
|
{
|
|
@@ -325,22 +325,25 @@ void printerShow(struct printerEnv env, char* text, enum t_type font)
|
|
break;
|
|
break;
|
|
nlines++;
|
|
nlines++;
|
|
}
|
|
}
|
|
|
|
+ // width and height
|
|
|
|
+ env->width = printLines(*env, text, gap, 0, font, 0) + 2*padding;
|
|
|
|
+ env->height = nlines * (env->maxascent + env->maxdescent + gap) - gap +
|
|
|
|
+ 2*padding;
|
|
|
|
|
|
- XClearWindow(env.d, env.w);
|
|
|
|
- // max width
|
|
|
|
- width = printLines(env, text, gap, 0, font, 0);
|
|
|
|
- height = nlines * (env.maxascent + env.maxdescent + gap) - gap;
|
|
|
|
|
|
+ XClearWindow(env->d, env->w);
|
|
|
|
+
|
|
|
|
+ XMoveResizeWindow(env->d, env->w, (env->root_width - env->width)/2,
|
|
|
|
+ env->root_height - env->margin_bottom - env->height, env->width,
|
|
|
|
+ env->height);
|
|
|
|
|
|
// frame
|
|
// frame
|
|
- XSetForeground(env.d, env.gc, env.color_background);
|
|
|
|
- XFillRectangle(env.d, env.w, env.gc, (env.width - width)/2 - padding,
|
|
|
|
- env.height - 2*padding - height, width + 2*padding, height + 2*padding);
|
|
|
|
- XSetForeground(env.d, env.gc, env.color_text);
|
|
|
|
|
|
+ XSetForeground(env->d, env->gc, env->color_background);
|
|
|
|
+ XFillRectangle(env->d, env->w, env->gc, 0, 0, env->width, env->height);
|
|
|
|
+ XSetForeground(env->d, env->gc, env->color_text);
|
|
|
|
|
|
// text
|
|
// text
|
|
- printLines(env, text, gap,
|
|
|
|
- env.height - padding - height + env.maxascent, font, 1);
|
|
|
|
- XFlush(env.d);
|
|
|
|
|
|
+ printLines(*env, text, gap, padding + env->maxascent, font, 1);
|
|
|
|
+ XFlush(env->d);
|
|
}
|
|
}
|
|
|
|
|
|
void printerClean(struct printerEnv env)
|
|
void printerClean(struct printerEnv env)
|