-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzglButton.cpp
executable file
·127 lines (104 loc) · 2.7 KB
/
zglButton.cpp
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
/*
* Copyright (C) 2010 ZiiLABS Pte Ltd
* All Rights Reserved.
*
* This software and its associated documentation may contain some
* proprietary, confidential and trade secret information of
* ZiiLABS Pte Ltd and except as provided by written agreement with
* ZiiLABS Pte Ltd
*
* a) no part may be disclosed, distributed, reproduced, transmitted,
* transcribed, stored in a retrieval system, adapted or translated
* in any form or by any means electronic, mechanical, magnetic,
* optical, chemical, manual or otherwise,
*
* and
*
* b) the recipient is not entitled to discover through reverse
* engineering or reverse compiling or other such techniques or
* processes the trade secrets contained therein or in the
* documentation.
*/
#include <stdlib.h>
#include "zglButton.h"
#include "zglEventType.h"
#include "zglBasicType.h"
zglButton::zglButton()
{
m_vertex[0].setUV(0.0f, 0.0f);
m_vertex[1].setUV(0.0f, 1.0f);
m_vertex[2].setUV(1.0f, 0.0f);
m_vertex[3].setUV(1.0f, 1.0f);
m_tx = 0.0f;
m_ty = 0.0f;
m_vertex[0].a = 0xff;
m_vertex[1].a = 0xff;
m_vertex[2].a = 0xff;
m_vertex[3].a = 0xff;
m_map_flag = FLAG_MAPPING_DYNAMIC;
}
void zglButton::init(zglTexture * tex, unsigned int width, unsigned int height)
{
zglWidget2D::init();
m_prim.init(DRAW_TRI_STRIP, m_vertex, 4, (zglTexture *) tex);
m_prim.setBlendType(BLEND_HALF);
m_width = width;
m_height = height;
}
void zglButton::setTexCoord(float left, float top, float right, float bottom,
float tx, float ty)
{
m_vertex[0].setUV(left, top);
m_vertex[1].setUV(left, bottom);
m_vertex[2].setUV(right, top);
m_vertex[3].setUV(right, bottom);
m_tx = tx;
m_ty = ty;
applyVertexUpdate();
}
void zglButton::updateDimension()
{
float width2 = m_width * 0.5f;
float height2 = m_height * 0.5f;
m_vertex[0].setPos(-width2, height2, 0.0f);
m_vertex[1].setPos(-width2, -height2, 0.0f);
m_vertex[2].setPos(width2, height2, 0.0f);
m_vertex[3].setPos(width2, -height2, 0.0f);
}
bool zglButton::onTouchEvent(zglTouchEvent *event)
{
bool ret = false;
switch (event->m_event_type)
{
case TOUCH_DOWN: //down
{
m_vertex[0].u += m_tx;
m_vertex[0].v += m_ty;
m_vertex[1].u += m_tx;
m_vertex[1].v += m_ty;
m_vertex[2].u += m_tx;
m_vertex[2].v += m_ty;
m_vertex[3].u += m_tx;
m_vertex[3].v += m_ty;
applyVertexUpdate();
}
break;
case TOUCH_UP:
case TOUCH_CANCEL:
{
m_vertex[0].u -= m_tx;
m_vertex[0].v -= m_ty;
m_vertex[1].u -= m_tx;
m_vertex[1].v -= m_ty;
m_vertex[2].u -= m_tx;
m_vertex[2].v -= m_ty;
m_vertex[3].u -= m_tx;
m_vertex[3].v -= m_ty;
applyVertexUpdate();
}
break;
case TOUCH_MOVE:
break;
}
return zglWidget::onTouchEvent(event) || ret;
}