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):
self
.
scale
=
1
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
):
self
.
scale
*=
scale
...
...
@@ -27,7 +35,7 @@ class Rectangle(mt.RectangularWidget):
def
get_transformation_matrix
(
self
):
t
=
cairo
.
Matrix
()
t
.
translate
(
*
self
.
get_position
()
)
t
.
translate
(
*
self
)
t
.
rotate
(
self
.
angle
)
t
.
scale
(
self
.
scale
,
self
.
scale
)
return
t
...
...
@@ -48,8 +56,6 @@ def create_context_window(w, h, callback):
def
create_context
(
area
,
event
):
"""
Add Cairo context to GTK window and draw initial state.
"""
global
cr
#if cr:
# return
cr
=
area
.
window
.
cairo_create
()
draw
()
...
...
@@ -78,24 +84,26 @@ def create_context_window(w, h, callback):
root
=
mt
.
RectangularWidget
(
0
,
0
,
w
,
h
)
# GTK window
win
=
gtk
.
Window
()
win
.
set_title
(
'
Cairo test
'
)
win
.
connect
(
'
destroy
'
,
quit
)
win
.
connect
(
'
key-press-event
'
,
handle_key
)
win
.
connect
(
'
configure-event
'
,
move_window
)
win
.
connect
(
'
show
'
,
callback
)
global
window
window
=
gtk
.
Window
()
window
.
set_title
(
'
Cairo test
'
)
window
.
connect
(
'
destroy
'
,
quit
)
window
.
connect
(
'
key-press-event
'
,
handle_key
)
window
.
connect
(
'
configure-event
'
,
move_window
)
window
.
connect
(
'
show
'
,
callback
)
# Drawing area, needed by cairo context for drawing
area
=
gtk
.
DrawingArea
()
area
.
set_size_request
(
w
,
h
)
area
.
connect
(
'
expose-event
'
,
create_context
)
win
.
add
(
area
)
win
dow
.
add
(
area
)
area
.
show
()
win
.
show
()
win
dow
.
show
()
def
draw
():
def
draw
(
*
args
):
print
'
draw
'
# Background
cr
.
rectangle
(
0
,
0
,
*
root
.
get_size
())
cr
.
set_source_rgb
(
0
,
1
,
0
)
...
...
@@ -103,13 +111,17 @@ def draw():
# Drawable objects (use save and restore to allow transformations)
for
obj
in
draw_objects
:
#
cr.save()
cr
.
save
()
obj
.
draw
(
cr
)
#cr.restore()
cr
.
restore
()
def
refresh
():
window
.
queue_draw
()
# Initialization
cr
=
root
=
None
window
=
cr
=
root
=
None
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