|
|
452870 |
|
|
|
452870 |
#include "app.h"
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
int graphInit(Graph *g, App *app) {
|
|
|
452870 |
LOGDBG("graph: init");
|
|
|
452870 |
|
|
|
452870 |
const uint16_t F = 65535; // full
|
|
|
452870 |
const uint16_t H = 32768; // half
|
|
|
452870 |
const uint16_t Q = 16384; // quart
|
|
|
452870 |
const uint16_t colorsRgb[GS_COUNT*2][3] = { // background, foreground
|
|
|
452870 |
{ 0, 0, Q }, { 0, 0, Q }, // window
|
|
|
452870 |
{ 0, 0, H }, { 0, 0, H }, // inactive button
|
|
|
452870 |
{ 0, 0, F }, { 0, 0, F }, // active button
|
|
|
452870 |
{ 0, 0, H }, { F, F, 0 }, // inactive text
|
|
|
452870 |
{ 0, 0, F }, { F, F, 0 } }; // active text
|
|
|
452870 |
|
|
|
452870 |
// create palette
|
|
|
452870 |
g->app = app;
|
|
|
452870 |
g->cm = xcb_generate_id(g->app->xcb);
|
|
|
452870 |
xcb_create_colormap(g->app->xcb, XCB_COLORMAP_ALLOC_NONE, g->cm, g->app->win, g->app->screen->root_visual);
|
|
|
452870 |
|
|
|
452870 |
// encqueue colors allocarion requests
|
|
|
452870 |
xcb_alloc_color_cookie_t cookies[GS_COUNT*2];
|
|
|
452870 |
for(int i = 0; i < GS_COUNT*2; ++i)
|
|
|
452870 |
cookies[i] = xcb_alloc_color(g->app->xcb, g->cm, colorsRgb[i][0], colorsRgb[i][1], colorsRgb[i][2]);
|
|
|
452870 |
|
|
|
452870 |
// take color allocation replies (take color indices)
|
|
|
452870 |
uint32_t colors[GS_COUNT*2];
|
|
|
452870 |
for(int i = 0; i < GS_COUNT*2; ++i) {
|
|
|
452870 |
xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(g->app->xcb, cookies[i], NULL);
|
|
|
452870 |
colors[i] = reply->pixel;
|
|
|
452870 |
free(reply);
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
// associate palette with the window
|
|
|
452870 |
xcb_change_window_attributes(g->app->xcb, g->app->win, XCB_CW_COLORMAP, &g->cm);
|
|
|
452870 |
|
|
|
452870 |
// create contexts
|
|
|
452870 |
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
|
|
452870 |
uint32_t values[3] = {0, 0, 0};
|
|
|
452870 |
for(int i = 0; i < GS_COUNT; ++i) {
|
|
|
452870 |
values[0] = colors[i*2 + 1]; // foreground
|
|
|
452870 |
values[1] = colors[i*2]; // background
|
|
|
452870 |
g->gc[i] = xcb_generate_id(g->app->xcb);
|
|
|
452870 |
xcb_create_gc(g->app->xcb, g->gc[i], g->app->win, mask, values);
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
return 1;
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
void graphDeinit(Graph *g) {
|
|
|
452870 |
LOGDBG("graph: deinit");
|
|
|
452870 |
for(int i = 0; i < GS_COUNT; ++i)
|
|
|
452870 |
xcb_free_gc(g->app->xcb, g->gc[i]);
|
|
|
452870 |
xcb_change_window_attributes(g->app->xcb, g->app->win, XCB_CW_COLORMAP, &g->app->screen->default_colormap);
|
|
|
452870 |
xcb_free_colormap(g->app->xcb, g->cm);
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
void graphResize(Graph *g)
|
|
|
452870 |
{ }
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
void graphDrawBackgound(Graph *g, int x, int y, int w, int h) {
|
|
|
452870 |
xcb_rectangle_t r = {x, y, w, h};
|
|
|
452870 |
xcb_poly_fill_rectangle(g->app->xcb, g->app->win, g->gc[GS_WINDOW], 1, &r);
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
void graphDrawButton(Graph *g, int x, int y, int w, int h, int active) {
|
|
|
452870 |
GraphStyle s = active ? GS_BUTTON_ACTIVE : GS_BUTTON_INACTIVE;
|
|
|
452870 |
xcb_rectangle_t r = {x, y, w, h};
|
|
|
452870 |
xcb_poly_fill_rectangle(g->app->xcb, g->app->win, g->gc[s], 1, &r);
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
int textLayoutInit(TextLayout *tl, Graph *g, int cx, int cy, const char *text) {
|
|
|
452870 |
tl->g = g;
|
|
|
452870 |
tl->text = text;
|
|
|
452870 |
return 1;
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
void textLayoutDeinit(TextLayout *tl)
|
|
|
452870 |
{ }
|
|
|
452870 |
|
|
|
452870 |
void textLayoutDraw(TextLayout *tl, int active)
|
|
|
452870 |
{ }
|