1 #include <Window.h>
2 #include "MyView.h"
3
4 #include "WinBorder.h"
5
6 #include <stdio.h>
7
8 extern BWindow* wind;
9
WinBorder(BRect frame,const char * name,uint32 rm,uint32 flags,rgb_color c)10 WinBorder::WinBorder(BRect frame, const char* name,
11 uint32 rm, uint32 flags, rgb_color c)
12 : Layer(frame, name, rm, flags, c)
13 {
14 fColor.red = 255;
15 fColor.green = 203;
16 fColor.blue = 0;
17
18 fRebuildDecRegion = true;
19 }
20
~WinBorder()21 WinBorder::~WinBorder()
22 {
23 }
24
MovedByHook(float dx,float dy)25 void WinBorder::MovedByHook(float dx, float dy)
26 {
27 fDecRegion.OffsetBy(dx, dy);
28 }
29
ResizedByHook(float dx,float dy,bool automatic)30 void WinBorder::ResizedByHook(float dx, float dy, bool automatic)
31 {
32 fRebuildDecRegion = true;
33 }
34
set_decorator_region(BRect bounds)35 void WinBorder::set_decorator_region(BRect bounds)
36 {
37 fRebuildDecRegion = false;
38
39 fDecRegion.MakeEmpty();
40 // NOTE: frame is in screen coords
41 fDecRegion.Include(BRect(bounds.left-4, bounds.top-4, bounds.right+4, bounds.top-1));
42 fDecRegion.Include(BRect(bounds.left-4, bounds.bottom+1, bounds.right+4, bounds.bottom+4));
43 fDecRegion.Include(BRect(bounds.left-4, bounds.top, bounds.left-1, bounds.bottom));
44 fDecRegion.Include(BRect(bounds.right+1, bounds.top, bounds.right+4, bounds.bottom));
45
46 // tab
47 fDecRegion.Include(BRect(bounds.left-4, bounds.top-4-10, bounds.left+bounds.Width()/2, bounds.top-4));
48
49 // resize rect
50 fDecRegion.Include(BRect(bounds.right-10, bounds.bottom-10, bounds.right, bounds.bottom));
51 }
52
alter_visible_for_children(BRegion & region)53 bool WinBorder::alter_visible_for_children(BRegion ®ion)
54 {
55 region.Exclude(&fDecRegion);
56 return true;
57 }
58
get_user_regions(BRegion & reg)59 void WinBorder::get_user_regions(BRegion ®)
60 {
61 if (fRebuildDecRegion)
62 {
63 set_decorator_region(Bounds());
64 ConvertToScreen2(&fDecRegion);
65 }
66
67 BRect screenFrame(Bounds());
68 ConvertToScreen2(&screenFrame);
69 reg.Set(screenFrame);
70
71 wind->Lock();
72 BRegion screenReg(GetRootLayer()->Bounds());
73 wind->Unlock();
74 reg.IntersectWith(&screenReg);
75
76 reg.Include(&fDecRegion);
77 }
78