File: label.cpp

package info (click to toggle)
libretro-bsnes-mercury 094%2Bgit20160126-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,636 kB
  • sloc: cpp: 109,056; ansic: 3,097; makefile: 638; xml: 11; sh: 1
file content (68 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (5)
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
namespace phoenix {

Size pLabel::minimumSize() {
  Size size = pFont::size(hfont, label.state.text);
  return {size.width, size.height};
}

void pLabel::setText(string text) {
  SetWindowText(hwnd, utf16_t(text));
  InvalidateRect(hwnd, 0, false);
}

void pLabel::constructor() {
  hwnd = CreateWindow(L"phoenix_label", L"",
    WS_CHILD,
    0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0);
  SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&label);
  setDefaultFont();
  setText(label.state.text);
  synchronize();
}

void pLabel::destructor() {
  DestroyWindow(hwnd);
}

void pLabel::orphan() {
  destructor();
  constructor();
}

static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
  HWND parentHwnd = GetParent(hwnd);
  Label* label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  if(label == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam);
  Window* window = (Window*)label->Sizable::state.window;
  if(window == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam);

  switch(msg) {
  case WM_GETDLGCODE: return DLGC_STATIC | DLGC_WANTCHARS;
  case WM_ERASEBKGND: return TRUE;
  case WM_PAINT: {
    PAINTSTRUCT ps;
    BeginPaint(hwnd, &ps);
    RECT rc;
    GetClientRect(hwnd, &rc);
    DrawThemeParentBackground(hwnd, ps.hdc, &rc);
    SetBkMode(ps.hdc, TRANSPARENT);
    SelectObject(ps.hdc, ((Widget*)label)->p.hfont);
    unsigned length = GetWindowTextLength(hwnd);
    wchar_t text[length + 1];
    GetWindowText(hwnd, text, length + 1);
    text[length] = 0;
    DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS);
    unsigned height = rc.bottom;
    GetClientRect(hwnd, &rc);
    rc.top = (rc.bottom - height) / 2;
    rc.bottom = rc.top + height;
    DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS);
    EndPaint(hwnd, &ps);
    return FALSE;
  }
  }

  return DefWindowProc(hwnd, msg, wparam, lparam);
}

}