Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F10881067
FROG_Window_Control.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
FROG_Window_Control.h
View Options
#ifndef _FROG_WINDOW_CONTROL_H__
#define _FROG_WINDOW_CONTROL_H__
#include
"FROG_Viewport.h"
//FROG_WINDOW_CONTROL_MESSAGE
#define FROG_WCM_MOUSE_CLICK_DOWN 111
#define FROG_WCM_MOUSE_CLICK_UP 112
#define FROG_WCM_MOUSE_ENTER_VP 121
#define FROG_WCM_MOUSE_LEAVE_VP 122
class
FROG_Window_Control
:
public
FROG_Viewport
{
public
:
typedef
bool
(
*
controlCallback_def
)(
FROG_Window_Control
*
,
int
,
void
*
);
protected
:
std
::
vector
<
controlCallback_def
>
RegisteredCallback_
;
std
::
vector
<
void
*>
RegisteredCallback_Args_
;
string
text_base_
;
string
text_
;
unsigned
char
txt_pos_
;
bool
carriageReturn_
;
public
:
FROG_Window_Control
(
int
x
,
int
y
,
int
w
,
int
h
,
char
*
name
=
NULL
,
FROG_Viewport
*
parent
=
NULL
)
:
FROG_Viewport
(
x
,
y
,
w
,
h
,
name
,
parent
){
color_
[
0
]
=
0.8f
;
color_
[
1
]
=
0.8f
;
color_
[
2
]
=
0.8f
;
color_
[
3
]
=
1.0f
;
movable_
=
false
;
carriageReturn_
=
false
;
txt_pos_
=
0
+
3
*
1
;
setTxt
(
name_
);
}
virtual
~
FROG_Window_Control
(){
}
virtual
int
minimal_width
(){
unsigned
int
Length
=
0
;
unsigned
int
MaxLength
=
0
;
for
(
string
::
iterator
it
=
text_
.
begin
();
it
!=
text_
.
end
();
it
++
){
if
((
*
it
)
==
'\n'
){
if
(
Length
>
MaxLength
)
MaxLength
=
Length
;
Length
=
0
;
}
else
{
Length
+=
9
;
}
}
return
max
(
Length
,
MaxLength
);
}
virtual
void
setTxtAlignment
(
unsigned
char
alignement
){
txt_pos_
=
alignement
;}
void
checkTxtCarriageReturn
(){
if
(
!
carriageReturn_
)
return
;
int
Length
=
0
;
int
SpacePos
=
-
1
;
for
(
string
::
iterator
it
=
text_
.
begin
();
it
!=
text_
.
end
();
it
++
){
if
((
*
it
)
==
'\n'
){
SpacePos
=-
1
;
Length
=
0
;
}
else
{
Length
+=
9
;
if
((
*
it
)
==
' '
)
SpacePos
=
it
-
text_
.
begin
();
if
(
Length
>=
w_
){
if
(
SpacePos
>
0
){
text_
.
replace
(
SpacePos
,
1
,
1
,
'\n'
);
}
else
{
text_
.
insert
(
it
,
1
,
'\n'
);
}
checkTxtCarriageReturn
();
break
;
}
}
}
}
void
setTxt
(
string
txt
){
text_base_
.
assign
(
txt
);
text_
.
assign
(
text_base_
);
checkTxtCarriageReturn
();
}
virtual
void
addCallback
(
bool
(
*
callbackFunc_
)(
FROG_Window_Control
*
,
int
,
void
*
),
void
*
args
=
NULL
){
RegisteredCallback_
.
push_back
(
callbackFunc_
);
RegisteredCallback_Args_
.
push_back
(
args
);
}
virtual
bool
Callback_Display
(
void
){
//printf("%s Display (visible=%i)\n",name_.c_str(),visible_);
if
(
!
visible_
)
return
false
;
glViewport
(
x_
,
y_
,
w_
,
h_
);
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
glOrtho
(
0
,
w_
,
0
,
h_
,
-
1
,
1
);
glMatrixMode
(
GL_MODELVIEW
);
glLoadIdentity
();
// glBegin(GL_QUADS);
glBegin
(
GL_LINE_LOOP
);
glLineWidth
(
3
);
glColor4fv
(
color_
);
glVertex2i
(
1
,
1
);
glVertex2i
(
w_
-
1
,
1
);
glVertex2i
(
w_
-
1
,
h_
-
1
);
glVertex2i
(
1
,
h_
-
1
);
glEnd
();
glColor3f
(
0
,
0
,
0
);
float
txt_x
,
txt_y
;
if
(
txt_pos_
%
3
==
0
){
txt_x
=
0
;
}
else
if
(
txt_pos_
%
3
==
1
){
txt_x
=
(
w_
-
minimal_width
())
/
2.0f
;
}
else
{
txt_x
=
float
(
w_
-
minimal_width
());
}
if
(
txt_pos_
/
3
==
0
){
txt_y
=
0
;
}
else
if
(
txt_pos_
/
3
==
1
){
txt_y
=
(
h_
-
15
)
/
2.0f
;
}
else
{
txt_y
=
h_
-
15.0f
;
}
if
(
txt_x
<
0
)
txt_x
=
0
;
if
(
txt_y
<
0
)
txt_y
=
0
;
glRasterPos2f
(
txt_x
,
txt_y
);
glutBitmapString
(
GLUT_BITMAP_9_BY_15
,
(
const
unsigned
char
*
)
text_
.
c_str
());
bool
EventHandled
=
false
;
//for(unsigned int i=0;i<daughters_.size();i++){
for
(
int
i
=
daughters_
.
size
()
-
1
;
i
>=
0
;
i
--
){
EventHandled
=
EventHandled
|
daughters_
[
i
]
->
Callback_Display
();
}
return
EventHandled
;
}
virtual
bool
Callback_Mouse
(
int
button
,
int
state
,
int
x
,
int
y
){
if
(
!
isInViewport
(
x
,
y
)){
if
(
button
<=
2
)
Handle_Keyboard_IsActive
=
false
;
return
false
;
}
if
(
Handle_Mouse_ButtonState
[
button
]
!=
(
state
==
GLUT_DOWN
)){
Handle_Mouse_hasChanged
=
true
;}
else
{
Handle_Mouse_hasChanged
=
false
;}
Handle_Mouse_ButtonState
[
button
]
=
(
state
==
GLUT_DOWN
);
if
(
button
<=
2
)
Handle_Keyboard_IsActive
=
true
;
bool
EventHandled
=
false
;
for
(
unsigned
int
i
=
0
;
i
<
daughters_
.
size
()
&&!
EventHandled
;
i
++
){
if
(
daughters_
[
i
]){
EventHandled
=
daughters_
[
i
]
->
Callback_Mouse
(
button
,
state
,
x
,
y
);
}
}
return
EventHandled
;
}
virtual
bool
Callback_LeaveViewport
(){
if
(
!
Handle_Mouse_IsInViewport
)
return
false
;
Handle_Mouse_IsInViewport
=
false
;
for
(
unsigned
int
i
=
0
;
i
<
daughters_
.
size
();
i
++
){
if
(
daughters_
[
i
]){
daughters_
[
i
]
->
Callback_LeaveViewport
();
}
}
for
(
unsigned
int
i
=
0
;
i
<
RegisteredCallback_
.
size
();
i
++
){
if
(
!
RegisteredCallback_
[
i
])
continue
;
RegisteredCallback_
[
i
](
this
,
FROG_WCM_MOUSE_LEAVE_VP
,
RegisteredCallback_Args_
[
i
]);
}
return
true
;
}
virtual
bool
Callback_EnterViewport
(){
Handle_Mouse_IsInViewport
=
true
;
for
(
unsigned
int
i
=
0
;
i
<
RegisteredCallback_
.
size
();
i
++
){
if
(
!
RegisteredCallback_
[
i
])
continue
;
RegisteredCallback_
[
i
](
this
,
FROG_WCM_MOUSE_ENTER_VP
,
RegisteredCallback_Args_
[
i
]);
}
return
true
;
}
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, May 3, 5:50 AM (5 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4982832
Default Alt Text
FROG_Window_Control.h (4 KB)
Attached To
rFROGSVN frogsvn
Event Timeline
Log In to Comment