modified: src/color.c
This commit is contained in:
parent
54b4a94f20
commit
c1ba91a6e8
39
src/color.c
39
src/color.c
@ -9,6 +9,7 @@
|
|||||||
#define PROMPT_BUFSIZE 32
|
#define PROMPT_BUFSIZE 32
|
||||||
|
|
||||||
#define X_ENTER_KEY 36
|
#define X_ENTER_KEY 36
|
||||||
|
#define X_BACKSPACE 22
|
||||||
|
|
||||||
#define X_Q_KEY 24
|
#define X_Q_KEY 24
|
||||||
#define X_W_KEY 25
|
#define X_W_KEY 25
|
||||||
@ -19,6 +20,9 @@
|
|||||||
#define X_D_KEY 40
|
#define X_D_KEY 40
|
||||||
|
|
||||||
|
|
||||||
|
#define TEXT_CORNER_OFFSET 100
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
@ -38,10 +42,11 @@ int main(void) {
|
|||||||
|
|
||||||
int text_buffer_space;
|
int text_buffer_space;
|
||||||
unsigned int channel_step;
|
unsigned int channel_step;
|
||||||
int is_prompt = 0;
|
int is_prompt = 1;
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int textpos_y;
|
||||||
|
|
||||||
unsigned int winsize_x;
|
|
||||||
unsigned int winsize_y;
|
|
||||||
|
|
||||||
XFontStruct* font;
|
XFontStruct* font;
|
||||||
|
|
||||||
@ -99,22 +104,22 @@ int main(void) {
|
|||||||
text_prompt_gc = XCreateGC(display, window, GCForeground | GCLineWidth, &text_prompt_formatting);
|
text_prompt_gc = XCreateGC(display, window, GCForeground | GCLineWidth, &text_prompt_formatting);
|
||||||
font = XLoadQueryFont(display, "-*-helvetica-medium-r-normal-*-20-*");
|
font = XLoadQueryFont(display, "-*-helvetica-medium-r-normal-*-20-*");
|
||||||
XSetFont(display, text_prompt_gc, font->fid);
|
XSetFont(display, text_prompt_gc, font->fid);
|
||||||
|
|
||||||
|
XGetWindowAttributes(display, window, &win_info);
|
||||||
|
textpos_y = win_info.height - TEXT_CORNER_OFFSET;
|
||||||
|
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
XNextEvent(display, &event);
|
XNextEvent(display, &event);
|
||||||
XGetWindowAttributes(display, window, &win_info);
|
|
||||||
winsize_x = win_info.width;
|
|
||||||
winsize_y = win_info.height;
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
printf("%i\n", event.xkey.keycode);
|
printf("-->%i\n", event.xkey.keycode);
|
||||||
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;
|
||||||
|
|
||||||
if(event.xkey.keycode == X_ENTER_KEY) {
|
if(event.xkey.keycode == X_BACKSPACE) {
|
||||||
if(text_buffer_space < PROMPT_BUFSIZE) {
|
if(text_buffer_space < PROMPT_BUFSIZE) {
|
||||||
text_prompt.nchars--;
|
text_prompt.nchars--;
|
||||||
}
|
}
|
||||||
@ -122,6 +127,7 @@ int main(void) {
|
|||||||
else if(text_buffer_space > 0) {
|
else 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);
|
||||||
}
|
}
|
||||||
|
XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("%i\n", win_info.depth);
|
printf("%i\n", win_info.depth);
|
||||||
@ -129,12 +135,6 @@ int main(void) {
|
|||||||
case X_ENTER_KEY:
|
case X_ENTER_KEY:
|
||||||
break;
|
break;
|
||||||
case X_Q_KEY:
|
case X_Q_KEY:
|
||||||
printf("Before: %i\n", background_color.red);
|
|
||||||
XFreeColors(display, colormap, &background_color.pixel, 1, NULL);
|
|
||||||
printf("Step: %i\n", channel_step);
|
|
||||||
background_color.red += channel_step; //TODO: change me to depth
|
|
||||||
printf("After: %i\n", background_color.red);
|
|
||||||
XAllocColor(display, colormap, &background_color);
|
|
||||||
break;
|
break;
|
||||||
case X_W_KEY:
|
case X_W_KEY:
|
||||||
break;
|
break;
|
||||||
@ -153,15 +153,18 @@ int main(void) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
XDrawText(display, window, text_prompt_gc, 10, winsize_y - 10, &text_prompt, 1);
|
XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1);
|
||||||
break;
|
break;
|
||||||
case Expose:
|
case Expose:
|
||||||
XDrawText(display, window, text_prompt_gc, 10, winsize_y - 10, &text_prompt, 1);
|
XGetWindowAttributes(display, window, &win_info);
|
||||||
printf("exposed\n");
|
textpos_y = win_info.height - TEXT_CORNER_OFFSET;
|
||||||
|
XDrawText(display, window, text_prompt_gc, TEXT_CORNER_OFFSET, textpos_y, &text_prompt, 1);
|
||||||
|
printf("%i\n", textpos_y);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
printf("testing\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user