File: vertical-slider.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (46 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download | duplicates (4)
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
#if defined(Hiro_VerticalSlider)

namespace hiro {

auto pVerticalSlider::construct() -> void {
  //TBS_TRANSPARENTBKGND is needed to render the transparent area of sliders properly inside TabFrame controls
  //however, this flag will prevent the slider control from redrawing during vertical window resizes when not inside TabFrame controls
  //this is because WM_PRINTCLIENT must be implemented in the parent window for this case
  //however, WM_PRINTCLIENT is incompatible with WM_PAINT, which is how most hiro custom widgets are rendered
  //as a hacky workaround, TBS_TRANSPARENTBKGND is enabled only when sliders are placed inside of TabFrame controls
  auto style = WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT;
  if(self().parentTabFrame(true)) style |= TBS_TRANSPARENTBKGND;
  hwnd = CreateWindow(TRACKBAR_CLASS, L"", style, 0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
  pWidget::construct();
  setLength(state().length);
  setPosition(state().position);
}

auto pVerticalSlider::destruct() -> void {
  DestroyWindow(hwnd);
}

auto pVerticalSlider::minimumSize() const -> Size {
  return {25_sx, 0};
}

auto pVerticalSlider::setLength(u32 length) -> void {
  length += (length == 0);
  SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1));
  SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3));
}

auto pVerticalSlider::setPosition(u32 position) -> void {
  SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position);
}

auto pVerticalSlider::onChange() -> void {
  u32 position = SendMessage(hwnd, TBM_GETPOS, 0, 0);
  if(position == state().position) return;
  state().position = position;
  self().doChange();
}

}

#endif