Skip to content

Commit

Permalink
split tek4010.c and tube.c, make general drawing primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
¨Rene Richarz committed Apr 12, 2019
1 parent 7bcfe85 commit b4ad52f
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 704 deletions.
72 changes: 10 additions & 62 deletions ards.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
*
*/

#define WRITE_TROUGH_INTENSITY 0.5 // green only
#define NORMAL_INTENSITY 0.8
#define CURSOR_INTENSITY 0.8
#define BRIGHT_SPOT_COLOR 1.0,1.0,1.0
#define BRIGHT_SPOT_COLOR_HALF 0.3,0.6,0.3
#define BLACK_COLOR 0.0,0.08,0.0 // effect of flood gun

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -43,50 +36,19 @@
#include <sys/time.h>

#include "main.h"
#include "tek4010.h"

extern void gtk_main_quit();
extern int globalClearPersistent;
extern int windowWidth;
extern int windowHeight;

extern int argFull;

extern int hDotsPerChar;
extern int vDotsPerChar;

extern int refresh_interval; // after this time in msec next refresh is done
extern long refreshCount;

extern int showCursor; // set of cursor is shown (not set in graphics mode)
extern int isBrightSpot; // set if there is currently a bright spot on the screen

extern double efactor;
extern int eoffx;
#include "tube.h"

static long startPaintTime;

extern long mSeconds();
extern void doCursor(cairo_t *cr2);
extern void clearPersistent(cairo_t *cr, cairo_t *cr2);
extern void clearSecond(cairo_t *cr2);
extern void clearPersistent(cairo_t *cr, cairo_t *cr2);
extern int isInput();
extern int getInputChar();

void ards_draw(cairo_t *cr, cairo_t *cr2, int first)
// draw onto the main window using cairo
// cr is used for persistent drawing, cr2 for temporary drawing

{
int ch;
char s[2];

refreshCount++; // to calculate the average refresh rate

int xlast = 0;
int ylast = 0;


if (first) {
first = 0;
int actualWidth;
Expand All @@ -110,37 +72,23 @@ void ards_draw(cairo_t *cr, cairo_t *cr2, int first)
// printf("Refresh interval: %d\n",refresh_interval);
}

startPaintTime = mSeconds(); // start to measure time for this draw operation
startPaintTime = tube_mSeconds(); // start to measure time for this draw operation

showCursor = 1;
isBrightSpot = 0;

// clear the second surface
clearSecond(cr2);
tube_clearSecond(cr2);

// clear persistent surface, if necessary
if (globalClearPersistent) {
clearPersistent(cr,cr2);
if (globaltube_clearPersistent) {
tube_clearPersistent(cr,cr2);
}

cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
cairo_set_line_width (cr, 1);
cairo_set_source_rgb(cr, 0, NORMAL_INTENSITY, 0);

cairo_select_font_face(cr, "Monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_select_font_face(cr2, "Monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);

if (argFull > 0.0) {
cairo_set_font_size(cr, (int)(efactor * 18));
cairo_set_font_size(cr2,(int)(efactor * 18));
}
else {
cairo_set_font_size(cr, 18);
cairo_set_font_size(cr2, 18);
}
tube_setupPainting(cr, cr2, "Monospace", (int)(efactor * 18));

do {
ch = getInputChar();
ch = tube_getInputChar();



Expand All @@ -151,10 +99,10 @@ void ards_draw(cairo_t *cr, cairo_t *cr2, int first)


}
while (((mSeconds() - startPaintTime) < refresh_interval));
while (((tube_mSeconds() - startPaintTime) < refresh_interval));

// display cursor

if (showCursor && (isInput() == 0)) doCursor(cr2);
if (showCursor && (tube_isInput() == 0)) tube_doCursor(cr2);

}
44 changes: 27 additions & 17 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*
*/

#define TIME_INTERVAL 10 // time interval for timer function in msec

#define GDK_DISABLE_DEPRECATION_WARNINGS

#include <stdio.h>
Expand All @@ -43,7 +45,6 @@
#include <gtk/gtk.h>

#include "main.h"
#include "tek4010.h"

extern FILE *putKeys;

Expand All @@ -57,7 +58,7 @@ extern int argARDS;
int windowWidth;
int windowHeight;

int globalClearPersistent;
int globaltube_clearPersistent;

static void do_drawing(cairo_t *, GtkWidget *);

Expand All @@ -70,21 +71,21 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,

static gboolean on_timer_event(GtkWidget *widget)
{
if (tek4010_on_timer_event())
if (tube_on_timer_event())
gtk_widget_queue_draw(widget);
return TRUE;
}

static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
if (tek4010_clicked(event->button, event->x, event->y))
if (tube_clicked(event->button, event->x, event->y))
gtk_widget_queue_draw(widget);
return TRUE;
}

