浙江大学竺可桢学院C程序设计基础(翁恺)行编辑器

**

浙江大学竺可桢学院C程序设计基础(翁恺)行编辑器

**
这次的作业有点难,时间也有点赶。写出来有点乱,可能没时间精校修整了,各位大佬见谅。如果有好的方法,非常欢迎和我交流,谢谢大家!
(要求和使用方法和学在浙大上的是一样的)

#include "acllib.h"
#include <stdio.h>
#include <math.h>

#define width 1200
#define length 300
#define start 20

int cnt_of_words = 0;
int length_of_words = 0;
char state_of_words = 1;//-1是小写,1是大写
char result[100];
double num_of_words = 1;
int state_of_carets = 1;//1是插入,-1是覆盖
double num_of_carets = 1;
int state_of_print = 0;

void mouse(int x, int y, int a, int b)
{   
    static int ox = -1;
    static int oy = -1;
    printf("%d %d %d %d \n", x, y, a ,b );
    beginPaint();
    line(ox, oy, x ,y);
    endPaint();
    ox = x;
    oy = y;
}

void key(int x, int y)
{   
    if((x == 20)&&(y == 1)) num_of_words = pow(-1,state_of_words++);
    if((x == 45)&&(y == 1)) num_of_carets = pow(-1,state_of_carets++);
    if((x == 13)&&(y == 0))printf("%s\n",result);//回车输出

    int i = 0;
    if(num_of_carets == 1)
    {
        if((x != 37)&&(x != 39)&&(cnt_of_words < length_of_words)\
                    &&(y == 0)&&(x != 20)&&(x != 45)&&(x != 8)&&(x != 46))//方向准备
        {
        for(i = length_of_words; i > cnt_of_words; i--)\
            result[i] = result[i-1];
        result[i] = 32;
        }
        else if((x != 37)&&(x != 39)&&(cnt_of_words > length_of_words)\
                    &&(y == 0)&&(x != 20)&&(x != 45)&&(x != 8)&&(x != 46))
        {
        for(i = length_of_words; i < cnt_of_words; i++)\
            result[i] = 32;
        length_of_words = cnt_of_words;
        }
    }
    

    int delete = 0;
    if(y == 0)//输入
    {
        if((x <= 'Z')&&(x >= 'A'))
        {
            length_of_words++;//字母
            if(num_of_words == -1)result[cnt_of_words++] = x - 'A' + 'a';
            else if(num_of_words == 1)result[cnt_of_words++] = x;
        }    
        else if(x == 32)
        {
            result[cnt_of_words++] = x;//空格
            length_of_words++;
        }
        else if((x <= '9')&&(x >= '0'))
        {
            result[cnt_of_words++] = x;//数字
            length_of_words++;
        }
        else if(x == 8)
        {
            for( delete = cnt_of_words - 1; delete <= length_of_words; delete++)
            {
                result[ delete ] = result[ delete + 1];
            }//Backspace
            length_of_words--;
            cnt_of_words--;
        }
        else if(x == 46)
        {
            for( delete = cnt_of_words; delete <= length_of_words; delete++)
            {
                result[ delete ] = result[delete + 1];
            }//Delete
            length_of_words--;
        }
    }

    if((x == 37)&&(y == 1))cnt_of_words--;//移动
    else if((x == 39)&&(y == 1))cnt_of_words++;

    beginPaint();
    clearDevice();
    if(num_of_carets == 1)setCaretSize(1,10);
    else if(num_of_carets == -1)setCaretSize(5,10);
    SetCaretPos(7 * cnt_of_words,1);
    showCaret();
    setPenWidth(20);
    paintText(0,0,result);
    endPaint();
}

int Setup()
{
    initWindow("Word", start, start, width, length);
    initConsole();
    
    beginPaint();
    //registerMouseEvent(mouse);
    registerKeyboardEvent(key);
    endPaint();
    return 0;
}

效果:
在这里插入图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaapengbo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值