Better horizontal candidate list rendering.
authorDaniel Wyatt
Sun, 28 Nov 2010 22:30:16 -0500
changeset 49163617cec7f0ee
parent 4915 834ce48a19c2
child 4917 7dafe21ca5d4
Better horizontal candidate list rendering.
Added horzcandspacing constant to add space between horizontal candidates.
src/video/win32/SDL_win32keyboard.c
     1.1 --- a/src/video/win32/SDL_win32keyboard.c	Sun May 09 12:58:58 2010 +0800
     1.2 +++ b/src/video/win32/SDL_win32keyboard.c	Sun Nov 28 22:30:16 2010 -0500
     1.3 @@ -1382,8 +1382,9 @@
     1.4  static void
     1.5  IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc)
     1.6  {
     1.7 -    int i = 0;
     1.8 +    int i, j;
     1.9      SIZE size = {0};
    1.10 +    SIZE candsizes[MAX_CANDLIST];
    1.11      SIZE maxcandsize = {0};
    1.12      HBITMAP hbm = NULL;
    1.13      BYTE *bits = NULL;
    1.14 @@ -1404,6 +1405,7 @@
    1.15      const COLORREF selbordercolor = RGB(0x84, 0xAC, 0xDD);
    1.16      const COLORREF selfillcolor = RGB(0xD2, 0xE6, 0xFF);
    1.17      const COLORREF seltextcolor = RGB(0, 0, 0);
    1.18 +    const int horzcandspacing = 5;
    1.19  
    1.20      HPEN listpen = listborder != 0 ? CreatePen(PS_SOLID, listborder, listbordercolor) : (HPEN)GetStockObject(NULL_PEN);
    1.21      HBRUSH listbrush = CreateSolidBrush(listfillcolor);
    1.22 @@ -1421,32 +1423,51 @@
    1.23          if (!*s)
    1.24              break;
    1.25  
    1.26 -        GetTextExtentPoint32W(hdc, s, SDL_wcslen(s), &size);
    1.27 -        maxcandsize.cx = SDL_max(maxcandsize.cx, size.cx);
    1.28 -        maxcandsize.cy = SDL_max(maxcandsize.cy, size.cy);
    1.29 +        GetTextExtentPoint32W(hdc, s, SDL_wcslen(s), &candsizes[i]);
    1.30 +        maxcandsize.cx = SDL_max(maxcandsize.cx, candsizes[i].cx);
    1.31 +        maxcandsize.cy = SDL_max(maxcandsize.cy, candsizes[i].cy);
    1.32  
    1.33      }
    1.34 -    if (!vertical)
    1.35 -        SDL_swap(maxcandsize.cx, maxcandsize.cy);
    1.36 -
    1.37 -    size.cx =
    1.38 -        (listborder * 2) +
    1.39 -        (listpadding * 2) +
    1.40 -        (candmargin * 2) +
    1.41 -        (candborder * 2) +
    1.42 -        (candpadding * 2) +
    1.43 -        (maxcandsize.cx)
    1.44 +    if (vertical) {
    1.45 +        size.cx =
    1.46 +            (listborder * 2) +
    1.47 +            (listpadding * 2) +
    1.48 +            (candmargin * 2) +
    1.49 +            (candborder * 2) +
    1.50 +            (candpadding * 2) +
    1.51 +            (maxcandsize.cx)
    1.52 +            ;
    1.53 +        size.cy =
    1.54 +            (listborder * 2) +
    1.55 +            (listpadding * 2) +
    1.56 +            ((candcount + 1) * candmargin) +
    1.57 +            (candcount * candborder * 2) +
    1.58 +            (candcount * candpadding * 2) +
    1.59 +            (candcount * maxcandsize.cy)
    1.60 +            ;
    1.61 +    }
    1.62 +    else {
    1.63 +        size.cx =
    1.64 +            (listborder * 2) +
    1.65 +            (listpadding * 2) +
    1.66 +            ((candcount + 1) * candmargin) +
    1.67 +            (candcount * candborder * 2) +
    1.68 +            (candcount * candpadding * 2) +
    1.69 +            ((candcount - 1) * horzcandspacing);
    1.70          ;
    1.71 -    size.cy =
    1.72 -        (listborder * 2) +
    1.73 -        (listpadding * 2) +
    1.74 -        ((candcount + 1) * candmargin) +
    1.75 -        (candcount * candborder * 2) +
    1.76 -        (candcount * candpadding * 2) +
    1.77 -        (candcount * maxcandsize.cy)
    1.78 -        ;
    1.79 -    if (!vertical)
    1.80 -        SDL_swap(size.cx, size.cy);
    1.81 +
    1.82 +        for (i = 0; i < candcount; ++i)
    1.83 +            size.cx += candsizes[i].cx;
    1.84 +
    1.85 +        size.cy =
    1.86 +            (listborder * 2) +
    1.87 +            (listpadding * 2) +
    1.88 +            (candmargin * 2) +
    1.89 +            (candborder * 2) +
    1.90 +            (candpadding * 2) +
    1.91 +            (maxcandsize.cy)
    1.92 +            ;
    1.93 +    }
    1.94  
    1.95      bits = StartDrawToBitmap(hdc, &hbm, size.cx, size.cy);
    1.96  
    1.97 @@ -1465,19 +1486,21 @@
    1.98          if (!*s)
    1.99              break;
   1.100  
   1.101 -        left = listborder + listpadding + candmargin;
   1.102 -        top = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * maxcandsize.cy);
   1.103 -        if (!vertical)
   1.104 -            SDL_swap(size.cx, size.cy);
   1.105 +        if (vertical) {
   1.106 +            left = listborder + listpadding + candmargin;
   1.107 +            top = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * maxcandsize.cy);
   1.108 +            right = size.cx - listborder - listpadding - candmargin;
   1.109 +            bottom = top + maxcandsize.cy + (candpadding * 2) + (candborder * 2);
   1.110 +        }
   1.111 +        else {
   1.112 +            left = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * horzcandspacing);
   1.113  
   1.114 -        right = size.cx - listborder - listpadding - candmargin;
   1.115 -        if (!vertical)
   1.116 -            SDL_swap(size.cx, size.cy);
   1.117 +            for (j = 0; j < i; ++j)
   1.118 +                left += candsizes[j].cx;
   1.119  
   1.120 -        bottom = top + maxcandsize.cy + (candpadding * 2) + (candborder * 2);
   1.121 -        if (!vertical) {
   1.122 -            SDL_swap(left, top);
   1.123 -            SDL_swap(right, bottom);
   1.124 +            top = listborder + listpadding + candmargin;
   1.125 +            right = left + candsizes[i].cx + (candpadding * 2) + (candborder * 2);
   1.126 +            bottom = size.cy - listborder - listpadding - candmargin;
   1.127          }
   1.128  
   1.129          if (i == videodata->ime_candsel) {