static void on_quit_event()
{
tek4010_quit();
tube_quit();
gtk_main_quit();
exit(0);
}
Expand Down Expand Up @@ -130,7 +131,7 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da
(event->keyval == 0xFF55) || // "page up" key
(event->keyval == 0xFF56)) // "page down" key
{
globalClearPersistent = 1;
globaltube_clearPersistent = 1;
gtk_widget_queue_draw(widget);
return;
}
Expand All @@ -141,15 +142,15 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da
else if (event->state & GDK_CONTROL_MASK) {
if ((event->keyval == 0xFF51) || // "<ctrl>left arrow" key
(event->keyval == 0xFF52)) { // "<ctrl>up arrow" key
globalClearPersistent = 1;
globaltube_clearPersistent = 1;
gtk_widget_queue_draw(widget);
return;
}
else if (event->keyval == 0x0077) { // "<ctrl>w" makes screendump
system("scrot --focussed");
return;
}
else if (event->keyval == 0x0071) { // "<ctrl>q" quits tek4010
else if (event->keyval == 0071) { // "<ctrl>q" quits tek4010
on_quit_event();
return;
}
Expand All @@ -174,15 +175,24 @@ int main (int argc, char *argv[])
GtkWidget *darea;
GtkWidget *window;

int askWindowWidth = A_WINDOW_WIDTH;
int askWindowHeight = A_WINDOW_HEIGHT;
int askWindowWidth;
int askWindowHeight;

tube_init(argc, argv);

tek4010_init(argc, argv);
if (argARDS) {
askWindowWidth = 1080;
askWindowHeight = 1414;
}

if (argFull) {
else if (argFull) {
askWindowWidth = 4096;
askWindowHeight = 3072;
}
else {
askWindowWidth = 1024;
askWindowHeight = 780;
}

gtk_init(&argc, &argv);

Expand All @@ -205,7 +215,7 @@ int main (int argc, char *argv[])
int screenHeight = gdk_screen_get_height(screen);
printf("Screen dimensions: %d x %d\n", screenWidth, screenHeight);

if (argFull) {
if (argFull && !argARDS) {
// DISPLAY UNDECORATED FULL SCREEN WINDOW
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
gtk_window_fullscreen(GTK_WINDOW(window));
Expand All @@ -216,6 +226,10 @@ int main (int argc, char *argv[])

else {
// DISPLAY DECORATED WINDOW
if (argARDS && (askWindowHeight > (screenHeight - 32))) {
askWindowWidth = 540;
askWindowHeight = 707;
}
gtk_window_set_decorated(GTK_WINDOW(window), TRUE);
gtk_window_set_default_size(GTK_WINDOW(window), askWindowWidth, askWindowHeight);
windowWidth = askWindowWidth;
Expand All @@ -234,10 +248,6 @@ int main (int argc, char *argv[])

gtk_window_set_title(GTK_WINDOW(window), windowName);

if (strlen(ICON_NAME) > 0) {
gtk_window_set_icon_from_file(GTK_WINDOW(window), ICON_NAME, NULL);
}

gtk_widget_show_all(window);

gtk_main();
Expand Down
8 changes: 4 additions & 4 deletions main.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#include <cairo.h>

void tek4010_init(int argc, char* argv[]);
void tube_init(int argc, char* argv[]);
void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first);
int tek4010_on_timer_event();
int tek4010_clicked(int button, int x, int y);
void tek4010_quit();
int tube_on_timer_event();
int tube_clicked(int button, int x, int y);
void tube_quit();

void ards_draw(cairo_t *cr, cairo_t *cr2, int first);

Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ CFLAGS = -std=c99 `pkg-config --cflags gtk+-3.0`

all: tek4010

tek4010: main.c main.h tek4010.c tek4010.h ards.c
gcc -o tek4010 main.c tek4010.c ards.c $(LIBS) $(CFLAGS)
tek4010: main.c main.h tube.c tube.h tek4010.c ards.c
gcc -o tek4010 main.c tube.c tek4010.c ards.c $(LIBS) $(CFLAGS)

install: tek4010
./install
Binary file modified tek4010
Binary file not shown.
Loading

0 comments on commit b4ad52f

Please sign in to comment.