コード例 #1
0
ファイル: MenuWindow.c プロジェクト: ezc/fcitx
/*
* 显示菜单上面的文字信息,只需要指定窗口,窗口宽度,需要显示文字的上边界,字体,显示的字符串和是否选择(选择后反色)
* 其他都固定,如背景和文字反色不反色的颜色,反色框和字的位置等
*/
void XlibMenuPaintText(XlibMenu * menu, cairo_t* c, FcitxCairoTextContext* ctc, int shellindex, int line_y, int fontHeight)
{
    FcitxXlibWindow* window = (FcitxXlibWindow*) menu;
    FcitxClassicUI* classicui = window->owner;
    FcitxSkin *sc = &classicui->skin;

    cairo_save(c);
    if (GetMenuItem(menu->menushell, shellindex)->isselect == 0) {
        FcitxCairoTextContextOutputString(ctc, GetMenuItem(menu->menushell, shellindex)->tipstr, 15 , line_y, &sc->skinFont.menuFontColor[MENU_INACTIVE]);
    } else {
        cairo_set_operator(c, CAIRO_OPERATOR_OVER);
        fcitx_cairo_set_color(c, &sc->skinMenu.activeColor);
        cairo_rectangle(c, 0 , line_y, window->contentWidth, fontHeight + 4);
        cairo_fill(c);

        FcitxCairoTextContextOutputString(ctc, GetMenuItem(menu->menushell, shellindex)->tipstr, 15 , line_y, &sc->skinFont.menuFontColor[MENU_ACTIVE]);
    }
    cairo_restore(c);
}
コード例 #2
0
ファイル: skin.c プロジェクト: ezc/fcitx
SkinImage* LoadImageWithText(FcitxClassicUI* classicui, FcitxSkin* sc, const char* name, const char* text, int w, int h, boolean active)
{
    if (!text || *text == '\0')
        return NULL;

    UnloadSingleImage(sc, name);

    int len = fcitx_utf8_char_len(text);
    if (len == 1 && text[len] && fcitx_utf8_char_len(text + len) == 1)
        len = 2;

    char* iconText = strndup(text, len);

    FcitxLog(DEBUG, "%s", iconText);

    cairo_surface_t* newsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
    cairo_t* c = cairo_create(newsurface);

    int min = w > h? h: w;
    min = min * 0.7;

    cairo_set_operator(c, CAIRO_OPERATOR_SOURCE);
    cairo_set_source_rgba(c ,1, 1, 1, 0.0);
    cairo_paint(c);

    FcitxConfigColor color;
    if (sc->skinMainBar.bUseCustomTextIconColor) {
        if (active)
            color = sc->skinMainBar.textIconColor[0];
        else
            color = sc->skinMainBar.textIconColor[1];
    }
    else
        color = sc->skinFont.menuFontColor[1];

    int textw, texth;
    FcitxCairoTextContext* ctc = FcitxCairoTextContextCreate(c);
    FcitxCairoTextContextSet(ctc, classicui->font, min, false);
    FcitxCairoTextContextStringSizeStrict(ctc, iconText, &textw, &texth);

    FcitxCairoTextContextOutputString(ctc, iconText, (w - textw) * 0.5, 0, &color);

    FcitxCairoTextContextFree(ctc);

    cairo_destroy(c);
    SkinImage* image = fcitx_utils_malloc0(sizeof(SkinImage));
    image->name = strdup(name);
    image->image = newsurface;
    image->textIcon = true;
    HASH_ADD_KEYPTR(hh, sc->imageTable, image->name, strlen(image->name), image);
    return image;
}
コード例 #3
0
ファイル: InputWindow.c プロジェクト: Axure/fcitx
void InputWindowPaint(FcitxXlibWindow* window, cairo_t* c)
{
    InputWindow* inputWindow = (InputWindow*) window;
    FcitxClassicUI* classicui = window->owner;
    FcitxInstance* instance = classicui->owner;
    FcitxInputState* input = FcitxInstanceGetInputState(instance);
    FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
    FcitxSkin* sc = &window->owner->skin;

    FcitxMessages* msgup = inputWindow->msgUp;
    FcitxMessages* msgdown = inputWindow->msgDown;
    char **strUp = inputWindow->strUp;
    char **strDown = inputWindow->strDown;
    int *posUpX = inputWindow->posUpX, *posUpY = inputWindow->posUpY;
    int *posDownX = inputWindow->posDownX, *posDownY = inputWindow->posDownY;

    cairo_save(c);
    cairo_set_operator(c, CAIRO_OPERATOR_OVER);

    SkinImage* prev = LoadImage(sc, sc->skinInputBar.backArrow, false);
    SkinImage* next = LoadImage(sc, sc->skinInputBar.forwardArrow, false);

    inputWindow->prevRect.x1 = inputWindow->prevRect.y1 = inputWindow->prevRect.x2 = inputWindow->prevRect.y2 = 0;
    inputWindow->nextRect.x1 = inputWindow->nextRect.y1 = inputWindow->nextRect.x2 = inputWindow->nextRect.y2 = 0;

    if (FcitxCandidateWordHasPrev(candList)
        || FcitxCandidateWordHasNext(candList)
    ) {
        if (prev && next) {
            int x, y;
            x = window->contentWidth - sc->skinInputBar.iBackArrowX + window->background->marginRight - window->background->marginLeft;
            y = sc->skinInputBar.iBackArrowY - window->background->marginTop;
            cairo_set_source_surface(c, prev->image, x, y);
            if (FcitxCandidateWordHasPrev(candList)) {
                inputWindow->prevRect.x1 = x;
                inputWindow->prevRect.y1 = y;
                inputWindow->prevRect.x2 = x + cairo_image_surface_get_width(prev->image);
                inputWindow->prevRect.y2 = y + cairo_image_surface_get_height(prev->image);

                if (inputWindow->highlight == PREVNEXT_HIGHLIGHT(true)) {
                    cairo_paint_with_alpha(c, 0.7);
                } else {
                    cairo_paint(c);
                }
            }
            else {
                cairo_paint_with_alpha(c, 0.3);
            }

            x = window->contentWidth - sc->skinInputBar.iForwardArrowX + window->background->marginRight - window->background->marginLeft;
            y = sc->skinInputBar.iForwardArrowY - window->background->marginTop;
            cairo_set_source_surface(c, next->image, x, y);
            if (FcitxCandidateWordHasNext(candList)) {
                inputWindow->nextRect.x1 = x;
                inputWindow->nextRect.y1 = y;
                inputWindow->nextRect.x2 = x + cairo_image_surface_get_width(prev->image);
                inputWindow->nextRect.y2 = y + cairo_image_surface_get_height(prev->image);
                if (inputWindow->highlight == PREVNEXT_HIGHLIGHT(false)) {
                    cairo_paint_with_alpha(c, 0.7);
                } else {
                    cairo_paint(c);
                }
            } else {
                cairo_paint_with_alpha(c, 0.3);
            }
        }
    }
    cairo_restore(c);
    cairo_save(c);

    /* draw text */
    FcitxCairoTextContext* ctc = FcitxCairoTextContextCreate(c);
    int dpi = sc->skinFont.respectDPI? classicui->dpi : 0;
    FcitxCairoTextContextSet(ctc, window->owner->font, window->owner->fontSize > 0 ? window->owner->fontSize : sc->skinFont.fontSize, dpi);

    int i;
    for (i = 0; i < FcitxMessagesGetMessageCount(msgup) ; i++) {
        FcitxCairoTextContextOutputString(ctc, strUp[i], posUpX[i], posUpY[i], &sc->skinFont.fontColor[FcitxMessagesGetMessageType(msgup, i) % 7]);
        if (strUp[i] != FcitxMessagesGetMessageString(msgup, i))
            free(strUp[i]);
    }

    int candidateIndex = -1;
    for (i = 0; i < FcitxMessagesGetMessageCount(msgdown) ; i++) {

        if (FcitxMessagesGetMessageType(msgdown, i) == MSG_INDEX) {
            candidateIndex ++;
        }

        FcitxConfigColor color = sc->skinFont.fontColor[FcitxMessagesGetMessageType(msgdown, i) % 7];
        double alpha = 1.0;
        if (CANDIDATE_HIGHLIGHT(candidateIndex) == inputWindow->highlight) {
            /* cal highlight color */
            color.r = (color.r + 0.5) / 2;
            color.g = (color.g + 0.5) / 2;
            color.b = (color.b + 0.5) / 2;
            alpha = 0.8;
        }
        cairo_set_source_rgba(c, color.r, color.g, color.b, alpha);

        FcitxCairoTextContextOutputString(ctc, strDown[i], posDownX[i], posDownY[i], NULL);
        if (strDown[i] != FcitxMessagesGetMessageString(msgdown, i))
            free(strDown[i]);
    }
    FcitxCairoTextContextFree(ctc);

    cairo_restore(c);

    // draw cursor
    if (FcitxMessagesGetMessageCount(msgup) && FcitxInputStateGetShowCursor(input)) {
        cairo_save(c);
        int cursorY1, cursorY2;
        if (sc->skinFont.respectDPI) {
            cursorY1 = sc->skinInputBar.iInputPos;
            cursorY2 = sc->skinInputBar.iInputPos + inputWindow->fontHeight;
        }
        else {
            cursorY1 = sc->skinInputBar.iInputPos - inputWindow->fontHeight;
            cursorY2 = sc->skinInputBar.iInputPos;
        }

        fcitx_cairo_set_color(c, &sc->skinInputBar.cursorColor);
        cairo_set_line_width(c, 1);
        cairo_move_to(c, inputWindow->pixelCursorPos + 0.5, cursorY1);
        cairo_line_to(c, inputWindow->pixelCursorPos + 0.5, cursorY2);
        cairo_stroke(c);

        cairo_restore(c);
    }

    FcitxMessagesSetMessageChanged(msgup, false);
    FcitxMessagesSetMessageChanged(msgdown, false);
}