From 16304b9f01fd9631e03866fa50ce2ffa849e0201 Mon Sep 17 00:00:00 2001
From: Etienne Brateau <etienne.brateau@ensiie.fr>
Date: Wed, 20 Feb 2019 18:52:39 +0100
Subject: [PATCH] Move some zoom functions into display module

---
 Makefile          |  3 ++-
 include/display.h |  8 ++++++
 src/display.c     | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 src/log.c         | 55 +----------------------------------------
 4 files changed, 73 insertions(+), 55 deletions(-)
 create mode 100644 include/display.h
 create mode 100644 src/display.c

diff --git a/Makefile b/Makefile
index 4137051..ffe1132 100644
--- a/Makefile
+++ b/Makefile
@@ -120,7 +120,8 @@ TOOLOBJ = $(SIMOBJ) \
 	  $(TARGET_DIR)/pagewriter.o $(TARGET_DIR)/pagereader.o	\
 	  $(TARGET_DIR)/configreader.o $(TARGET_DIR)/attrs.o \
 	  $(TARGET_DIR)/keyboard.o $(TARGET_DIR)/box.o \
-	  $(TARGET_DIR)/pen.o $(TARGET_DIR)/libraryreader.o
+	  $(TARGET_DIR)/pen.o $(TARGET_DIR)/libraryreader.o \
+	  $(TARGET_DIR)/display.o
 
 
 $(TARGET_DIR)/ana/%.o: $(SRC_DIR)/ana/%.c
diff --git a/include/display.h b/include/display.h
new file mode 100644
index 0000000..26e3abc
--- /dev/null
+++ b/include/display.h
@@ -0,0 +1,8 @@
+#ifndef DISPLAY_H
+#define DISPLAY_H
+
+void setscale(short s);
+void zoomto(short z);
+void scroll();
+
+#endif
diff --git a/src/display.c b/src/display.c
new file mode 100644
index 0000000..b83ea0b
--- /dev/null
+++ b/src/display.c
@@ -0,0 +1,62 @@
+#include "display.h"
+#include "logglobals.h"
+#include "logdef.h"
+#include "window.h"
+#include "keyboard.h"
+#include "log.h"
+
+short zoom;   ///< Zooming level
+
+/// Set the scaling (zoom) factor.
+void setscale(short s)
+{
+	zoom = s;
+	gg.scale = zoomscales[s + 2];
+	gg.hscale = gg.scale / 2;
+}
+
+
+void zoomto(short z)
+{
+	short s0, i, FORLIM;
+
+	if (-2 > z || z > 2 || z == zoom)
+	{
+		clearfunc();
+		return;
+	}
+	s0 = gg.scale;
+	setscale(z);
+	xoff0 += (gg.xoff + across / 2) * gg.scale / s0 - across / 2 - gg.xoff;
+	yoff0 += (gg.yoff + baseline / 2) * gg.scale / s0 - baseline / 2 - gg.yoff;
+	FORLIM = gg.numpages;
+	for (i = 0; i < FORLIM; i++)
+	{
+		xoffp[i] = (xoffp[i] + across / 2) * gg.scale / s0 - across / 2;
+		yoffp[i] = (yoffp[i] + baseline / 2) * gg.scale / s0 - baseline / 2;
+	}
+	refrfunc();
+}
+
+
+void scroll()
+{
+	char ch, TEMP;
+
+	if (strcmp(gg.func, "REFR"))
+		return;
+	remcursor();
+	gg.xoff += xoff0;
+	gg.yoff += yoff0;
+	refrwindow1();
+	xoff0 = 0;
+	yoff0 = 0;
+	TEMP = nk_testkey(0);
+	if ((uchar)TEMP < 32 && ((1L << TEMP) & 0x90000500L) != 0)
+		ch = inkey2();
+	restorecursor();
+	gg.startpoint = false;
+	clearfunc();
+}
+
+
diff --git a/src/log.c b/src/log.c
index fab2e19..d48c20e 100644
--- a/src/log.c
+++ b/src/log.c
@@ -66,6 +66,7 @@
 
 #include "attrs.h"
 #include "window.h"
+#include "display.h"
 #include "label.h"
 #include "gate.h"
 #include "wire.h"
@@ -132,7 +133,6 @@ char *gatesname[maxgatesfiles];
 char *loghelpname;   ///< Name of help file
 char *lognewsname;   ///< Name of news file
 
-short zoom;   ///< Zooming level
 int ospointflag;   ///< Starting point was touched
 
 long xoff0;   ///< Good ol' XOFF
@@ -1740,15 +1740,6 @@ static void getsigname(char *name, log_sigrec **sig)
 }
 
 
-/// Set the scaling (zoom) factor.
-void setscale(short s)
-{
-	zoom = s;
-	gg.scale = zoomscales[s + 2];
-	gg.hscale = gg.scale / 2;
-}
-
-
 static void setupregion(log_regrec **r, short pagenum)
 {
 	log_regrec *r2;
@@ -1935,50 +1926,6 @@ void refrfunc()
 		clearfunc();
 }
 
-static void zoomto(short z)
-{
-	short s0, i, FORLIM;
-
-	if (-2 > z || z > 2 || z == zoom)
-	{
-		clearfunc();
-		return;
-	}
-	s0 = gg.scale;
-	setscale(z);
-	xoff0 += (gg.xoff + across / 2) * gg.scale / s0 - across / 2 - gg.xoff;
-	yoff0 += (gg.yoff + baseline / 2) * gg.scale / s0 - baseline / 2 - gg.yoff;
-	FORLIM = gg.numpages;
-	for (i = 0; i < FORLIM; i++)
-	{
-		xoffp[i] = (xoffp[i] + across / 2) * gg.scale / s0 - across / 2;
-		yoffp[i] = (yoffp[i] + baseline / 2) * gg.scale / s0 - baseline / 2;
-	}
-	refrfunc();
-}
-
-
-void scroll()
-{
-	char ch, TEMP;
-
-	if (strcmp(gg.func, "REFR"))
-		return;
-	remcursor();
-	gg.xoff += xoff0;
-	gg.yoff += yoff0;
-	refrwindow1();
-	xoff0 = 0;
-	yoff0 = 0;
-	TEMP = nk_testkey(0);
-	if ((uchar)TEMP < 32 && ((1L << TEMP) & 0x90000500L) != 0)
-		ch = inkey2();
-	restorecursor();
-	gg.startpoint = false;
-	clearfunc();
-}
-
-
 void doimmedcnffunction()
 {
 	char STR1[256], STR2[256];
-- 
GitLab