
Руководство программиста
Структурная схема программного комплекса (выше) включает 15 подчиненных программных модулей, расположенных на втором и третьем уровнях. Программные модули выполняют следующие функции (в скобках указаны имена процедур):
Меню (menu)- служит для выбора пользователем требуемого инструмента;
Инструменты (tools)- средства графического взаимодействия пользователя и программы;
Доп. Функции 1(edit)- средство редактирования результата работы графического редактора (копировать/вырезать, вставить);
Доп. Функции 2(file)- средство преобразования результата работы графического редактора (удалить, сохранить, открыть);
void screen(); /// рисует экран
void file_screen(); /// рисует меню
void file_control(void *buffer); /// меню, состоящее из создания, открытия и сохранения файла
void open_file(); /// панель инструментов и реализация рисования формы
void palette(); /// рисует палитрой
char another_shape(int x, int y); /// переключение форм и инструментов
void button(int x1,int y1,int x2,int y2,int col);
void active_collor(int x,int y); /// отображает активный цвет
void returnn(); /// вернуться к open_file function
Результат работы программы и анализ
Программа работает подобно программе «Paint» от Microsoft.
Сравнение с программой Microsoft “Paint”:
Руководство пользователя
1. Чтобы нарисовать некоторые элементы, а именно овал и прямоугольник, выполнить функции вырезать и копировать – нужно: выбрать соответствующий инструмент и нажать левой кнопкой мыши для того, чтобы отметить верхнюю левую границу рисунка, а затем нажать правой кнопкой мыши для отметки правой нижней границы рисунка.
2. Заливка закрашивает только те области, которые обрамлены чёрным цветом, иначе будет закрашен весь лист.
3. Функция «сохранить как .bmp» сохраняет файл в отдельной папке.
ТЕСТИРОВАНИЕ ПРОГРАММЫ
В следствии тестирования программы было выявлено то, что программа не всегда реагирует на нажатия мышки либо тачпада. Поэтому стоит нажать несколько раз, для устранения неполадки.
ВЫВОД
В ходе выполнения курсовой работы была создана программа, которая внешним видом и функционалом напоминает «Paint» времён Windows XP. Функционал не так обширен, как у «Paint», но основные функции присутствуют.
ИСПОЛЬЗУЕМАЯ ЛИТЕРАТУРА И ИСТОЧНИКИ
1.Лекции по предмету «Структурное Программирование»;
2.Сайты:
ru.stackoverflow.com;
www.cyberforum.ru;
www.c-cpp.ru;
code-live.ru.
ЛИСТИНГ ПРОГРАММЫ
Файл «head.h»
void screen(); ///screen drawing
void file_screen(); ///context menu drawing
void file_control(void *buffer); ///context menu consisting of creating, opening and saving a file
void open_file(); ///toolbar and shape drawing implementation
void palette(); ///palette drawing
char another_shape(int x, int y); ///switching shapes and tools
void button(int x1,int y1,int x2,int y2,int col);
void active_collor(int x,int y); ///display active color
void returnn(); ///return to open_file function
extern int a,b, x, y, leftcolor[15], xr, yr, act_col, coord1, coord2, tsize;
extern char ch;
Файл «main.cpp»
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include<math.h>
#include "head.h"
int a,b, xr, yr, act_col=0, coord1, coord2, tsize=3;
int x=0, y=0;
char ch;
int leftcolor[15];
int main(void)
{
initwindow(700, 540,"Windows BGI");
screen();
void *buffer;
unsigned size;
do
{
getmouseclick(WM_LBUTTONDOWN, xr,yr);
if((xr>660)&&(yr>0)&&(xr<700)&&(yr<24))
{
_Exit(0);
}
if((xr>600)&&(yr>25)&&(xr<700)&&(yr<50)) ///file button
{
size=imagesize(599, 50, 698, 167);
buffer=malloc(size);
getimage(599, 50, 698, 167, buffer);
file_screen();
file_control(buffer);
free(buffer);
}
}
while(ch!='e');
}
Файл «func.cpp»
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include<math.h>
#include "head.h"
void file_control(void *buffer)
{
do
{
getmouseclick(WM_LBUTTONDOWN, x,y);
if(x>660 && x<700 && y>0 && y<24)
{
_Exit(0);
}
if(x>560 && x<698 && y>50 && y<85) /// new file
{
readimagefile("file.bmp", 3, 27, 598, 508);
putimage(599, 50, buffer, COPY_PUT);
open_file();
}
else if(x>560 && y>87 && x<698 && y<125) ///open
{
readimagefile("file1.bmp", 3, 27, 598, 508);
putimage(599, 50, buffer, COPY_PUT);
open_file();
}
else if(x>560 && x<698 && y>127 && y<170) ///save
{
writeimagefile("file1.bmp", 3, 27, 598, 508);
putimage(599, 50, buffer, COPY_PUT);
open_file();
}
}
while(ch!='e');
}
void open_file()
{
void *buffer, *buffer1;
unsigned size, size1;
int maxx, maxy;
coord1=x;
coord2=y;
maxx = getmaxx( );
maxy = getmaxy( );
setcolor(0);
setlinestyle(0,0,0);
rectangle(2, 26, 598, 508);
do
{
if(x>660 && y>0 && x<700 && y<24)
{
_Exit(0);
}
if(x>600 && x<700 && y>25 && y<50) // we press file button
{
size=imagesize(599, 50, 698, 167);
buffer=malloc(size);
getimage(599, 50, 698, 167, buffer);
file_screen();
file_control(buffer);
free(buffer);
}
if(ch == 'o') ///clear screan
{
setfillstyle(1, 15);
bar(3, 27, 598, 508);
}
while(!ismouseclick(WM_LBUTTONDOWN))
{
delay(100);
}
getmouseclick(WM_LBUTTONDOWN,x,y);
if(!ismouseclick(WM_LBUTTONDOWN))
{
if(x>529 && x<700 && y>40 && y<500) ch=another_shape(x,y);
if(ch=='p') ///pen
{
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN,x,y);
int flag=1;
int tsize2=5;
do
{
getmouseclick(WM_MOUSEMOVE,x,y);
setfillstyle(1, act_col);
setlinestyle(0,1,tsize2);
if(x>2 && x<590 && y>26 && y<500)
bar(x, y, x+tsize2, y+tsize2);
flag=(ismouseclick(WM_LBUTTONDOWN));
getmouseclick(WM_LBUTTONUP, x, y);
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
returnn();
}
while(!flag);
}
if(ch=='f') ///fill
{
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
if(x>2 && x<590 && y>26 && y<500)
{
ismouseclick(WM_LBUTTONDOWN);
setfillstyle(1, act_col);
floodfill(x,y, 0);
}
}
if(ch=='y') ///eraser
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN,x,y);
int flag=1;
do
{
getmouseclick(WM_MOUSEMOVE,x,y);
setfillstyle(1, 15);
if(x>2 && x<580 && y>26 && y<493)
bar(x, y, x+16, y+16);
flag=(ismouseclick(WM_LBUTTONDOWN));
returnn();
}
while(!flag);
}
if(ch=='g') ///color picker
{
if(x>3 && x<596 && y>27 && y<508)
{
act_col=getpixel(x,y);
setfillstyle(1,act_col);
bar(635,515,690,535);
}
if(x>0 && x<510 && y>700 && y<540)
{
act_col=getpixel(x,y);
setfillstyle(1,act_col);
bar(635,515,690,535);
}
}
if ( ch == 'r' ) ///rectangle
{
while(ch=='r')
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN, x, y);
a=x,b=y;
delay(600);
getmouseclick(WM_LBUTTONUP, x, y);
setcolor(act_col);
setlinestyle(0,1,tsize);
if(x>2 && x<590 && y>26 && y<500)
{
rectangle(a,b,x,y);
}
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
returnn();
}
}
if ( ch == 'b' ) ///bar
{
while(ch=='b')
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN, x, y);
a=x,b=y;
delay(700);
getmouseclick(WM_LBUTTONUP, x, y);
setfillstyle(1,act_col);
if(x>2 && x<590 && y>26 && y<500)
{
bar(a,b,x,y);
}
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
returnn();
}
}
if ( ch == 'k') ///ellipse
{
while(ch=='k')
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN,x,y);
delay(700);
getmouseclick(WM_LBUTTONUP,coord1,coord2);
setlinestyle(0,0,tsize);
setcolor(act_col);
if(x>2 && x<590 && y>26 && y<500 && coord1>2 && coord1<590 && coord2>26 && coord2<500)
ellipse((x+coord1)/2,(y+coord2)/2,0,360,abs(x-coord1)/2,abs(y-coord2)/2);
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
returnn();
}
}
if( ch == 'j') ///filled ellipse
{
while(ch=='j')
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN,x,y);
delay(600);
getmouseclick(WM_LBUTTONUP,coord1,coord2);
setcolor(act_col);
if(x>2 && x<590 && y>26 && y<500 && coord1>2 && coord1<590 && coord2>26 && coord2<500)
{
fillellipse((x+coord1)/2,(y+coord2)/2,abs(x-coord1)/2,abs(y-coord2)/2);
}
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
returnn();
}
}
if(ch == 'c') ///circle
{
while(ch=='c')
{tsize=3;
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN,x,y);
delay(600);
getmouseclick(WM_LBUTTONUP,coord1,coord2);
int sqr=sqrt((coord1-x)*(coord1-x)+(coord2-y)*(coord2-y));
if(x>2 && x<590 && y>26 && y<500 && coord1>2 && coord1<590 && coord2>26 && coord2<50)
setlinestyle(0,0,tsize);
setcolor(act_col);
circle((coord1+x)/2,(coord2+y)/2,sqr/2);
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
returnn();
}
}
if ( ch == '3' ) ///bar3d
{
while(ch=='3')
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN, x, y);
a=x,b=y;
delay(800);
getmouseclick(WM_LBUTTONUP, x, y);
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
setcolor(act_col);
setlinestyle(0,1,tsize);
if(x>2 && x<590 && y>26 && y<500 && a>2 && a<590 && b>26 && b<500)
bar3d(a,b,x,y,20,1);
returnn();
}
}
if(ch=='l') /// line
{
while(ch=='l')
{
while(!ismouseclick(WM_LBUTTONDOWN)) {}
getmouseclick(WM_LBUTTONDOWN, x, y);
a=x,b=y;
delay(900);
getmouseclick(WM_LBUTTONUP, x, y);
if(x>0 && x<528 && y>510 && y<540)active_collor(x,y);
setcolor(act_col);
setlinestyle(0,1,tsize);
if(a>2 && a<590 && b>26 && b<500 && x>2 && x<590 && y>26 && y<500)
line(a,b,x,y);
returnn();
getmouseclick(WM_LBUTTONDOWN, x,y);
}
}
}
}
while(ch!='e');
}
char another_shape(int x, int y)
{
if(x>604 && x<647 && y>83 && y<127) ///pen
{
button(604, 83, 647, 127, 10);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'p';
}
if(x>652 && x<695 && y>83 && y<127) ///fill
{
button(652, 83, 695, 127, 10);
button(604, 83, 647, 127, 15);
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'f';
}
if(x>604 && x<647 && y>134 && y<180) ///eraser
{
button(604, 134, 647,180, 10);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'y';
}
if(x>608 && x<647 && y>214 && y<243) ///rectangle
{
button(608, 214, 647, 243, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'r';
}
if(x>650 && x<691 && y>214 && y<243) ///bar
{
button(650, 214, 691, 243, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'b';
}
if(x>608 && x<647 && y>245 && y<277) /// ellipse
{
button(608, 245, 647, 277, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'k';
}
if(x>650 && x<691 && y>245 && y<277) ///filled ellipse
{
button(650, 245, 691, 277, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'j';
}
if(x>608 && x<647 && y>279 && y<310) ///circle
{
button(608, 279, 647, 310, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'c';
}
if(x>650 && x<691 && y>279 && y<310) ///bar3d
{
button(650, 279, 691, 310, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(608, 312, 647, 340,7); //l
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return '3';
}
if(x>608 && x<647 && y>312 && y<340) ///line
{
button(608, 312, 647, 340, 5);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(633, 448, 692, 497, 15); //0
button(652, 134, 695,180, 15); //g
return 'l';
}
if(x>633 && x<692 && y>448 && y<497) ///clear screen
{
button(633, 448, 692, 497, 10);
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
button(652, 134, 695,180, 15); //g
return 'o';
}
if(x>652 && x<695 && y>134 && y<180) ///color picker
{
button(652, 134, 695,180, 10);
button(633, 448, 692, 497, 15); //o
button(604, 83, 647, 127, 15);
button(652, 83, 695, 127, 15); //f
button(604, 134, 647,180, 15); //y eras
button(608, 214, 647, 243, 7); //r
button(650, 214, 691, 243, 7); //b
button(608, 245, 647, 277, 7); //k ellip
button(650, 245, 691, 277, 7); //j f ellip
button(608, 279, 647, 310, 7); //c
button(650, 279, 691, 310, 7); //3d
button(608, 312, 647, 340,7); //l
return 'g';
}
}
void returnn()
{
getmouseclick(WM_LBUTTONDOWN, x,y);
if((x>535)&&(y>0)&&(x<700)&&(y<540))
{
open_file();
return;
}
}
Файл «draw.cpp»
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
#include<math.h>
#include "head.h"
void screen()
{
palette();
setcolor(8);
setlinestyle(0, 0, 5);
setfillstyle(1,10);
bar(0,0, 700, 25); //top panel
setfillstyle(1, 13);
bar(600, 25, 700, 540); // area tools, shapes etc
setfillstyle(1, 10);
bar(600, 25, 700, 50);//file
setlinestyle(0,0, 2);
rectangle(600, 25, 700, 50);
rectangle(600, 25, 700, 510);
rectangle(1, 1, 699, 539);
rectangle(0,509, 699, 539);
rectangle(0,0,700,25);
setbkcolor(13);
setcolor(15);
outtextxy(540, 515, "active collor :");
outtextxy(631, 61, "Tools");
outtextxy(629, 188, "Shapes");
settextstyle(10, 0,1);
setbkcolor(10);
setcolor(13);
outtextxy(632, 30, "File");
setfillstyle(1,15);
bar(604,210,695,346); //for shapes
setcolor(7);
rectangle(604,210,695,346);
readimagefile("exit.bmp", 673, 2, 695, 23);
readimagefile("pencil.bmp", 610, 90, 640, 120); button(604, 83, 647, 127, 15);
readimagefile("fill.bmp", 653, 89,692, 124); button(652, 83, 695, 127, 15);
readimagefile("eraser.bmp", 608, 139, 640, 175); button(604, 134, 647,180, 15);
readimagefile("pipette.bmp", 656, 139, 692, 175); button(652, 134, 695,180, 15);
readimagefile("rect.bmp", 610, 218, 645, 238); button(608, 214, 647, 243, 7);
readimagefile("bar.bmp", 653, 218 ,688, 238); button(650, 214, 691, 243, 7);
readimagefile("ellipse.bmp", 610, 250, 645, 272);button(608, 245, 647, 277, 7);
readimagefile("ellipse2.bmp", 653, 250, 688, 272);button(650, 245, 691, 277, 7);
readimagefile("circ.bmp", 613, 282, 640, 307); button(608, 279, 647, 310, 7);
readimagefile("bar3d.bmp", 656, 280, 692, 307); button(650, 279, 691, 310, 7);
readimagefile("line.bmp", 610, 312, 643, 340); button(608, 312, 647, 340, 7);
readimagefile("brush.bmp", 637, 450, 682, 495); button(633, 448, 692, 497, 15);
active_collor(x,y);
setfillstyle(5,12);
bar(636,516,690,535);
}
void file_screen()
{
setfillstyle(1,10);
setcolor(8);
setlinestyle(0, 0, 2);
bar(600, 51, 698, 167);
rectangle(600, 51, 698, 167);
setbkcolor(10);
setcolor(15);
settextstyle(10, 0,1);
outtextxy(607, 58, "new");
outtextxy(607, 98, "open");
outtextxy(607, 138, "save");
readimagefile("new.bmp", 670, 55, 690, 78);
readimagefile("open.bmp", 664, 94, 692, 122);
readimagefile("save.bmp", 664, 135, 695, 162);
}
void palette()
{
int left, top, c, color;
left=55;
top=514;
color = getcolor();
setcolor(8);
setfillstyle(1,13);
bar(0,510,700,540);
rectangle(0,510,700,540);
setcolor(15);
setbkcolor(13);
outtextxy(4,515,"Colors:");
for( c = 0 ; c <= 15 ; c++ )
{
setfillstyle(1, c);
bar(left, top, left+20, top+20);
setcolor(15);
rectangle(left, top, left+20, top+20);
leftcolor[c-1] = left;
left+=30;
}
setcolor(color);
}
void button(int x1,int y1,int x2,int y2,int col)
{
setcolor(col);
setlinestyle(0, 1, 1);
rectangle(x1,y1,x2,y2);
}
void active_collor(int x,int y)
{
act_col=getpixel(x,y);
setfillstyle(1,act_col);
bar(635,515,690,535);
setcolor(15);
setlinestyle(0, 1,tsize);
rectangle(635,515,690,535);
}