File: horizontal-slider.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 (47 lines) | stat: -rw-r--r-- 1,341 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
namespace phoenix {

Size pHorizontalSlider::minimumSize() {
  return {0, 25};
}

void pHorizontalSlider::setLength(unsigned length) {
  length += (length == 0);
  SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1));
  SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3));
  horizontalSlider.setPosition(0);
}

void pHorizontalSlider::setPosition(unsigned position) {
  SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position);
}

void pHorizontalSlider::constructor() {
  hwnd = CreateWindow(
    TRACKBAR_CLASS, L"", WS_CHILD | WS_TABSTOP | TBS_TRANSPARENTBKGND | TBS_NOTICKS | TBS_BOTH | TBS_HORZ,
    0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0
  );
  SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&horizontalSlider);

  unsigned position = horizontalSlider.state.position;
  setLength(horizontalSlider.state.length);
  horizontalSlider.setPosition(position);
  synchronize();
}

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

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

void pHorizontalSlider::onChange() {
  unsigned position = SendMessage(hwnd, TBM_GETPOS, 0, 0);
  if(position == horizontalSlider.state.position) return;
  horizontalSlider.state.position = position;
  if(horizontalSlider.onChange) horizontalSlider.onChange();
}

}