Changeset fe65dba


Ignore:
Timestamp:
05/02/11 14:13:51 (4 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
5eb4d90
Parents:
2a57f1f
git-author:
xkolman2 <xkolman2@…> (05/02/11 14:13:51)
git-committer:
xkolman2 <xkolman2@…> (05/02/11 14:13:51)
Message:

enable line wrapping
make the navigation text bigger & reuse the first line with distance-to-turn
cut the overflowing part of the text (show a "scissors" icon when this happens)
show current turn number/turn cound and elapsed distance/total distance in the footer
add icons for previous/next and hihe/show

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@359 0858a4d0-ffff-46e5-938e-62b5ecb34222

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/mod_turnByTurn.py

    rd3be082 rfe65dba  
    4242  def goToInitialState(self): 
    4343    self.steps = [] 
    44     self.currentStepIndex = None 
     44    self.currentStepIndex = 0 
    4545    self.currentStepIndicator = None 
    4646    self.espeakFirstTrigger = False 
     
    5151    self.currentStep = None 
    5252    self.navigationBoxHidden = False 
     53    self.mRouteLength = 0 
    5354 
    5455 
     
    134135    elif message == "switchToNextTurn": 
    135136      self.switchToNextStep() 
     137#    elif message == "showMessageInNotification": 
     138#      currentStep = self.getCurrentStep() 
     139#      if currentStep: 
     140#        message = currentStep['descriptionHtml'] 
    136141 
    137142  def drawMapOverlay(self,cr): 
     
    167172        buttonStripOffset = 0.25 * bh 
    168173 
    169         # construct parameters for the cairo drawn buttons 
    170         boxAlpha = self.navigationBoxBackground[3] 
    171         parametricIconName="generic:;%f;;%f;7;5" % (0, boxAlpha*2) 
     174        # construct parametric background for the cairo drawn buttons 
     175        background="generic:;%f;;%f;5;0" % (0, 1.0) 
    172176         
    173177        if self.navigationBoxHidden: 
     
    175179          showButtonWidth = bw * 0.2 
    176180          # the show button uses custom parameters 
    177           parametricIconName="generic:;%f;;%f;;5" % (boxAlpha, boxAlpha) 
    178           menus.drawButton(cr, bx+(bw-showButtonWidth), by, showButtonWidth, buttonStripOffset, "#show", parametricIconName, "turnByTurn:toggleBoxHiding") 
     181          parametricIconName="center:show;0.1>%s" % background 
     182          menus.drawButton(cr, bx+(bw-showButtonWidth), by, showButtonWidth, buttonStripOffset, "", parametricIconName, "turnByTurn:toggleBoxHiding") 
     183   
    179184        else: 
    180           # background 
     185          # draw the info-box background 
    181186          cr.set_source_rgba(*self.navigationBoxBackground) 
    182187          cr.rectangle(bx,by,bw,bh) 
    183188          cr.fill() 
    184           cr.set_source_rgba(*self.navigationBoxText) 
     189           
     190          # create a layout for our drawing area 
    185191          pg = pangocairo.CairoContext(cr) 
    186           # create a layout for our drawing area 
    187192          layout = pg.create_layout() 
     193 
     194          # get the current turn message 
    188195          message = currentStep['descriptionHtml'] 
    189  
    190           # display current distance to the next point 
     196       
     197          # display current distance to the next point & other unit conversions 
    191198          units = self.m.get('units', None) 
    192199          if units and self.currentDistance: 
    193             distString = units.m2CurrentUnitString(self.currentDistance,2) 
     200            distString = units.m2CurrentUnitString(self.currentDistance,1,True) 
     201            currentDistString = units.m2CurrentUnitString(currentStep['mDistanceFromStart'],1,True) 
     202            routeLengthString = units.m2CurrentUnitString(self.mRouteLength,1,True) 
    194203          else: 
    195204            distString = "" 
    196  
    197           note = "<sub> tap this box to reroute</sub>" 
    198           message = distString + "\n" + message + "\n\n" + note 
    199  
    200           border = min(w/30.0,h/30.0) 
     205            currentDistString = "" 
     206            routeLengthString = "" 
     207 
     208          # TODO: find why there needs to be a newline at the end 
     209          message = "%s : %s\n" % (distString, message) 
     210 
     211          border = min(bw/50.0,bh/50.0) 
     212          # compute how much space is actually available for the text 
     213          usableWidth = bw-2*border 
     214          usableHeight = bh-6*border-buttonStripOffset 
     215          layout.set_width(int(usableWidth*pango.SCALE)) 
     216          layout.set_wrap(pango.WRAP_WORD) 
    201217          layout.set_markup(message) 
    202           layout.set_font_description(pango.FontDescription("Sans Serif 20")) 
    203           # scale to text to fit into the box 
     218          layout.set_font_description(pango.FontDescription("Sans Serif 24")) #TODO: custom font size ? 
    204219          (lw,lh) = layout.get_size() 
    205220          if lw == 0 or lh == 0: 
     221            # no need to draw a zero are layout 
    206222            return 
    207           scale = float(pango.SCALE) 
    208           factor = min(((bw-2*border)/(lw/scale)),((bh-2*border-buttonStripOffset)/(lh/scale))) 
    209           factor = min(factor, 1.0) 
    210           cr.move_to(bx+border,by+border+buttonStripOffset) 
     223 
     224          # get coordinates for the area available for text 
     225          ulX,ulY = (bx+border,by+border+buttonStripOffset) 
     226          cr.move_to(ulX,ulY) 
    211227          cr.save() 
    212           cr.scale(factor,factor) 
     228          if lh > usableHeight: # is the rendered text larger than the usable area ? 
     229            clipHeight = 0 
     230            # find last completley visible line 
     231            cut = False 
     232            for id in range(0,layout.get_line_count()-1): 
     233              lineHeight = layout.get_line(id).get_pixel_extents()[1][3] 
     234              if clipHeight + lineHeight <= usableHeight: 
     235                clipHeight = clipHeight + lineHeight 
     236              else: 
     237                cut = True # signalize we cut off some lines 
     238                break 
     239             
     240            textEndY = by+border+clipHeight+buttonStripOffset 
     241 
     242            if cut: 
     243              """ notify the user that a part of the text was cut, 
     244              by drawing a red line and a scissors icon""" 
     245              # draw the red line 
     246              cr.set_source_rgb(1,0,0) 
     247              cr.set_line_width(bh*0.01) 
     248              cr.move_to(bx,textEndY) 
     249              cr.line_to(bx+bw,textEndY) 
     250              cr.stroke() 
     251              # draw the scissors icon 
     252              cutSide = bw/10 
     253              menus.drawButton(cr, bx+bw, textEndY-cutSide/2.0, cutSide, cutSide, "", "center:scissors_right;0>%s" % background, "turnByTurn:nop") 
     254              #TODO: show the whole message in a notifications after clicking the scossors 
     255              # (this needs line wrapping support in modRana notifications) 
     256 
     257 
     258            # clip out the overflowing part of the text 
     259            cr.rectangle(ulX,ulY,usableWidth,clipHeight) 
     260            cr.translate(ulX,ulY) 
     261            cr.clip() 
     262 
     263          cr.set_source_rgba(*self.navigationBoxText) 
    213264          pg.show_layout(layout) 
    214265          cr.restore() 
     266 
     267          # use the bottom of the infobox to display info 
     268          (bottomX,bottomY) = (bx, by+bh-6*border) 
     269          note = "%s/%s, %d/%d   <sub> tap this box to reroute</sub>" % (currentDistString, routeLengthString, self.currentStepIndex+1,len(self.steps)) 
     270          menus.drawText(cr, "%s" % note, bottomX, bottomY, bw, 6*border, 0, rgbaColor=self.navigationBoxText) 
    215271          # make clickable 
    216272          clickHandler = self.m.get('clickHandler', None) 
     
    224280 
    225281          # * previous turn button 
    226           menus.drawButton(cr, bx, by, switchButtonWidth, buttonStripOffset, "#previous", parametricIconName, "turnByTurn:switchToPreviousTurn") 
     282          menus.drawButton(cr, bx, by, switchButtonWidth, buttonStripOffset, "", "center:less;0.1>%s" % background, "turnByTurn:switchToPreviousTurn") 
    227283          # * next turn button 
    228           menus.drawButton(cr, bx+switchButtonWidth, by, switchButtonWidth, buttonStripOffset, "#next", parametricIconName, "turnByTurn:switchToNextTurn") 
     284          menus.drawButton(cr, bx+switchButtonWidth, by, switchButtonWidth, buttonStripOffset, "", "center:more;0.1>%s" % background, "turnByTurn:switchToNextTurn") 
    229285          # * hide button 
    230           menus.drawButton(cr, bx+2*switchButtonWidth, by, hideButtonWidth, buttonStripOffset, "#hide", parametricIconName, "turnByTurn:toggleBoxHiding") 
     286          menus.drawButton(cr, bx+2*switchButtonWidth, by, hideButtonWidth, buttonStripOffset, "", "center:hide;0.1>%s" % background, "turnByTurn:toggleBoxHiding") 
    231287 
    232288 
     
    343399        self.sendMessage('notification:use at own risk, watch for cliffs, etc.#2') 
    344400        route = dirs['Directions']['Routes'][0] 
     401        # for some reason the combined distance does not account for the last step 
     402        self.mRouteLength = route['Distance']['meters'] + route['Steps'][-1]["Distance"]["meters"] 
    345403        self.steps = [] 
     404        mDistanceFromStart = route['Steps'][-1]["Distance"]["meters"] 
    346405        for step in route['Steps']: 
    347406          step['currentDistance'] = None # add the currentDistance key 
     407          # add and compute the distance from start 
     408          step['mDistanceFromStart'] = mDistanceFromStart 
     409          mDistanceFromLast = step["Distance"]["meters"] 
     410          mDistanceFromStart = mDistanceFromStart + mDistanceFromLast 
    348411          self.steps.append(step) 
    349412        self.steps = dirs['Directions']['Routes'][0]['Steps'] 
Note: See TracChangeset for help on using the changeset viewer.