void taskbar_start (s_window_t *window, s_config_t *cfg) { int x; s_timer_t *timer; s_handler_t *hndl; tbar_data_t *tbar_data; s_window_set_coor(window, WINDOW_TYPE_NOFORM, 0, window->surface->height - 30, window->surface->width, 30); s_window_set_alwaysontop(window, 1); s_window_set_resizeable(window, 0); s_window_atevent(window, taskbar_atevent); s_window_atexit(window, taskbar_atexit); s_free(window->surface->vbuf); window->surface->width = window->surface->buf->w; window->surface->height = window->surface->buf->h; window->surface->vbuf = (unsigned char *) s_malloc(window->surface->width * window->surface->height * window->surface->bytesperpixel); tbar_data = (tbar_data_t *) s_malloc(sizeof(tbar_data_t)); tbar_data->tbar_clock = (tbar_clock_t *) s_malloc(sizeof(tbar_clock_t)); tbar_data->tbar_smenu = (tbar_smenu_t *) s_malloc(sizeof(tbar_smenu_t)); s_list_init(&(tbar_data->tbar_smenu->progs)); s_image_init(&(tbar_data->tbar_smenu->img)); s_image_img(DESKTOPDIR "/img/icons/xynth.png", tbar_data->tbar_smenu->img); s_image_get_handler(tbar_data->tbar_smenu->img); tbar_data->tbar_smenu->running = 0; tbar_data->tbar_progs = (tbar_progs_t *) s_malloc(sizeof(tbar_progs_t)); tbar_data->tbar_progs->desktop = (s_desktop_t *) s_malloc(sizeof(s_desktop_t)); s_list_init(&(tbar_data->tbar_progs->desktop->clients)); s_font_init(&(tbar_data->tbar_progs->prog_font), "arial.ttf"); s_image_init(&(tbar_data->tbar_progs->tbar_img)); s_image_img(DESKTOPDIR "/img/widget/taskbar.png", tbar_data->tbar_progs->tbar_img); s_image_get_buf(window->surface, tbar_data->tbar_progs->tbar_img); s_image_init(&(tbar_data->tbar_progs->prog_img[0])); s_image_img(DESKTOPDIR "/img/widget/button4.png", tbar_data->tbar_progs->prog_img[0]); s_image_get_buf(window->surface, tbar_data->tbar_progs->prog_img[0]); s_image_init(&(tbar_data->tbar_progs->prog_img[1])); s_image_img(DESKTOPDIR "/img/widget/button3.png", tbar_data->tbar_progs->prog_img[1]); s_image_get_buf(window->surface, tbar_data->tbar_progs->prog_img[1]); window->data = (void *) tbar_data; s_fillbox(window->surface, 0, 0, window->surface->buf->w, window->surface->buf->h, s_rgbcolor(window->surface, 255, 255, 255)); s_fillbox(window->surface, 1, 1, window->surface->buf->w - 1, window->surface->buf->h - 1, s_rgbcolor(window->surface, 115, 117, 115)); for (x = 1; x <= window->surface->buf->w; x++) { s_putboxpart(window->surface, x, 1, 1, window->surface->buf->h - 2, 1, 30, tbar_data->tbar_progs->tbar_img->buf, 0, 1); } tbar_data->tbar_clock->clock = NULL; tbar_data->tbar_clock->rect.x = window->surface->width - 3 - 75; tbar_data->tbar_clock->rect.y = 3; tbar_data->tbar_clock->rect.w = 75; tbar_data->tbar_clock->rect.h = window->surface->height - 6; s_font_init(&(tbar_data->tbar_clock->font), "veramono.ttf"); s_font_set_size(tbar_data->tbar_clock->font, tbar_data->tbar_clock->rect.h); tbar_data->tbar_smenu->rect.x = 3; tbar_data->tbar_smenu->rect.y = 3; tbar_data->tbar_smenu->rect.w = window->surface->height - 6; tbar_data->tbar_smenu->rect.h = window->surface->height - 6; tbar_data->tbar_progs->rect.x = 3 + tbar_data->tbar_smenu->rect.w + 3; tbar_data->tbar_progs->rect.y = 3; tbar_data->tbar_progs->rect.w = window->surface->width - 3 - tbar_data->tbar_smenu->rect.w - 3 - 3 - tbar_data->tbar_clock->rect.w - 3; tbar_data->tbar_progs->rect.h = window->surface->height - 6; s_handler_init(&hndl); hndl->type = MOUSE_HANDLER; hndl->mouse.x = tbar_data->tbar_progs->rect.x; hndl->mouse.y = tbar_data->tbar_progs->rect.y; hndl->mouse.w = tbar_data->tbar_progs->rect.w; hndl->mouse.h = tbar_data->tbar_progs->rect.h; hndl->mouse.r = taskbar_progs_handler_r; hndl->mouse.button = MOUSE_BUTTON_LEFT; s_handler_add(window, hndl); s_handler_init(&hndl); hndl->type = MOUSE_HANDLER; hndl->mouse.x = tbar_data->tbar_smenu->rect.x; hndl->mouse.y = tbar_data->tbar_smenu->rect.y; hndl->mouse.w = tbar_data->tbar_smenu->rect.w; hndl->mouse.h = tbar_data->tbar_smenu->rect.h; hndl->mouse.p = taskbar_start_menu_handler_p; hndl->mouse.button = MOUSE_BUTTON_LEFT; s_handler_add(window, hndl); taskbar_start_menu_icon(window); s_handler_init(&hndl); hndl->type = MOUSE_HANDLER; hndl->mouse.x = tbar_data->tbar_clock->rect.x; hndl->mouse.y = tbar_data->tbar_clock->rect.y; hndl->mouse.w = tbar_data->tbar_clock->rect.w; hndl->mouse.h = tbar_data->tbar_clock->rect.h; hndl->mouse.o = taskbar_clock_handler_o; hndl->mouse.oh = taskbar_clock_handler_oh; hndl->data = NULL; s_handler_add(window, hndl); start_menu_setup(window, cfg); s_timer_init(&timer); timer->timeval = 1000; timer->cb = taskbar_clock_draw; s_timer_add(window, timer); taskbar_clock_draw(window, timer); s_window_show(window); s_window_main(window); }
static int draw_single_box (s_surface_t *wsurface, s_rect_t *rect, osk_char_t c[4], int colors[2], image_bin_t *image_bin) { int i; int r; int g; int b; int fh; int x = 0; int y = 0; char *tbuf; s_image_t *img; s_font_t *font; s_surface_t *surface; if (s_surface_create(&surface, rect->w, rect->h, wsurface->bitsperpixel)) { return -1; } s_fillbox(surface, 0, 0, rect->w, rect->h, colors[0]); s_image_init(&img); image_load(img, image_bin->width, image_bin->height, (unsigned char *) image_bin->pixel_data); s_image_get_buf(surface, img); tbuf = (char *) s_malloc(sizeof(char) * (rect->w - 2) * (rect->h - 2) * surface->bytesperpixel); s_scalebox(surface, img->w, img->h, img->buf, rect->w - 2, rect->h - 2, tbuf); s_putbox(surface, 1, 1, rect->w - 2, rect->h - 2, tbuf); s_free(tbuf); s_image_uninit(img); fh = rect->h / 3; for (i = 0; i < 4; i++) { s_font_init(&font, "veramono.ttf"); s_font_set_str(font, c[i].name); s_colorrgb(wsurface, colors[1], &r, &g, &b); s_font_set_rgb(font, r, g, b); if (strlen(c[i].name) > 1) { s_font_set_size(font, fh - 5); } else { s_font_set_size(font, fh); } s_font_get_glyph(font); s_image_get_handler(font->glyph.img); font->glyph.img->handler->x = 0; font->glyph.img->handler->y = 0; font->glyph.img->handler->w = font->glyph.img->w; font->glyph.img->handler->h = font->glyph.img->h; switch (i) { case 0: x = 5; y = (rect->h - fh) / 2; break; case 1: x = (rect->w - font->glyph.img->handler->w) / 2; y = 2; break; case 2: x = rect->w - font->glyph.img->handler->w - 3; y = (rect->h - fh) / 2; break; case 3: y = rect->h - fh - 7; x = (rect->w - font->glyph.img->handler->w) / 2; break; } s_putboxpartrgba(surface, x, y + fh - font->glyph.yMax, font->glyph.img->handler->w, font->glyph.img->handler->h, font->glyph.img->w, font->glyph.img->h, font->glyph.img->rgba, font->glyph.img->handler->x, font->glyph.img->handler->y); s_font_uninit(font); } s_putbox(wsurface, rect->x, rect->y, rect->w, rect->h, surface->vbuf); s_surface_destroy(surface); return 0; }
Mines::Mines (int argc, char *argv[]) { int r; int c; int o; char *tmp; SButton *sbutton; MButton *mbutton; unsigned int *rgba; char *flag_img = {" . " "....... . " ".,,,,,. . " ".,,,,,. . " ".,,,,,. . " ".,,,,,. . " "....... . " " . " " . " " . " " . " " .... " " ...... " " ..........."}; char *mine_img = {" . " " . " " . ..... " " ......... " " ......... " " ...,,...... " " ...,,...... " ".............." " ........... " " ........... " " ......... " " ......... " " . ..... . " " . "}; minesC = 40; minesW = 17; minesH = 17; while ((o = getopt(argc, argv, "m:w:h:")) != -1) { switch (o) { case 'm': minesC = atoi(optarg); break; case 'w': minesW = atoi(optarg); break; case 'h': minesH = atoi(optarg); break; default: break; } } minesMatrix = new int*[minesH]; minesMatrix_ = new int*[minesH]; for (o = 0; o < minesH; o++) { minesMatrix[o] = new int[minesW]; minesMatrix_[o] = new int[minesW]; } minesWindow = new SWindow(); s_image_init(&minesFlag); minesFlag->rgba = (unsigned int *) s_malloc(14 * 14 * sizeof(unsigned int)); tmp = flag_img; rgba = minesFlag->rgba; minesFlag->w = 14; minesFlag->h = 14; for (r = 0; r < 14; r++) { for (c = 0; c < 14; c++) { if (*tmp == '.') { *rgba = 0x00000000; } else if (*tmp == ',') { *rgba = 0xFF000000; } else { *rgba = 0x000000FF; } tmp++; rgba++; } } s_image_get_mat(minesFlag); s_image_get_buf(minesWindow->objectWindow->surface, minesFlag); s_image_init(&minesMine); minesMine->rgba = (unsigned int *) s_malloc(14 * 14 * sizeof(unsigned int)); tmp = mine_img; rgba = minesMine->rgba; minesMine->w = 14; minesMine->h = 14; for (r = 0; r < 14; r++) { for (c = 0; c < 14; c++) { if (*tmp == '.') { *rgba = 0x00000000; } else if (*tmp == ',') { *rgba = 0xFFFFFF00; } else { *rgba = 0x000000FF; } tmp++; rgba++; } } s_image_get_mat(minesMine); s_image_get_buf(minesWindow->objectWindow->surface, minesMine); topLayout = new SLayout(minesWindow, 1, 1); topLayout->layoutSetColSpacing(10); topLayout->layoutSetRowSpacing(10); btnsLayout = new SLayout(NULL, 1, 3); btnsLayout->layoutSetColSpacing(5); btnsLayout->layoutSetRowSpacing(5); minesLayout = new SLayout(NULL, minesH, minesW); minesLayout->layoutSetColSpacing(1); minesLayout->layoutSetRowSpacing(1); // topLayout->layoutInsertObject(btnsLayout, 0, 0); topLayout->layoutInsertObject(minesLayout, 0, 0); sbutton = new SButton(NULL, SFrame::Panel); btnsLayout->layoutInsertObject(sbutton, 0, 1); for (r = 0; r < minesH; r++) { for (c = 0; c < minesW; c++) { mbutton = new MButton(); mbutton->buttonR = r; mbutton->buttonC = c; mbutton->buttonMines = this; minesLayout->layoutInsertObject(mbutton, r, c); } } minesWindow->windowSetCoor(0, 0, minesW * 25, minesH * 25); minesWindow->windowSetTitle("Demo - %s", argv[0]); minesInit(); #ifdef DEBUG for (r = 0; r < minesH; r++) { for (c = 0; c < minesW; c++) { printf("%3d", minesMatrix[r][c]); } printf("\n"); } #endif minesWindow->windowShow(); minesWindow->windowMain(); }