summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Weiland <techcrazybsw@gmail.com>2020-07-26 12:46:01 -0500
committerBrett Weiland <techcrazybsw@gmail.com>2020-07-26 12:46:01 -0500
commitee39e60edd3348f97abb67af7c84b459a49eb4ed (patch)
tree532cfad5ca832a79a21728fd54db2d92fe589ab5
parentdd3d885a31eefd44f0026d726372f53781947927 (diff)
new file: bin/color
modified: src/color.c new file: src/color.h
-rwxr-xr-xbin/colorbin0 -> 17656 bytes
-rw-r--r--src/color.c110
-rw-r--r--src/color.h24
3 files changed, 98 insertions, 36 deletions
diff --git a/bin/color b/bin/color
new file mode 100755
index 0000000..3a492ae
--- /dev/null
+++ b/bin/color
Binary files differ
diff --git a/src/color.c b/src/color.c
index 8ff1612..565f85a 100644
--- a/src/color.c
+++ b/src/color.c
@@ -5,19 +5,59 @@
#include <string.h>
#include <errno.h>
#include <math.h>
+#include <signal.h>
#include "color.h"
-int add_color(color_info color) {
-
+int add_color(update_info *color, int key) {
+ XFreeColors(color->display, color->colormap, &color->background.pixel, 1, 0);
+ XFreeColors(color->display, color->colormap, &color->foreground.pixel, 1, 0);
+ printf("%i\n", color->channel_step);
+ switch(key){
+ case X_Q_KEY:
+ color->background.red += color->channel_step;
+ break;
+ case X_W_KEY:
+ color->background.green += color->channel_step;
+ printf("%i\n", color->background.green);
+ break;
+ case X_E_KEY:
+ color->background.blue += color->channel_step;
+ break;
+ case X_A_KEY:
+ color->background.red -= color->channel_step;
+ break;
+ case X_S_KEY:
+ color->background.green -= color->channel_step;
+ break;
+ case X_D_KEY:
+ color->background.blue -= color->channel_step;
+ break;
+ default:
+ printf("what the actual fuck is wrong with your program you cunt\n");
+ break;
+ }
+ color->foreground.red = 0xffff - color->background.red;
+ color->foreground.green = 0xffff - color->background.green;
+ color->foreground.blue = 0xffff - color->background.blue;
+ XAllocColor(color->display, color->colormap, &color->foreground);
+ XAllocColor(color->display, color->colormap, &color->background);
}
+int redraw_display(update_info *display_summary, XTextItem *text_prompt, GC *gc, unsigned int textpos_y) {
+ XClearWindow(display_summary->display, display_summary->window);
+ XSetWindowBackground(display_summary->display, display_summary->window, display_summary->background.pixel);
+ XSetForeground(display_summary->display, *gc, display_summary->foreground.pixel);
+ printf("%i\n", display_summary->foreground.red);
+ XDrawText(display_summary->display, display_summary->window, *gc, TEXT_CORNER_OFFSET, textpos_y, text_prompt, 1);
+
+}
int main(void) {
- char text_prompt_buffer[PROMPT_BUFSIZE] = "";
+ char text_prompt_buffer[PROMPT_BUFSIZE] = "Q/W/E increases R/G/B. A/S/D decreases R/G/B. Enter allows exact value. Press Escape to dismiss.";
Display *display;
Window window;
@@ -53,9 +93,9 @@ int main(void) {
//background colormap
colormap = DefaultColormap(display, screen);
- background_color.red = 1000;
+ background_color.red = 0;
background_color.green = 0;
- background_color.blue = 60000;
+ background_color.blue = 0;
//text colormap
foreground_color.red = 0xffff - background_color.red;
@@ -71,7 +111,7 @@ int main(void) {
window = XCreateSimpleWindow(display, RootWindow(display, screen),
10, 10,
- 100, 100,
+ 1920, 1080,
0,
background_color.pixel,
background_color.pixel); //last arg is color
@@ -79,7 +119,8 @@ int main(void) {
XMapWindow(display, window);
XSelectInput(display, window, KeyPressMask | ExposureMask);
XGetWindowAttributes(display, window, &win_info);
- color_step = 0xffff / pow(2, (win_info.depth / 3)) ;
+ //TODO: this math is techincly one off in very, very specific scenarios
+ color_step = 0xffff / pow(2, (win_info.depth / 3)) + 0.5;
@@ -112,18 +153,26 @@ int main(void) {
XNextEvent(display, &event);
switch (event.type) {
case KeyPress:
+ printf("%i\n", event.xkey.keycode);
if(is_prompt) {
XClearWindow(display, window);
text_buffer_space = PROMPT_BUFSIZE - text_prompt.nchars;
-
- if(event.xkey.keycode == X_BACKSPACE) {
- if(text_buffer_space < PROMPT_BUFSIZE) {
- text_prompt.nchars--;
- }
- }
- else if(text_buffer_space > 0) {
- text_prompt.nchars += XLookupString(&event.xkey, text_prompt_buffer + text_prompt.nchars, text_buffer_space, NULL, NULL);
+ switch(event.xkey.keycode) {
+ case X_BACKSPACE:
+ if(text_buffer_space < PROMPT_BUFSIZE) {
+ text_prompt.nchars--;
+ }
+ break;
+ case X_ESCAPE_KEY:
+ text_prompt.nchars = 0;
+ is_prompt = 0;
+ break;
+ default:
+ if(text_buffer_space > 0) {
+ text_prompt.nchars += XLookupString(&event.xkey, text_prompt_buffer + text_prompt.nchars, text_buffer_space, NULL, NULL);
+ }
+ break;
}
XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1);
}
@@ -131,31 +180,20 @@ int main(void) {
switch(event.xkey.keycode) {
case X_ENTER_KEY:
break;
- case X_Q_KEY:
- printf("%i\n", channel_step);
- XFreeColors(display, colormap, &background_color.pixel, 1, 0);
- XFreeColors(display, colormap, &foreground_color.pixel, 1, 0);
- background_color.red += channel_step;
- foreground_color.red = 0xffff - background_color.red; //we could just sub channel_step, but eh. i donno.
- printf("----%i\n", background_color.red);
- XAllocColor(display, colormap, &foreground_color);
- XAllocColor(display, colormap, &background_color);
- XClearWindow(display, window);
- XSetWindowBackground(display, window, background_color.pixel);
- break;
- case X_W_KEY:
- break;
- case X_E_KEY:
- break;
- case X_A_KEY:
- break;
- case X_S_KEY:
- break;
+ case X_Q_KEY: //if anyone is reading this, on a scale from 1-10,
+ case X_W_KEY: //just how ugly is this?
+ case X_E_KEY: //I don't know why, but it feels gross.
+ case X_A_KEY: //to be fair, most of this code is just for me.
+ case X_S_KEY: //otherwise, it'd be way cleaner.
case X_D_KEY:
+ add_color(&display_summary, event.xkey.keycode);
break;
+ case X_ESCAPE_KEY:
+ text_prompt.nchars = 0;
default:
break;
}
+ redraw_display(&display_summary, &text_prompt, &text_prompt_gc, textpos_y);
}
@@ -165,7 +203,7 @@ int main(void) {
case Expose:
XGetWindowAttributes(display, window, &win_info);
textpos_y = win_info.height - TEXT_CORNER_OFFSET;
- XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1);
+ redraw_display(&display_summary, &text_prompt, &text_prompt_gc, textpos_y);
break;
default:
break;
diff --git a/src/color.h b/src/color.h
new file mode 100644
index 0000000..ac81a01
--- /dev/null
+++ b/src/color.h
@@ -0,0 +1,24 @@
+#define PROMPT_BUFSIZE 256
+
+#define X_ENTER_KEY 36
+#define X_BACKSPACE 22
+#define X_ESCAPE_KEY 9
+
+#define X_Q_KEY 24
+#define X_W_KEY 25
+#define X_E_KEY 26
+
+#define X_A_KEY 38
+#define X_S_KEY 39
+#define X_D_KEY 40
+
+#define TEXT_CORNER_OFFSET 25
+
+typedef struct {
+ Window window;
+ Display *display;
+ Colormap colormap;
+ XColor background;
+ XColor foreground;
+ unsigned int channel_step;
+} update_info;