Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multitouch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
multitouch
Commits
b9c5b6e3
Commit
b9c5b6e3
authored
12 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
First attempt to make cairo rectangle draggable.
parent
878291b4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/cairotest.py
+27
-15
27 additions, 15 deletions
tests/cairotest.py
with
27 additions
and
15 deletions
tests/cairotest.py
+
27
−
15
View file @
b9c5b6e3
...
@@ -19,6 +19,14 @@ class Rectangle(mt.RectangularWidget):
...
@@ -19,6 +19,14 @@ class Rectangle(mt.RectangularWidget):
self
.
scale
=
1
self
.
scale
=
1
self
.
color
=
color
self
.
color
=
color
self
.
on_drag
(
self
.
move
)
def
move
(
self
,
g
):
print
'
drag rectangle
'
,
g
.
get_translation
()
self
.
translate
(
*
g
.
get_translation
())
print
self
refresh
()
def
scale
(
self
,
angle
):
def
scale
(
self
,
angle
):
self
.
scale
*=
scale
self
.
scale
*=
scale
...
@@ -27,7 +35,7 @@ class Rectangle(mt.RectangularWidget):
...
@@ -27,7 +35,7 @@ class Rectangle(mt.RectangularWidget):
def
get_transformation_matrix
(
self
):
def
get_transformation_matrix
(
self
):
t
=
cairo
.
Matrix
()
t
=
cairo
.
Matrix
()
t
.
translate
(
*
self
.
get_position
()
)
t
.
translate
(
*
self
)
t
.
rotate
(
self
.
angle
)
t
.
rotate
(
self
.
angle
)
t
.
scale
(
self
.
scale
,
self
.
scale
)
t
.
scale
(
self
.
scale
,
self
.
scale
)
return
t
return
t
...
@@ -48,8 +56,6 @@ def create_context_window(w, h, callback):
...
@@ -48,8 +56,6 @@ def create_context_window(w, h, callback):
def
create_context
(
area
,
event
):
def
create_context
(
area
,
event
):
"""
Add Cairo context to GTK window and draw initial state.
"""
"""
Add Cairo context to GTK window and draw initial state.
"""
global
cr
global
cr
#if cr:
# return
cr
=
area
.
window
.
cairo_create
()
cr
=
area
.
window
.
cairo_create
()
draw
()
draw
()
...
@@ -78,24 +84,26 @@ def create_context_window(w, h, callback):
...
@@ -78,24 +84,26 @@ def create_context_window(w, h, callback):
root
=
mt
.
RectangularWidget
(
0
,
0
,
w
,
h
)
root
=
mt
.
RectangularWidget
(
0
,
0
,
w
,
h
)
# GTK window
# GTK window
win
=
gtk
.
Window
()
global
window
win
.
set_title
(
'
Cairo test
'
)
window
=
gtk
.
Window
()
win
.
connect
(
'
destroy
'
,
quit
)
window
.
set_title
(
'
Cairo test
'
)
win
.
connect
(
'
key-press-event
'
,
handle_key
)
window
.
connect
(
'
destroy
'
,
quit
)
win
.
connect
(
'
configure-event
'
,
move_window
)
window
.
connect
(
'
key-press-event
'
,
handle_key
)
win
.
connect
(
'
show
'
,
callback
)
window
.
connect
(
'
configure-event
'
,
move_window
)
window
.
connect
(
'
show
'
,
callback
)
# Drawing area, needed by cairo context for drawing
# Drawing area, needed by cairo context for drawing
area
=
gtk
.
DrawingArea
()
area
=
gtk
.
DrawingArea
()
area
.
set_size_request
(
w
,
h
)
area
.
set_size_request
(
w
,
h
)
area
.
connect
(
'
expose-event
'
,
create_context
)
area
.
connect
(
'
expose-event
'
,
create_context
)
win
.
add
(
area
)
win
dow
.
add
(
area
)
area
.
show
()
area
.
show
()
win
.
show
()
win
dow
.
show
()
def
draw
():
def
draw
(
*
args
):
print
'
draw
'
# Background
# Background
cr
.
rectangle
(
0
,
0
,
*
root
.
get_size
())
cr
.
rectangle
(
0
,
0
,
*
root
.
get_size
())
cr
.
set_source_rgb
(
0
,
1
,
0
)
cr
.
set_source_rgb
(
0
,
1
,
0
)
...
@@ -103,13 +111,17 @@ def draw():
...
@@ -103,13 +111,17 @@ def draw():
# Drawable objects (use save and restore to allow transformations)
# Drawable objects (use save and restore to allow transformations)
for
obj
in
draw_objects
:
for
obj
in
draw_objects
:
#
cr.save()
cr
.
save
()
obj
.
draw
(
cr
)
obj
.
draw
(
cr
)
#cr.restore()
cr
.
restore
()
def
refresh
():
window
.
queue_draw
()
# Initialization
# Initialization
cr
=
root
=
None
window
=
cr
=
root
=
None
draw_objects
=
[]
draw_objects
=
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment