-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathYabBitmapView.cpp
More file actions
117 lines (104 loc) · 3.08 KB
/
YabBitmapView.cpp
File metadata and controls
117 lines (104 loc) · 3.08 KB
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
#include <Bitmap.h>
#include <Path.h>
#include <Picture.h>
#include <Region.h>
#include <View.h>
#include "YabWindow.h"
#include "YabBitmapView.h"
YabBitmapView::YabBitmapView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags)
{
bmp = new BBitmap(BRect(0,0, frame.Width(), frame.Height()), B_RGBA32, true);
BView *myView = new BView(BRect(0,0, frame.Width(), frame.Height()), "canvas", B_FOLLOW_NONE, 0);
bmp->AddChild(myView);
SetDrawingMode(B_OP_COPY);
SetViewColor(0,0,0,255);
mouseMovedInfo = 1;
mouseStateInfo = -1;
prevMouseStateInfo = 0;
mouseX = 0;
mouseY = 0;
mouseLButton = 0;
mouseMButton = 0;
mouseRButton = 0;
}
YabBitmapView::~YabBitmapView()
{
delete bmp;
}
BBitmap* YabBitmapView::GetBitmap()
{
return bmp;
}
BView* YabBitmapView::GetBitmapView()
{
return bmp->FindView("canvas");
}
void YabBitmapView::Draw(BRect updateRect)
{
DrawBitmap(bmp, updateRect, updateRect);
}
void YabBitmapView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, true);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
switch(transit)
{
case B_INSIDE_VIEW:
if(prevMouseStateInfo==1)
mouseStateInfo = 0;
else
{
mouseStateInfo = 1;
prevMouseStateInfo = 1;
}
mouseMovedInfo = 0;
break;
case B_ENTERED_VIEW:
mouseStateInfo = 1;
mouseMovedInfo = 0;
break;
case B_OUTSIDE_VIEW:
mouseStateInfo = 2;
mouseMovedInfo = 1;
break;
case B_EXITED_VIEW:
mouseStateInfo = 3;
mouseMovedInfo = 1;
prevMouseStateInfo = 0;
break;
}
BView::MouseMoved(point, transit, message);
}
void YabBitmapView::MouseDown(BPoint point)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, false);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
mouseStateInfo = 4;
BView::MouseDown(point);
}
void YabBitmapView::MouseUp(BPoint point)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, false);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
mouseStateInfo = 5;
BView::MouseUp(point);
}