modified: src/color.c

modified:   src/color.h
This commit is contained in:
Brett Weiland 2020-08-06 21:58:14 -05:00
parent 40ac18e27b
commit b6c997706d
3 changed files with 46 additions and 28 deletions

BIN
bin/color

Binary file not shown.

View File

@ -12,43 +12,43 @@
int add_color(update_info *color, int key) { int add_color(update_info *color, int key) {
XFreeColors(color->display, color->colormap, &color->background.pixel, 1, 0); XFreeColors(color->display, color->colormap, &color->background->pixel, 1, 0);
switch(key){ switch(key){
case X_Q_KEY: case X_Q_KEY:
color->background.red += color->channel_step; color->background->red += color->channel_step;
break; break;
case X_W_KEY: case X_W_KEY:
color->background.green += color->channel_step; color->background->green += color->channel_step;
printf("%i\n", color->background.green);
break; break;
case X_E_KEY: case X_E_KEY:
color->background.blue += color->channel_step; color->background->blue += color->channel_step;
break; break;
case X_A_KEY: case X_A_KEY:
color->background.red -= color->channel_step; color->background->red -= color->channel_step;
break; break;
case X_S_KEY: case X_S_KEY:
color->background.green -= color->channel_step; color->background->green -= color->channel_step;
break; break;
case X_D_KEY: case X_D_KEY:
color->background.blue -= color->channel_step; color->background->blue -= color->channel_step;
break; break;
default: default:
printf("what the actual fuck is wrong with your program you cunt\n"); printf("what the actual fuck is wrong with your program you cunt\n");
break; break;
} }
XAllocColor(color->display, color->colormap, &color->background); XAllocColor(color->display, color->colormap, color->background);
printf("Pixel:\t%x\nR:\t%x\nG:\t%x\nB:\t%x\n", color->background->pixel, color->background->red, color->background->green, color->background->blue);
} }
int redraw_display(update_info *display_summary, XTextItem *text_prompt, GC *gc, unsigned int textpos_y) { void redraw_display(update_info *display_summary, XTextItem *text_prompt, GC *gc, unsigned int textpos_y) {
XFreeColors(display_summary->display, display_summary->colormap, &display_summary->foreground.pixel, 1, 0); XFreeColors(display_summary->display, display_summary->colormap, &display_summary->foreground.pixel, 1, 0);
display_summary->foreground.red = 0xffff - display_summary->background.red; display_summary->foreground.red = 0xffff - display_summary->background->red;
display_summary->foreground.green = 0xffff - display_summary->background.green; display_summary->foreground.green = 0xffff - display_summary->background->green;
display_summary->foreground.blue = 0xffff - display_summary->background.blue; display_summary->foreground.blue = 0xffff - display_summary->background->blue;
XAllocColor(display_summary->display, display_summary->colormap, &display_summary->foreground); XAllocColor(display_summary->display, display_summary->colormap, &display_summary->foreground);
XClearWindow(display_summary->display, display_summary->window); XClearWindow(display_summary->display, display_summary->window);
printf("%i\n", display_summary->background.pixel); XSetWindowBackground(display_summary->display, display_summary->window, display_summary->background->pixel);
XSetWindowBackground(display_summary->display, display_summary->window, display_summary->background.pixel);
XSetForeground(display_summary->display, *gc, display_summary->foreground.pixel); XSetForeground(display_summary->display, *gc, display_summary->foreground.pixel);
XDrawText(display_summary->display, display_summary->window, *gc, TEXT_CORNER_OFFSET, textpos_y, text_prompt, 1); XDrawText(display_summary->display, display_summary->window, *gc, TEXT_CORNER_OFFSET, textpos_y, text_prompt, 1);
@ -56,7 +56,9 @@ int redraw_display(update_info *display_summary, XTextItem *text_prompt, GC *gc,
int main(void) { int main(void) {
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."; char text_prompt_buffer[PROMPT_BUFSIZE] = "Q/W/E, A/S/D for RGB channels. [Enter] begins rgb prompt, [Space] for 24 bit integers, [Enter] for hex. Seperate channels with \"/\"";
char rgb_split_seperations[3][3];
Display *display; Display *display;
Window window; Window window;
@ -77,7 +79,6 @@ int main(void) {
unsigned int textpos_y; unsigned int textpos_y;
XFontStruct* font; XFontStruct* font;
XWindowAttributes win_info; XWindowAttributes win_info;
@ -104,6 +105,13 @@ int main(void) {
XAllocColor(display, colormap, &background_color); XAllocColor(display, colormap, &background_color);
XAllocColor(display, colormap, &foreground_color); XAllocColor(display, colormap, &foreground_color);
XFreeColors(display, colormap, &background_color.pixel, 1, 0);
XParseColor(display, colormap, "rgb:0/0/ff", &background_color);
XAllocColor(display, colormap, &background_color);
XFreeColors(display, colormap, &background_color.pixel, 1, 0);
XAllocColor(display, colormap, &background_color);
@ -142,7 +150,7 @@ int main(void) {
.window = window, .window = window,
.display = display, .display = display,
.colormap = colormap, .colormap = colormap,
.background = background_color, .background = &background_color,
.foreground = foreground_color, .foreground = foreground_color,
.channel_step = color_step .channel_step = color_step
}; };
@ -154,6 +162,7 @@ int main(void) {
if(is_prompt) { if(is_prompt) {
XClearWindow(display, window); XClearWindow(display, window);
text_buffer_space = PROMPT_BUFSIZE - text_prompt.nchars; text_buffer_space = PROMPT_BUFSIZE - text_prompt.nchars;
printf("%i\n", event.xkey.keycode);
switch(event.xkey.keycode) { switch(event.xkey.keycode) {
case X_BACKSPACE: case X_BACKSPACE:
if(text_buffer_space < PROMPT_BUFSIZE) { if(text_buffer_space < PROMPT_BUFSIZE) {
@ -166,14 +175,21 @@ int main(void) {
break; break;
case X_ENTER_KEY: case X_ENTER_KEY:
text_prompt_buffer[text_prompt.nchars + 1] = '\0'; text_prompt_buffer[text_prompt.nchars + 1] = '\0';
XFreeColors(display, colormap, background_color.pixel, 1, NULL); XFreeColors(display, colormap, &background_color.pixel, 1, 0);
XParseColor(display, colormap, text_prompt_buffer, &background_color); XParseColor(display, colormap, text_prompt_buffer, &background_color);
background_color.red = 60000;
XAllocColor(display, colormap, &background_color); XAllocColor(display, colormap, &background_color);
is_prompt = 0; is_prompt = 0;
text_prompt.nchars = 0; text_prompt.nchars = 0;
redraw_display(&display_summary, &text_prompt, &text_prompt_gc, textpos_y); redraw_display(&display_summary, &text_prompt, &text_prompt_gc, textpos_y);
break; break;
case X_SHIFT_KEY:
XFreeColors(display, colormap, &background_color.pixel, 1, 0);
str
background_color.red =
background_color.green =
background_color.blue =
printf("Pixel:\t%x\nR:\t%x\nG:\t%x\nB:\t%x\n", background_color.pixel, background_color.red, background_color.green, background_color.blue);
default: default:
if(text_buffer_space > 0) { if(text_buffer_space > 0) {
text_prompt.nchars += XLookupString(&event.xkey, text_prompt_buffer + text_prompt.nchars, text_buffer_space, NULL, NULL); text_prompt.nchars += XLookupString(&event.xkey, text_prompt_buffer + text_prompt.nchars, text_buffer_space, NULL, NULL);
@ -189,16 +205,17 @@ int main(void) {
text_prompt.nchars = 4; text_prompt.nchars = 4;
strcpy(text_prompt_buffer, "rgb:"); strcpy(text_prompt_buffer, "rgb:");
break; break;
case X_Q_KEY: //if anyone is reading this, on a scale from 1-10, case X_ESCAPE_KEY:
case X_W_KEY: //just how ugly is this? text_prompt.nchars = 0;
case X_E_KEY: //I don't know why, but it feels gross. break;
case X_A_KEY: //to be fair, most of this code is just for me. case X_Q_KEY: // if anyone is reading this, on a scale from 1-10,
case X_S_KEY: //otherwise, it'd be way cleaner. 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: case X_D_KEY:
add_color(&display_summary, event.xkey.keycode); add_color(&display_summary, event.xkey.keycode);
break; break;
case X_ESCAPE_KEY:
text_prompt.nchars = 0;
default: default:
break; break;
} }

View File

@ -3,6 +3,7 @@
#define X_ENTER_KEY 36 #define X_ENTER_KEY 36
#define X_BACKSPACE 22 #define X_BACKSPACE 22
#define X_ESCAPE_KEY 9 #define X_ESCAPE_KEY 9
#define X_SHIFT_KEY 36
#define X_Q_KEY 24 #define X_Q_KEY 24
#define X_W_KEY 25 #define X_W_KEY 25
@ -18,7 +19,7 @@ typedef struct {
Window window; Window window;
Display *display; Display *display;
Colormap colormap; Colormap colormap;
XColor background; XColor *background;
XColor foreground; XColor foreground;
unsigned int channel_step; unsigned int channel_step;
} update_info; } update_info;