Example #1
0
*/	RXIEXT int RXD_Text(int cmd, RXIFRM *frm, REBCEC *ctx)
/*
**		DRAW command dispatcher.
**
***********************************************************************/
{
	switch (cmd) {

    case CMD_TEXT_INIT_WORDS:
        //temp hack - will be removed later
        text_ext_words = RL_MAP_WORDS(RXA_SERIES(frm,1));
        break;

    case CMD_TEXT_ANTI_ALIAS:
        rt_anti_alias(ctx->envr, RXA_LOGIC(frm, 1));
        break;

    case CMD_TEXT_BOLD:
        rt_bold(ctx->envr, RXA_LOGIC(frm, 1));
        break;

    case CMD_TEXT_CARET:
        {
            RXIARG val;
            u32 *words, *w;
            REBSER *obj;
            REBCNT type;
            REBXYF caret, highlightStart, highlightEnd;
            REBXYF *pcaret = 0, *phighlightStart = 0;
            obj = RXA_OBJECT(frm, 1);
//Reb_Print("RXI_WORDS_OF_OBJECT() called\n");
            words = RL_WORDS_OF_OBJECT(obj);
//Reb_Print("RXI_WORDS_OF_OBJECT() OK\n");
            w = words;

            while (type = RL_GET_FIELD(obj, w[0], &val))
            {
//                RL_Print("word: %d %d %d\n", w[0],w[1], (REBYTE)w[1]);
                switch(RL_FIND_WORD(text_ext_words,w[0]))
                {
                    case W_TEXT_CARET:
                        if (type == RXT_BLOCK){
                            REBSER* block = val.series;
                            REBINT len = RL_SERIES(block, RXI_SER_TAIL);
                            if (len > 1){
                                RXIARG pos, elem;
                                if (
                                    RL_GET_VALUE(block, 0, &pos) == RXT_BLOCK &&
                                    RL_GET_VALUE(block, 1, &elem) == RXT_STRING
                                ){
                                    caret.x = 1 + pos.index;
                                    caret.y = 1 + elem.index;
                                    pcaret = ⁁
                                }
                            }
                        }
                        break;

                    case W_TEXT_HIGHLIGHT_START:
                        if (type == RXT_BLOCK){
                            REBSER* block = val.series;
                            REBINT len = RL_SERIES(block, RXI_SER_TAIL);
                            if (len > 1){
                                RXIARG pos, elem;
                                if (
                                    RL_GET_VALUE(block, 0, &pos) == RXT_BLOCK &&
                                    RL_GET_VALUE(block, 1, &elem) == RXT_STRING
                                ){
                                    highlightStart.x = 1 + pos.index;
                                    highlightStart.y = 1 + elem.index;
                                    phighlightStart = &highlightStart;
                                }
                            }
                        }
                        break;

                    case W_TEXT_HIGHLIGHT_END:
                        if (type == RXT_BLOCK){
                            REBSER* block = val.series;
                            REBINT len = RL_SERIES(block, RXI_SER_TAIL);
                            if (len > 1){
                                RXIARG pos, elem;
                                if (
                                    RL_GET_VALUE(block, 0, &pos) == RXT_BLOCK &&
                                    RL_GET_VALUE(block, 1, &elem) == RXT_STRING
                                ){
                                    highlightEnd.x = 1 + pos.index;
                                    highlightEnd.y = 1 + elem.index;
                                }
                            }
                        }
                        break;
                }

                w++;
            }
            OS_Free(words);
            rt_caret(ctx->envr, pcaret, phighlightStart, highlightEnd);
        }

        break;

    case CMD_TEXT_CENTER:
        rt_center(ctx->envr);
        break;

    case CMD_TEXT_COLOR:
        rt_color(ctx->envr, RXA_TUPLE(frm,1) + 1);
       break;

    case CMD_TEXT_DROP:
        rt_drop(ctx->envr, RXA_INT32(frm,1));
        break;

    case CMD_TEXT_FONT:
        {
            RXIARG val;
            u32 *words,*w;
            REBSER *obj;
            REBCNT type;
            REBFNT *font = rt_get_font(ctx->envr);

            obj = RXA_OBJECT(frm, 1);
            words = RL_WORDS_OF_OBJECT(obj);
            w = words;

            while (type = RL_GET_FIELD(obj, w[0], &val))
            {
                switch(RL_FIND_WORD(text_ext_words,w[0]))
                {
                    case W_TEXT_NAME:
                        if (type == RXT_STRING){
                            wchar_t* str;
                            REBCNT gc = TRUE;
                            if (RL_GET_STRING(val.series, 0 , (void*)&str) < 0){
                                size_t newSize = mbstowcs(NULL, (char*)str, 0) + 1;
                                size_t origsize = strlen((char*)str) + 1;
                                //note: following string will be deallocated by the rich text module
                                wchar_t* wstr = OS_Make(newSize * sizeof( wchar_t ));
                                mbstowcs(wstr, (char*)str, newSize);
                                str = wstr;
                                gc = FALSE;
                            }
                            font->name = str;
                            font->name_gc = gc;
                        }
                        break;

                    case W_TEXT_STYLE:
                        switch(type)
                        {
                            case RXT_WORD:
                            {
                                u32 styleWord = RL_FIND_WORD(text_ext_words,val.int32a);
                                if (styleWord) rt_set_font_styles(font, styleWord);
                            }
                            break;

                            case RXT_BLOCK:
                            {
                                RXIARG styleVal;
                                REBCNT styleType;
                                REBCNT n;
                                u32 styleWord;
                                for (n = 0; styleType = RL_GET_VALUE(val.series, n, &styleVal); n++) {
                                    if (styleType == RXT_WORD) {
                                        styleWord = RL_FIND_WORD(text_ext_words,styleVal.int32a);
                                        if (styleWord) rt_set_font_styles(font, styleWord);
                                    }
                                }
                            }
                            break;
                        }
                        break;

                    case W_TEXT_SIZE:
                        if (type == RXT_INTEGER)
                            font->size = val.int64;
                        break;

                    case W_TEXT_COLOR:
                        if (type == RXT_TUPLE)
                            memcpy(font->color,val.bytes + 1 , 4);
                        break;

                    case W_TEXT_OFFSET:
                        if (type == RXT_PAIR) {
                            font->offset_x = val.pair.x;
                            font->offset_y = val.pair.y;
                        }
                        break;

                    case W_TEXT_SPACE:
                        if (type == RXT_PAIR) {
                            font->space_x = val.pair.x;
                            font->space_y = val.pair.y;
                        }
                        break;

                    case W_TEXT_SHADOW:
                        switch(type)
                        {
                            case RXT_PAIR:
                            {
                                font->shadow_x = val.pair.x;
                                font->shadow_y = val.pair.y;
                            }
                            break;

                            case RXT_BLOCK:
                            {
                                RXIARG shadowVal;
                                REBCNT shadowType;
                                REBCNT n;
                                for (n = 0; shadowType = RL_GET_VALUE(val.series, n, &shadowVal); n++) {
                                    switch (shadowType)
                                    {
                                        case RXT_PAIR:
                                            font->shadow_x = shadowVal.pair.x;
                                            font->shadow_y = shadowVal.pair.y;
                                            break;

                                        case RXT_TUPLE:
                                            memcpy(font->shadow_color,shadowVal.bytes + 1 , 4);
                                            break;

                                        case RXT_INTEGER:
                                            font->shadow_blur = shadowVal.int64;
                                            break;
                                    }
                                }
                            }
                            break;
                        }
                        break;
                }

                w++;
            }
            OS_Free(words);
            rt_font(ctx->envr, font);
        }
        break;

    case CMD_TEXT_ITALIC:
        rt_italic(ctx->envr, RXA_LOGIC(frm, 1));
        break;

    case CMD_TEXT_LEFT:
        rt_left(ctx->envr);
        break;

	case CMD_TEXT_NEWLINE:
        rt_newline(ctx->envr, ctx->index + 1);
		break;

    case CMD_TEXT_PARA:
        {
            RXIARG val;
            u32 *words,*w;
            REBSER *obj;
            REBCNT type;
            REBPRA *para = rt_get_para(ctx->envr);

            obj = RXA_OBJECT(frm, 1);
            words = RL_WORDS_OF_OBJECT(obj);
            w = words;

            while (type = RL_GET_FIELD(obj, w[0], &val))
            {
                switch(RL_FIND_WORD(text_ext_words,w[0]))
                {
                    case W_TEXT_ORIGIN:
                       if (type == RXT_PAIR) {
                            para->origin_x = val.pair.x;
                            para->origin_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_MARGIN:
                       if (type == RXT_PAIR) {
                            para->margin_x = val.pair.x;
                            para->margin_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_INDENT:
                       if (type == RXT_PAIR) {
                            para->indent_x = val.pair.x;
                            para->indent_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_TABS:
                       if (type == RXT_INTEGER) {
                            para->tabs = val.int64;
                        }
                        break;
                    case W_TEXT_WRAPQ:
                       if (type == RXT_LOGIC) {
                            para->wrap = val.int32a;
                        }
                        break;
                    case W_TEXT_SCROLL:
                       if (type == RXT_PAIR) {
                            para->scroll_x = val.pair.x;
                            para->scroll_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_ALIGN:
                        if (type == RXT_WORD) {
                            para->align = RL_FIND_WORD(text_ext_words,val.int32a);
                        }
                        break;
                    case W_TEXT_VALIGN:
                        if (type == RXT_WORD) {
                            para->valign = RL_FIND_WORD(text_ext_words,val.int32a);
                        }
                        break;
                }

                w++;
            }
            OS_Free(words);
            rt_para(ctx->envr, para);
        }
        break;

    case CMD_TEXT_RIGHT:
        rt_right(ctx->envr);
        break;

	case CMD_TEXT_SCROLL:
		rt_scroll(ctx->envr, RXA_PAIR(frm, 1));
		break;

    case CMD_TEXT_SHADOW:
        rt_shadow(ctx->envr, RXA_PAIR(frm, 1), RXA_TUPLE(frm,2) + 1, RXA_INT32(frm,3));
        break;

	case CMD_TEXT_SIZE:
		rt_font_size(ctx->envr, RXA_INT32(frm,1));
		break;

    case CMD_TEXT_TEXT:
        {
            REBCHR* str;
            REBCNT gc = TRUE;
            if (RL_GET_STRING(RXA_SERIES(frm, 1), 0 , (void*)&str) < 0){
                size_t newSize = mbstowcs(NULL, (char*)str, 0) + 1;
                size_t origsize = strlen((char*)str) + 1;
                //note: following string will be deallocated by the rich text module
                wchar_t* wstr = OS_Make(newSize * sizeof( wchar_t ));
                mbstowcs(wstr, (char*)str, newSize);
                str = (REBCHR*)wstr;
                gc = FALSE;
            }
            rt_text(ctx->envr, str, ctx->index + 2, gc);
        }
        break;

    case CMD_TEXT_UNDERLINE:
        rt_underline(ctx->envr, RXA_LOGIC(frm, 1));
		break;

	default:
		return RXR_NO_COMMAND;
	}
    return RXR_UNSET;
}
Example #2
0
RXIEXT int RX_Call(int cmd, RXIFRM *frm, REBCEC *ctx) {
	REBYTE *str;

	switch (cmd) {

	case 0:
		RXA_INT64(frm, 1) = 0;
		RXA_TYPE(frm, 1) = RXT_INTEGER;
		break;

	case 1:
		break; // same as arg

	case 2:
		RXA_INT64(frm, 1) = RXA_INT64(frm, 2);
		RXA_TYPE(frm, 1)  = RXA_TYPE(frm, 2);
		break;

	case 3:
		RXA_WORD(frm, 1) = RL_MAP_WORD("system"); //?? is frame always long enough??
		RXA_TYPE(frm, 1) = RXT_WORD;
		break;

	case 4:
		RL_GET_STRING(RXA_SERIES(frm, 1), 0, (void*)(&str)); // latin-1 only for test
		RXA_WORD(frm, 1) = RL_MAP_WORD(str);
		RXA_TYPE(frm, 1) = RXT_WORD;
		break;

	case 5:
		RXA_TYPE(frm, 1) = RL_GET_FIELD(RXA_OBJECT(frm, 1), RXA_WORD(frm, 2), &RXA_ARG(frm, 1));
		break;

	case 6:
		RXA_TYPE(frm, 1) = Test_Sync_Callback(RXA_OBJECT(frm, 1), RXA_WORD(frm, 2), &RXA_ARG(frm, 1));
		break;

	case 7:
		RXA_LOGIC(frm, 1) = Test_Async_Callback(RXA_OBJECT(frm, 1), RXA_WORD(frm, 2));
		RXA_TYPE(frm, 1) = RXT_LOGIC;
		break;

	case 8:
		RXA_TYPE(frm, 1) = RXT_IMAGE;
		RXA_SERIES(frm, 1) = RL_MAKE_IMAGE(2, 3);
		break;

	case 9:
		{
			REBCEC cec;
			cec.envr = 0;
			cec.block = RXA_SERIES(frm, 1);
			cec.index = 0;
			RL_DO_COMMANDS(RXA_SERIES(frm, 1), 0, &cec);
		}
		return RXR_UNSET;

	case 10:
		RXA_INT64(frm, 1) = (i64)(ctx ? ctx->index : -1);
		RXA_TYPE(frm, 1) = RXT_INTEGER;
		break;

	default:
		return RXR_NO_COMMAND;
	}
    return RXR_VALUE;
}