summaryrefslogtreecommitdiff
path: root/src/color.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/color.c')
-rw-r--r--src/color.c110
1 files changed, 74 insertions, 36 deletions
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;