File: ui_sample_sb_view_lib_win32.c

package info (click to toggle)
mlterm 3.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,340 kB
  • sloc: ansic: 154,713; sh: 5,302; cpp: 2,953; objc: 2,776; java: 2,472; makefile: 2,445; perl: 1,674; xml: 44
file content (70 lines) | stat: -rw-r--r-- 1,721 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */

#include "ui_sample_sb_view_lib.h"

#include <stdio.h>

/* --- global functions --- */

Pixmap ui_get_icon_pixmap(ui_sb_view_t *view, GC gc, GC memgc, char **data, unsigned int width,
                          unsigned int height, unsigned int depth, /* Not used */
                          unsigned long black,                     /* Not used */
                          unsigned long white                      /* Not used */
                          ) {
  HBITMAP pix;
  char cur;
  int x;
  int y;

  pix = CreateCompatibleBitmap(gc, width, height);
  SelectObject(memgc, pix);

  cur = '\0';
  for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
      if (cur != data[y][x]) {
        if (data[y][x] == ' ') {
          SelectObject(memgc, GetStockObject(WHITE_PEN));
        } else if (data[y][x] == '#') {
          SelectObject(memgc, GetStockObject(BLACK_PEN));
        } else {
          continue;
        }

        cur = data[y][x];
      }

      MoveToEx(memgc, x, y, NULL);
      LineTo(memgc, x + 1, y + 1);
    }

    x = 0;
  }

  /* XXX HBITMAP -> Pixmap(== HDC) to share ui_sample_sb_view_lib.h interfaces with xlib. */
  return (Pixmap)pix;
}

int ui_draw_icon_pixmap_fg(ui_sb_view_t *view, GC gc, char **data, unsigned int width,
                           unsigned int height) {
  int x;
  int y;
  int start;

  start = 0;
  for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
      if (data[y][x] == '-') {
        if (!start) {
          MoveToEx(gc, x, y, NULL);
          start = 1;
        }
      } else if (start) {
        LineTo(gc, x, y);
        start = 0;
      }
    }
  }

  return 1;
}