3 #ifndef __ZBaseInline_H
4 #define __ZBaseInline_H
15 INLINE ZPoint::ZPoint ()
22 INLINE ZPoint::ZPoint (
int x_coord,
int y_coord)
30 INLINE ZPoint::ZPoint (
const ZPoint& zpoint)
38 INLINE ZPoint::operator XPoint ()
const
50 ZPoint::add_offset (
const ZSize& zsize)
59 ZPoint::sub_offset (
const ZSize& zsize)
68 ZPoint::print (
const char* szEnd)
const
70 printf(
"ZPoint:: x=%d, y=%d %s", x, y, szEnd);
76 ZPoint::operator== (
const ZPoint& zpoint)
const
78 return x == zpoint.x && y == zpoint.y;
84 ZPoint::operator!= (
const ZPoint& zpoint)
const
86 return !operator==(zpoint);
96 INLINE ZSize::ZSize ()
103 INLINE ZSize::ZSize (
int width,
int height)
111 INLINE ZSize::ZSize (
const ZSize& zsize)
120 ZSize::difference (
const ZPoint& zpoint1,
const ZPoint& zpoint2)
122 w = zpoint1.x - zpoint2.x;
123 h = zpoint1.y - zpoint2.y;
129 ZSize::print (
const char* szEnd)
const
131 printf(
"ZSize:: w=%d, h=%d %s", w, h, szEnd);
137 ZSize::operator== (
const ZSize& zsize)
const
139 return w == zsize.w && h == zsize.h;
145 ZSize::operator!= (
const ZSize& zsize)
const
147 return !operator==(zsize);
157 INLINE ZRect::ZRect ()
162 INLINE ZRect::ZRect (
const ZPoint& zpoint1,
164 :
ZPoint(MIN(zpoint1.x, zpoint2.x), MIN(zpoint1.y, zpoint2.y)),
165 ZSize(ABS(zpoint1.x - zpoint2.x), ABS(zpoint1.y - zpoint2.y))
171 INLINE ZRect::ZRect (
const ZPoint& zpoint,
172 const ZSize& zsize, ZCorner zcorner)
175 move(zpoint, zcorner);
180 INLINE ZRect::ZRect (
const ZRect& zrect)
188 ZRect::print (
const char* szEnd)
const
190 printf(
"ZRect:: x=%d, y=%d, w=%d, h=%d %s", x, y, w, h, szEnd);
196 ZRect::operator== (
const ZRect& zrect)
const
198 return ZPoint::operator==(zrect) && ZSize::operator==(zrect);
204 ZRect::operator!= (
const ZRect& zrect)
const
206 return !operator==(zrect);
226 ZConnect::root_wid ()
const
228 register Window wid = RootWindow(dpy, scr_no);
249 ZConnect::rect ()
const
251 return rect(root_wid());
259 ZConnect::depth (Drawable drawable)
const
265 XGetGeometry(dpy, drawable, &root_wid, (
int*)&dummy,
266 (
int*)&dummy, &dummy, &dummy, &dummy, &d);
276 ZConnect::white ()
const
278 return WhitePixel(dpy, scr_no);
286 ZConnect::black ()
const
288 return BlackPixel(dpy, scr_no);
296 ZConnect::color (
const char* szColorName)
const
298 return zcp_color_pixel(szColorName);
316 ZGEnv::text_width (
const char* szText)
const
318 if(szText == NULL) Throw(ERROR__NULL);
320 if(szText[0] ==
'\0')
323 return XTextWidth(font, szText, strlen(szText));
331 ZGEnv::text_width (
int n)
const
333 return n * font->max_bounds.width;
341 ZGEnv::text_ascent ()
const
351 ZGEnv::text_descent ()
const
353 return font->descent;
361 ZGEnv::text_height ()
const
363 return text_ascent() + text_descent();
371 ZGEnv::draw_text (Drawable
id,
int x,
int y,
int attachment,
372 const char* szText)
const
374 if(szText == NULL) Throw(ERROR__NULL);
376 ZRect r = text_rect(x, y, attachment, szText);
377 XDrawString(dpy,
id, gc, r.x, r.y + r.h - 1 - text_descent(),
378 szText, strlen(szText));
388 ZGEnv::set_foreground (ColorPixel cp)
390 XSetForeground(dpy, gc, cp);
391 changed_state(ChangedForeground);
395 if(!strcmp(fg_name,
"black"))
399 fg_name = strdup(
"black");
405 ZGEnv::set_foreground (
const char* szColorName)
407 set_foreground(color(szColorName));
411 if(!strcmp(fg_name, szColorName))
415 fg_name = strdup(szColorName);
421 ZGEnv::get_foreground ()
const
424 Status rc = XGetGCValues(dpy, gc, GCForeground, &gc_val);
426 x_error(ERROR__X_GET_GC_VALUES);
427 return gc_val.foreground;
433 ZGEnv::get_foreground_name ()
const
441 ZGEnv::set_background (ColorPixel cp)
443 XSetBackground(dpy, gc, cp);
444 changed_state(ChangedBackground);
448 if(!strcmp(bg_name,
"white"))
452 bg_name = strdup(
"white");
458 ZGEnv::set_background (
const char* szColorName)
460 set_background(color(szColorName));
464 if(!strcmp(bg_name, szColorName))
468 bg_name = strdup(szColorName);
474 ZGEnv::get_background ()
const
477 Status rc = XGetGCValues(dpy, gc, GCBackground, &gc_val);
479 x_error(ERROR__X_GET_GC_VALUES);
480 return gc_val.background;
486 ZGEnv::get_background_name ()
const
494 ZGEnv::set_line_width (
int new_width)
497 gc_val.line_width = new_width;
498 XChangeGC(dpy, gc, GCLineWidth, &gc_val);
500 changed_state(ChangedLineWidth);
506 ZGEnv::get_line_width ()
const
509 Status rc = XGetGCValues(dpy, gc, GCLineWidth, &gc_val);
511 x_error(ERROR__X_GET_GC_VALUES);
512 return gc_val.line_width;
518 ZGEnv::set_line_style (
int new_style,
int dash,
int hole)
521 gc_val.line_style = new_style;
522 XChangeGC(dpy, gc, GCLineStyle, &gc_val);
527 XSetDashes(dpy, gc, 0, dash_hole, NUMBER(dash_hole));
529 changed_state(ChangedLineStyle);
535 ZGEnv::get_line_style ()
const
538 Status rc = XGetGCValues(dpy, gc, GCLineStyle, &gc_val);
540 x_error(ERROR__X_GET_GC_VALUES);
541 return gc_val.line_style;
547 ZGEnv::get_font_name ()
const
555 ZGEnv::set_font_as (
const ZGEnv& zgenv)
557 set_font(zgenv.get_font_name());
563 ZGEnv::get_font ()
const
566 Status rc = XGetGCValues(dpy, gc, GCFont, &gc_val);
568 x_error(ERROR__X_GET_GC_VALUES);
579 INLINE ZWindow::ZWindow (
const ZConnect& zconnect, Window window)
587 INLINE ZWindow::ZWindow (
const ZWindow& zwindow)
598 ZWindow::draw_text (
int x,
int y,
int attachment,
599 const char* szText)
const
601 ZGEnv::draw_text(wid, x, y, attachment, szText);
609 ZWindow::draw_text (
const ZRect& box,
int alignment,
610 const char* szText)
const
612 ZGEnv::draw_text(wid, box, alignment, szText);
622 INLINE ZDrawable::ZDrawable (
const ZConnect& zconnect, Drawable drawable)
630 INLINE ZDrawable::ZDrawable (
const ZDrawable& zdrawable)
641 ZDrawable::draw_text (
int x,
int y,
int attachment,
642 const char* szText)
const
644 ZGEnv::draw_text(did, x, y, attachment, szText);
652 ZDrawable::draw_text (
const ZRect& box,
int alignment,
653 const char* szText)
const
655 ZGEnv::draw_text(did, box, alignment, szText);
665 INLINE ZArea::ZArea (
const ZConnect& zconnect,
const ZSize& zsize)
668 (Drawable)XCreatePixmap(zconnect.dpy,
669 zconnect.root_wid(), zsize.w, zsize.h,
670 zconnect.depth(zconnect.root_wid())))
677 INLINE ZArea::ZArea (
const ZArea& zarea)
680 (Drawable)XCreatePixmap(zarea.dpy, zarea.root_wid(),
683 zarea.depth(zarea.did)))
686 XCopyArea(dpy, zarea.did, did, gc, 0, 0,
687 zarea.rect().w, zarea.rect().h, 0, 0);
695 ZArea::resize (
const ZSize& zsize)
697 XFreePixmap(dpy, did);
698 did = (Drawable)XCreatePixmap(dpy, root_wid(), zsize.w, zsize.h,
710 INLINE ZWidget::ZWidget (Widget w)