aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_ml/comboskin.cpp
blob: 886005ceca336c7d12608f42b14eb3e676e28506 (plain) (blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "main.h"

#include "comboskin.h"

static int RectInRect(RECT *rect1, RECT *rect2)
{ 
  // this has a bias towards true

  // this could probably be optimized a lot
  return ((rect1->top >= rect2->top && rect1->top <= rect2->bottom) ||
      (rect1->bottom >= rect2->top && rect1->bottom <= rect2->bottom) ||
      (rect2->top >= rect1->top && rect2->top <= rect1->bottom) ||
      (rect2->bottom >= rect1->top && rect2->bottom <= rect1->bottom)) // vertical intersect
      &&
      ((rect1->left >= rect2->left && rect1->left <= rect2->right) ||
      (rect1->right >= rect2->left && rect1->right <= rect2->right) ||
      (rect2->left >= rect1->left && rect2->left <= rect1->right) ||
      (rect2->right >= rect1->left && rect2->right <= rect1->right)) // horiz intersect
      ;
}

static INT_PTR CALLBACK wndproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
  ComboSkin *cs=(ComboSkin *)(LONG_PTR)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  if (uMsg == WM_PAINT) 
  {
    RECT r;
    GetClientRect(hwndDlg,&r);
    RECT ur;
    GetUpdateRect(hwndDlg,&ur,FALSE);
    if(RectInRect(&r,&ur)) //hmmm not sure about testing this, should probably use a backbuffer or something
    {
      //Fill with bg color
      HDC hdc=GetDC(hwndDlg);
      HBRUSH b=CreateSolidBrush(WADlg_getColor(WADLG_WNDBG));
      HBRUSH b2=CreateSolidBrush(WADlg_getColor(WADLG_HILITE)); //sunken

      //top line
      {
        RECT a={0,0,r.right-r.left,3};
        FillRect(hdc,&a,b);
        ValidateRect(hwndDlg,&a);
      }
      //bottom lines
      {
        RECT a={0,r.bottom-2,r.right-r.left,r.bottom};
        FillRect(hdc,&a,b);
        ValidateRect(hwndDlg,&a);
      }
      {
        //sunken part
        RECT a={0,r.bottom-3,r.right-r.left,r.bottom-2};
        FillRect(hdc,&a,b2);
        ValidateRect(hwndDlg,&a);
      }
      //left
      {
        RECT a={0,0,2,r.bottom-r.top};
        FillRect(hdc,&a,b);
        ValidateRect(hwndDlg,&a);
      }
      //right
      {
        RECT a={r.right-2,0,r.right,r.bottom-r.top};
        FillRect(hdc,&a,b);
        ValidateRect(hwndDlg,&a);
      }

      //paint the arrow
      HBITMAP bmp=WADlg_getBitmap();
      HDC hdcbmp = CreateCompatibleDC(hdc);
      SelectObject(hdcbmp,bmp);
      int pushed=0;
      if(GetAsyncKeyState(MK_LBUTTON) & 0x8000)
      {
        //check if in arrow down area
        POINT cursor;
        GetCursorPos(&cursor);
        ScreenToClient(hwndDlg,&cursor);
        if(cursor.x >= r.right-20 && cursor.x <= r.right) 
		{
			pushed=1;
		}
      }
      int startx=14;
      int starty=31;
      if(pushed) startx+=28;
      int left=r.right-18;
      int top=r.top+4;
      StretchBlt(hdc,left,top,14,14,hdcbmp,startx,starty,14,14,SRCCOPY);
      DeleteDC(hdcbmp);
      RECT a={left,top,left+14,top+14};
      ValidateRect(hwndDlg,&a);
      //paint arrow borders
      {
        HBRUSH b=CreateSolidBrush(WADlg_getColor(WADLG_ITEMBG));
        RECT a={left,3,left+14,4};
        FillRect(hdc,&a,b);
        ValidateRect(hwndDlg,&a);

        RECT c={left,17,left+14,18};
        FillRect(hdc,&c,b);
        ValidateRect(hwndDlg,&c);

        RECT d={left+14,3,left+15,18};
        FillRect(hdc,&d,b);
        ValidateRect(hwndDlg,&d);

        RECT e={left+15,3,left+16,19};
        FillRect(hdc,&e,b2);
        ValidateRect(hwndDlg,&e);

        DeleteObject(b);
      }
      
      DeleteObject(b);
      DeleteObject(b2);
      ReleaseDC(hwndDlg,hdc);
    }
  }

  if(uMsg == WM_WINDOWPOSCHANGING)
  {
    //move it up 1 pixel so it's correctly centered
    WINDOWPOS *wp=(WINDOWPOS *)lParam;
    wp->y--;
  }

  if(uMsg == WM_KILLFOCUS || uMsg == WM_LBUTTONUP)
  {
    InvalidateRect(hwndDlg,NULL,TRUE);
  }
  
  return CallWindowProc(cs->m_old_wndproc,hwndDlg,uMsg,wParam,lParam);
}

ComboSkin::ComboSkin(HWND hwnd)
{
  m_hwnd=hwnd;

  SetWindowLongPtr(m_hwnd,GWLP_USERDATA, (LONGX86)(LONG_PTR)this);
  m_old_wndproc=(WNDPROC)(LONG_PTR)SetWindowLongPtr(m_hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)wndproc);
}

ComboSkin::~ComboSkin()
{
  SetWindowLongPtr(m_hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)m_old_wndproc);
}