diff --git a/01_git/Makefile.UNIX b/01_git/Makefile.UNIX index 72a051909afea6513bf70b9af163173d68e27b7e..fe9bb394de19d58d65039edefb3e51ec30295819 100644 --- a/01_git/Makefile.UNIX +++ b/01_git/Makefile.UNIX @@ -17,7 +17,7 @@ COPTS = -O3 -std=c99 -pipe -Wall -DNDEBUG -D_BSD_SOURCE -D_XOPEN_SOURCE=600 -Wer CFLAGS = $(COPTS) $(COMPILE_FLAGS) $(C_INCLUDE) -OBJ = astime.o astime_x.o safecopy.o x_color.o sunriset.o +OBJ = astime.o astime_x.o safecopy.o x_color.o x_primitives.o sunriset.o all: astime @echo Ready. diff --git a/01_git/Makefile.in b/01_git/Makefile.in index 04451a2ae8297c717f1db3fa1e027a5ee3e4d8cb..7d8020eff7c24b2eb829ecc45332ac9d3d8dfe91 100644 --- a/01_git/Makefile.in +++ b/01_git/Makefile.in @@ -2,7 +2,7 @@ CFLAGS+=-g -OBJS = astime.o astime_x.o safecopy.o x_color.o sunriset.o +OBJS = astime.o astime_x.o safecopy.o x_color.o x_primitives.o sunriset.o PROG = astime diff --git a/01_git/astime_x.c b/01_git/astime_x.c index 465c1b0c7950e91358d06ff52c8e31aef85c870b..978a8541ba3395cc3d6e75af5fcbdcbd2ec1c7b9 100644 --- a/01_git/astime_x.c +++ b/01_git/astime_x.c @@ -28,9 +28,10 @@ #include <X11/Xatom.h> #include "sunriset.h" - #include "x_color.h" +#include "x_primitives.h" #include "state.h" + struct astime_state state; #include "dof.xpm" @@ -135,54 +136,8 @@ void initialize(int argc, char **argv, int iconic, int pushed_in, int no_border); -int DrawCenteredArc(Display *display, - Drawable d, - GC gc, - int x, - int y, - unsigned int width, - unsigned int height, - int angle1, - int angle2); -int FillCenteredArc(Display *display, - Drawable d, - GC gc, - int x, - int y, - unsigned int width, - unsigned int height, - int angle1, - int angle2); /* functions */ -int DrawCenteredArc(Display *display, - Drawable d, - GC gc, - int x, - int y, - unsigned int width, - unsigned int height, - int angle1, - int angle2) -{ - return XDrawArc(display, d, gc, - x - width, y - height, 2 * width, 2 * height, angle1, angle2); -} -int FillCenteredArc(Display *display, - Drawable d, - GC gc, - int x, - int y, - unsigned int width, - unsigned int height, - int angle1, - int angle2) -{ - return XFillArc(display, d, gc, - x - width, y - height, 2 * width, 2 * height, angle1, angle2); -} - - void draw_sunriset(Window win, struct tm *local_time, double lon, @@ -428,6 +383,9 @@ void draw_window(Window win) state.lon, state.lat, civil_pix, SUNRISET_SIZE, CIVIL_TWILIGHT); draw_sunriset(win, loc_time, state.lon, state.lat, day_pix, SUNRISET_SIZE, SUNRISESET); + XSetForeground(mainDisplay, mainGC, pix[0]); + /*DrawTriangle(mainDisplay, win, mainGC, center.x, center.y, 300, 300, + loc_time->tm_sec * 6 * 64);*/ } /* draw filled polygonal hands */ for (i = 2; i >= 0; i--) { diff --git a/01_git/x_primitives.c b/01_git/x_primitives.c new file mode 100644 index 0000000000000000000000000000000000000000..1e59f31ed742852a640261932d99be96e47ffaa9 --- /dev/null +++ b/01_git/x_primitives.c @@ -0,0 +1,77 @@ +/* + * This software is distributed under GPL. For details see LICENSE file. + */ + +#include <X11/Xlib.h> +#include <math.h> +#include <stdio.h> +#include "x_primitives.h" + +/* + * XPoints *points: array of four points + */ + +void CalculateTriangleCoordinates(XPoint *points, short x, short y, + unsigned short width, unsigned short height, short angle); + +void RotateCoordinates(short *x, short *y, short center_x, short center_y, + short angle); +void RotateCoordinates(short *x, short *y, short center_x, short center_y, + short angle) +{ + double r_angle = (angle / 64) % 360 * (M_PI / 180.0); + int x_coord = x[0], y_coord = y[0]; + x[0] = center_x + cos(r_angle) * (x_coord - center_x) + - sin(r_angle) * (y_coord - center_y); + y[0] = center_y + sin(r_angle) * (x_coord - center_x) + - cos(r_angle) * (y_coord - center_y); + printf("x = %d, y = %d\n", x_coord, y_coord); +} +void CalculateTriangleCoordinates(XPoint *points, short x, short y, + unsigned short width, unsigned short height, short angle) +{ + points[0].x = x - width / 2; + points[0].y = y; + points[1].x = x + width / 2; + points[1].y = y; + points[2].x = x; + points[2].y = y + height; + points[3].x = points[0].x; + points[3].y = points[0].y; + { + int i; + for (i = 0; i < 4; i++) { + RotateCoordinates(&points[i].x, &points[i].y, x, y, angle); + } + } +} +int DrawTriangle(Display *display, Drawable d, GC gc, + short x, short y, unsigned short width, unsigned short height, + short angle) +{ + XPoint points[4]; + CalculateTriangleCoordinates(points, x, y, width, height, angle); + return XDrawLines(display, d, gc, points, 4, CoordModeOrigin); +} +int FillTriangle(Display *display, Drawable d, GC gc, + short x, short y, unsigned short width, unsigned short height, + short angle) +{ + XPoint points[4]; + CalculateTriangleCoordinates(points, x, y, width, height, angle); + return XFillPolygon(display, d, gc, points, 4, Convex, CoordModeOrigin); +} +int DrawCenteredArc(Display *display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int angle1, int angle2) +{ + return XDrawArc(display, d, gc, + x - width, y - height, 2 * width, 2 * height, angle1, angle2); +} +int FillCenteredArc(Display *display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int angle1, int angle2) +{ + return XFillArc(display, d, gc, + x - width, y - height, 2 * width, 2 * height, angle1, angle2); +} diff --git a/01_git/x_primitives.h b/01_git/x_primitives.h new file mode 100644 index 0000000000000000000000000000000000000000..5da7739dc85262352840c0ea565a75a6ffdf7885 --- /dev/null +++ b/01_git/x_primitives.h @@ -0,0 +1,16 @@ +/* + * This software is distributed under GPL. For details see LICENSE file. + */ + +int DrawTriangle(Display *display, Drawable d, GC gc, + short x, short y, unsigned short width, unsigned short height, + short angle); +int FillTriangle(Display *display, Drawable d, GC gc, + short x, short y, unsigned short width, unsigned short height, + short angle); +int DrawCenteredArc(Display *display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int angle1, int angle2); +int FillCenteredArc(Display *display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int angle1, int angle2);