summaryrefslogtreecommitdiff
path: root/src/fl_scroll_area.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/fl_scroll_area.cxx')
-rw-r--r--src/fl_scroll_area.cxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/fl_scroll_area.cxx b/src/fl_scroll_area.cxx
new file mode 100644
index 000000000..2aecee7ad
--- /dev/null
+++ b/src/fl_scroll_area.cxx
@@ -0,0 +1,66 @@
+// fl_scroll_area.C
+
+// Drawing function to move the contents of a rectangle. This is passed
+// a "callback" which is called to draw rectangular areas that are moved
+// into the drawing area.
+
+#include <FL/x.H>
+
+// scroll a rectangle and redraw the newly exposed portions:
+void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
+ void (*draw_area)(void*, int,int,int,int), void* data)
+{
+ if (!dx && !dy) return;
+ if (dx <= -W || dx >= W || dy <= -H || dy >= H) {
+ // no intersection of old an new scroll
+ draw_area(data,X,Y,W,H);
+ return;
+ }
+ int src_x, src_w, dest_x, clip_x, clip_w;
+ if (dx > 0) {
+ src_x = X;
+ dest_x = X+dx;
+ src_w = W-dx;
+ clip_x = X;
+ clip_w = dx;
+ } else {
+ src_x = X-dx;
+ dest_x = X;
+ src_w = W+dx;
+ clip_x = X+src_w;
+ clip_w = W-src_w;
+ }
+ int src_y, src_h, dest_y, clip_y, clip_h;
+ if (dy > 0) {
+ src_y = Y;
+ dest_y = Y+dy;
+ src_h = H-dy;
+ clip_y = Y;
+ clip_h = dy;
+ } else {
+ src_y = Y-dy;
+ dest_y = Y;
+ src_h = H+dy;
+ clip_y = Y+src_h;
+ clip_h = H-src_h;
+ }
+#ifdef WIN32
+ BitBlt(fl_gc, dest_x, dest_y, src_w, src_h, fl_gc, src_x, src_y,SRCCOPY);
+ // NYI: need to redraw areas that the source of BitBlt was bad due to
+ // overlapped windows, probably similar to X version:
+#else
+ XCopyArea(fl_display, fl_window, fl_window, fl_gc,
+ src_x, src_y, src_w, src_h, dest_x, dest_y);
+ // we have to sync the display and get the GraphicsExpose events! (sigh)
+ for (;;) {
+ XEvent e; XWindowEvent(fl_display, fl_window, ExposureMask, &e);
+ if (e.type == NoExpose) break;
+ // otherwise assumme it is a GraphicsExpose event:
+ draw_area(data, e.xexpose.x, e.xexpose.y,
+ e.xexpose.width, e.xexpose.height);
+ if (!e.xgraphicsexpose.count) break;
+ }
+#endif
+ if (dx) draw_area(data, clip_x, dest_y, clip_w, src_h);
+ if (dy) draw_area(data, X, clip_y, W, clip_h);
+}