Changeset 1196

Show
Ignore:
Timestamp:
04/05/07 01:23:17 (2 years ago)
Author:
arj..@yirdis.nl
Message:

Fixed some issues with text placement in Gaphas

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/trunk/demo.py

    r1185 r1196  
    3030from gaphas.painter import ItemPainter 
    3131from gaphas import state 
     32from gaphas.util import text_extents 
    3233 
    3334# Global undo list 
     
    6566 
    6667class MyText(Text): 
    67     """Text with experimental connection protocol. 
    6868    """ 
    69     pass 
     69    Text with experimental connection protocol. 
     70    """ 
     71     
     72    def draw(self, context): 
     73        Text.draw(self, context) 
     74        cr = context.cairo 
     75        w, h = text_extents(cr, self.text, multiline=self.multiline) 
     76        cr.rectangle(0, 0, w, h) 
     77        cr.set_source_rgba(.3, .3, 1., .6) 
     78        cr.stroke() 
    7079 
    7180 
     
    306315    l.orthogonal = True 
    307316 
    308     t=MyText(
     317    t=MyText('Single line'
    309318    t.matrix.translate(70,70) 
     319    c.add(t) 
     320 
     321    off_y = 0 
     322    for align_x in (-1, 0, 1): 
     323        for align_y in (-1, 0, 1): 
     324            t=MyText('Aligned text %d/%d' % (align_x, align_y), 
     325                     align_x=align_x, align_y=align_y) 
     326            t.matrix.translate(120, 200 + off_y) 
     327            off_y += 30 
     328            c.add(t) 
     329 
     330    t=MyText('Multiple\nlines', multiline = True) 
     331    t.matrix.translate(70,100) 
    310332    c.add(t) 
    311333 
  • gaphas/trunk/gaphas/examples.py

    r1145 r1196  
    1212from constraint import LineConstraint 
    1313from geometry import point_on_rectangle, distance_rectangle_point 
     14from util import text_extents, text_align, text_multiline 
    1415 
    1516class Box(Element): 
     
    5051 
    5152class Text(Item): 
    52     """Simple item shoring some text on the canvas. 
     53    """ 
     54    Simple item showing some text on the canvas. 
    5355    """ 
    5456 
    55     def __init__(self): 
     57    def __init__(self, text=None, plain=False, multiline=False, align_x=1, align_y=-1): 
    5658        super(Text, self).__init__() 
     59        self.text = text is None and 'Hello' or text 
     60        self.plain = plain 
     61        self.multiline = multiline 
     62        self.align_x = align_x 
     63        self.align_y = align_y 
    5764 
    5865    def draw(self, context): 
    5966        #print 'Text.draw', self 
    60         c = context.cairo 
    61         c.show_text('Hello') 
     67        cr = context.cairo 
     68        if self.multiline: 
     69            text_multiline(cr, 0, 0, self.text) 
     70        elif self.plain: 
     71            cr.show_text(self.text) 
     72        else: 
     73            text_align(cr, 0, 0, self.text, self.align_x, self.align_y) 
    6274        context.draw_children() 
    6375 
  • gaphas/trunk/gaphas/tool.py

    r1183 r1196  
    445445        finally: 
    446446            # Decrement handle strength, previously incremented on button press 
    447             self._grabbed_handle.x.strength -= 1 
    448             self._grabbed_handle.y.strength -= 1 
     447            if self._grabbed_handle: 
     448                self._grabbed_handle.x.strength -= 1 
     449                self._grabbed_handle.y.strength -= 1 
    449450            context.view.queue_draw_item(context.view.hovered_item, handles=True) 
    450451            context.ungrab() 
  • gaphas/trunk/gaphas/util.py

    r1133 r1196  
    3636def text_align(cr, x, y, text, align_x=0, align_y=0, padding_x=0, padding_y=0): 
    3737    """ 
    38     Draw text using (x, y) as center. 
    39     x    - center x 
    40     y    - center y 
     38    Draw text relative to (x, y). 
     39    x, y - coordinates 
    4140    text - text to print (utf8) 
    4241    align_x - -1 (top), 0 (middle), 1 (bottom) 
     
    7776    for line in text.split('\n'): 
    7877        x_bear, y_bear, w, h, x_adv, y_adv = cr.text_extents(text) 
     78        y += h 
    7979        cr.move_to(x, y) 
    8080        cr.show_text(line) 
    81         y += h + padding 
    8281 
    8382def text_set_font(cr, font): 
  • gaphas/trunk/setup.py

    r1165 r1196  
    88setup( 
    99    name='gaphas', 
    10     version='0.1.3', 
     10    version='0.1.4', 
    1111    description='Gaphas is a GTK+ based diagramming widget', 
    1212    long_description="""\