home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
GRAPHWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-05
|
11KB
|
501 lines
#include <owl\owlpch.h>
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\dc.h>
#include <color.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
extern "C" {
#include "graph.h"
#include "view.h"
}
/*int Cols, Lines ;*/
int Display_X, Display_Y;
int FontH, FontV ;
#include "message.h"
extern TFrameWindow *MainWindow ;
extern TApplication *Application ;
extern TDC *ModelDC ;
extern TPalette *ModelPalet;
static TColor *col[17] ;
int lastcolor = -1;
int paletteowner = TRUE;
static int palettemode = FALSE;
//static PALETTEENTRY pal[17];
static PALETTEENTRY pal[1];
#define BUFFERPOINTS 512
static TPoint bufferpoint[BUFFERPOINTS], *ppoint;
static BYTE buffertype[BUFFERPOINTS], *ptype;
static int buffersize;
static int bufferflag;
static int polydrawflag;
static void buffer_flush();
static void buffer_append(int x1, int y1, int x2, int y2);
void graph_init()
{
int i ;
// カラーコードの設定
for( i = 0 ; i < 16 ; i++ )
{
if ( col[i] != NULL )
{
delete col[i] ;
}
}
for( i = 0 ; i < 8 ; ++i )
{
col[i] = new TColor( (i&2) ? 255 : 0, (i&4) ? 255 : 0, (i&1) ? 255 : 0 );
}
for( i = 8 ; i < 16 ; ++i )
{
col[i] = new TColor( 127, 255, 255 );
}
if (ModelDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) {
col[16] = new TColor(128, 128, 0);
palettemode = TRUE;
pal[0] = TPaletteEntry(255, 128, 128, PC_RESERVED);
ModelPalet = new TPalette(pal, 1);
ModelDC->SelectObject(*ModelPalet);
ModelDC->RealizePalette();
} else {
col[16] = new TColor(255^100, 255^100, 0);
palettemode = FALSE;
}
bufferflag = FALSE;
ppoint = bufferpoint;
ptype = buffertype;
}
void graph_exit()
{
}
void graph_line( int x1, int y1, int x2, int y2, int color )
{
if ( color < 16 )
{
if (lastcolor != color) {
if (bufferflag && buffersize > 0) {
buffer_flush();
}
if (palettemode && color == SELECT_COLOR) {
ModelDC->SelectObject(TPen(PALETTEINDEX(0)));
} else {
ModelDC->SelectObject( TPen( *(col[color]) ) );
}
lastcolor = color;
}
if (bufferflag) {
buffer_append(x1, y1, x2, y2);
} else {
ModelDC->MoveTo( x1, y1 );
ModelDC->LineTo( x2, y2 );
}
}
else
{
if (bufferflag && buffersize > 0) {
buffer_flush();
}
int rmode ;
rmode = ModelDC->SetROP2( R2_XORPEN );
if (lastcolor != 16) {
ModelDC->SelectObject( TPen(*(col[16])) );
lastcolor = 16;
}
ModelDC->MoveTo( x1, y1 );
ModelDC->LineTo( x2, y2 );
ModelDC->SetROP2( rmode );
}
}
void graph_dashline( int x1, int y1, int x2, int y2, int color )
{
if ( color < 16 )
{
if (bufferflag && buffersize > 0) {
buffer_flush();
}
ModelDC->MoveTo( x1, y1 );
if (lastcolor != color+32) {
ModelDC->SelectObject( TPen( *(col[color]), 1, PS_DOT ) );
lastcolor = color+32;
}
ModelDC->LineTo( x2, y2 );
}
}
void graph_cls( int color )
{
}
void graph_fill( int x1, int y1, int x2, int y2, int color )
{
if ( color < 16 )
{
if (x2 == x1+2 && y2 == y1+2) {
if (lastcolor != color) {
if (bufferflag && buffersize > 0) {
buffer_flush();
}
if (palettemode && color == SELECT_COLOR) {
ModelDC->SelectObject(TPen(PALETTEINDEX(0)));
} else {
ModelDC->SelectObject( TPen( *(col[color]) ) );
}
lastcolor = color;
}
if (bufferflag) {
buffer_append(x1, y1, x1, y2);
buffer_append(x1, y2, x2, y2);
buffer_append(x2, y2, x2, y1);
buffer_append(x2, y1, x1, y1);
} else {
TPoint pp[5];
pp[0].x = pp[1].x = pp[4].x = x1;
pp[2].x = pp[3].x = x2;
pp[0].y = pp[3].y = pp[4].y = y1;
pp[1].y = pp[2].y = y2;
ModelDC->Polyline(pp, 5);
}
} else if (palettemode && color == SELECT_COLOR) {
if (bufferflag && buffersize > 0) {
buffer_flush();
}
if (lastcolor != color+64) {
ModelDC->SelectObject(TPen(PALETTEINDEX(0)));
ModelDC->SelectObject(TBrush(PALETTEINDEX(0)));
lastcolor = color + 64;
}
ModelDC->Rectangle(x1, y1, x2+1, y2+1);
} else {
ModelDC->TextRect( x1, y1, x2+1, y2+1, *(col[color]) );
}
} else {
if (bufferflag && buffersize > 0) {
buffer_flush();
}
int rmode ;
rmode = ModelDC->SetROP2( R2_XORPEN );
if (lastcolor != 16 + 64) {
ModelDC->SelectObject(TPen(*(col[16])));
ModelDC->SelectObject(TBrush(*(col[16])));
lastcolor = 16 + 64;
}
if (x2 == x1+2 && y2 == y1+2) {
TPoint pp[5];
pp[0].x = pp[1].x = pp[4].x = x1;
pp[2].x = pp[3].x = x2;
pp[0].y = pp[3].y = pp[4].y = y1;
pp[1].y = pp[2].y = y2;
ModelDC->Polyline(pp, 5);
} else {
ModelDC->Rectangle(x1, y1, x2+1, y2+1);
}
ModelDC->SetROP2( rmode );
}
}
void graph_palet( int code, int g, int r, int b )
{
if (!palettemode || code != SELECT_COLOR) {
delete col[code] ;
col[code] = new TColor( r, g, b );
}
if (palettemode && code == SELECT_COLOR && paletteowner) {
pal[0] = TPaletteEntry(r, g, b, PC_RESERVED);
ModelPalet->AnimatePalette(0, 1, pal);
}
}
void graph_puts( char* str, int x, int y, int atr )
{
int rmode;
ModelDC->SetTextColor( *(col[atr & 15]) );
ModelDC->SetBkColor( *(col[atr >> 4]) );
rmode = ModelDC->SetBkMode(OPAQUE);
ModelDC->TextOut( x, y, str );
ModelDC->SetBkMode(rmode);
}
void graph_pattern( int x, int y, int color, short* pat, int h, int v )
{
#if 0
// const int PATTERN_MAXWIDTH = 64;
// const int PATTERN_MAXHEIGHT = 64;
// const int PATTERN_HBYTE = ((PATTERN_MAXWIDTH+3)/4)*4;
int rh = ((h-1)/4+1)*4;
// static TDib dib(PATTERN_MAXWIDTH, PATTERN_MAXHEIGHT, 256);
TDib dib(h, v, 256);
dib.SetColor(0, *col[color>>4]);
dib.SetColor(1, *col[color&15]);
unsigned char *p = (unsigned char *)dib.GetBits();
int i, j, k, hword, hh;
int a;
hword = ( h + 15 ) / 16 ;
p += rh*(v-1);
// p += PATTERN_HBYTE * (PATTERN_MAXHEIGHT-1);
for( i = 0 ; i < v ; i++ )
{
hh = h;
for( j = 0 ; j < hword ; j++ )
{
a = *pat++ & 0xffff ;
for( k = 0 ; k < 16 && k < hh ; k++ )
{
if ( a & 0x8000 )
*p++ = 1;
else
*p++ = 0 ;
a += a ;
}
hh -= 16 ;
}
p += (rh-h) - 2 * rh;
// p += (PATTERN_HBYTE - h) - 2 * PATTERN_HBYTE;
}
// dib.ChangeModeToPal(*ModelPalet);
ModelDC->SetDIBitsToDevice(TRect(x,y,x+h,y+v), TPoint(0,0),dib);
#else
int i, j, k, hword, hh;
int a;
hword = ( h + 15 ) / 16 ;
graph_fill(x, y, x+h-1, y+v-1, color & 15);
// ModelDC->SelectObject(TPen(*(col[color>>4])));
// ModelDC->SelectObject(TBrush(*(col[color>>4])));
// lastcolor = -1;
for( i = 0 ; i < v ; i++ )
{
hh = h;
for( j = 0 ; j < hword ; j++ )
{
a = *pat++ & 0xffff ;
for( k = 0 ; k < 16 && k < hh ; k++ )
{
if ((a & 0x8000) == 0) {
// ModelDC->Rectangle(x+j*16+k, y+i, x+j*16+k+1, y+i+1);
ModelDC->TextRect(x+j*16+k, y+i, x+j*16+k+1, y+i+1, *(col[color>>4]));
}
a += a ;
}
hh -= 16 ;
}
}
#endif
}
void graph_pattern2( int x, int y, int color, short* pat, int h, int v )
{
}
void graph_pattern_xor( int x, int y, int color, short* pat, int h, int v )
{
}
/* ボタン表示 */
void graph_box( int x1, int y1, int x2, int y2, int sw )
{
if ( sw )
{
#if 0
graph_line( x1, y1, x2, y1, 7 );
graph_fill( x1, y1, x1+1, y2, 7 );
graph_line( x1, y2, x2, y2, 0 );
graph_line( x2, y1, x2, y2, 0 );
#else
graph_line( x1+1, y1, x2-1, y1, 7 );
graph_line( x1, y1+1, x1, y2-1, 7 );
graph_line( x1+1, y2, x2-1, y2, 0 );
graph_line( x2, y1+1, x2, y2-1, 0 );
#endif
}
else
{
#if 0
graph_line( x1, y1, x2, y1, 0 );
graph_line( x1, y1, x1, y2, 0 );
graph_line( x1, y2, x2, y2, 7 );
graph_fill( x2-1, y1, x2, y2, 7 );
#else
graph_line( x1+1, y1, x2-1, y1, 0 );
graph_line( x1, y1+1, x1, y2-1, 0 );
graph_line( x1+1, y2, x2-1, y2, 7 );
graph_line( x2, y1+1, x2, y2-1, 7 );
#endif
}
}
int graph_push(int, int, int, int )
{
return FALSE;
}
int graph_pop(void)
{
return FALSE;
}
#if 0
TDC *backupDC = NULL;
TBitmap *bufferbitmap;
#endif
static void buffer_flush()
{
if (buffersize > 0) {
#if 0
printf("flush %d\n", buffersize);
int i;
for (i = 0; i < buffersize; i++) {
if (buffertype[i] == PT_MOVETO) {
printf("MoveTo(%d,%d)\n", bufferpoint[i].x, bufferpoint[i].y);
} else {
printf("LineTo(%d,%d)\n", bufferpoint[i].x, bufferpoint[i].y);
}
}
printf("->\n");
#endif
if (ModelDC->PolyDraw(bufferpoint, buffertype, buffersize) == FALSE) {
TPoint *pbegin, *pend;
BYTE *pt;
int i, size;;
pbegin = bufferpoint;
pend = pbegin+1;
size = 1;
pt = buffertype+1;
for (i = buffersize-1; i > 0; i--) {
if (*pt == PT_MOVETO) {
ModelDC->Polyline(pbegin, size);
#if 0
printf("MoveTo(%d,%d)\n", pbegin[0].x, pbegin[0].y);
for (int j = 1; j < size; j++) {
printf("LineTo(%d,%d)\n", pbegin[j].x, pbegin[j].y);
}
#endif
pbegin = pend;
size = 0;
}
pt++;
pend++;
size++;
}
if (size > 0) {
ModelDC->Polyline(pbegin, size);
#if 0
printf("MoveTo(%d,%d)\n", pbegin[0].x, pbegin[0].y);
for (int j = 1; j < size; j++) {
printf("LineTo(%d,%d)\n", pbegin[j].x, pbegin[j].y);
}
#endif
}
}
buffersize = 0;
ppoint = bufferpoint;
ptype = buffertype;
}
}
static void buffer_append(int x1, int y1, int x2, int y2)
{
if (buffersize > BUFFERPOINTS-2) {
buffer_flush();
}
if (buffersize > 0 && ppoint[-1].x == x1 && ppoint[-1].y == y1) {
ppoint->x = x2;
ppoint->y = y2;
ppoint++;
*ptype++ = PT_LINETO;
buffersize++;
} else if (buffersize > 0 && ppoint[-1].x == x2 && ppoint[-1].y == y2) {
ppoint->x = x1;
ppoint->y = y1;
ppoint++;
*ptype++ = PT_LINETO;
buffersize++;
} else {
ppoint->x = x1;
ppoint->y = y1;
ppoint++;
*ptype++ = PT_MOVETO;
ppoint->x = x2;
ppoint->y = y2;
ppoint++;
*ptype++ = PT_LINETO;
buffersize+=2;
}
}
int graph_buffer_start()
{
#if 0
if (backupDC == NULL) {
backupDC = ModelDC;
ModelDC = new TMemoryDC(*backupDC);
TRect rect=backupDC->GetClipBox();
//printf("Alloc MemoryDC(%d,%d)\n", rect.right, rect.bottom);
// bufferbitmap = new TBitmap(*backupDC, rect.right, rect.bottom);
bufferbitmap = new TBitmap(*backupDC, x2-x1+1, y2-y1+1);
ModelDC->SetWindowOrg(TPoint(x1,y1));
// ModelDC->SetViewportOrg(TPoint(x1,y1));
ModelDC->SelectObject(*bufferbitmap);
if (ModelPalet != NULL) {
ModelDC->SelectObject(*ModelPalet);
ModelDC->RealizePalette();
}
ModelDC->SetBkMode(TRANSPARENT);
lastcolor = -1;
}
#endif
bufferflag = TRUE;
return TRUE;
}
#if 0
void graph_buffer_draw(int x1, int y1, int x2, int y2)
{
printf("buffer_draw(%d,%d)-(%d,%d) %d\n", x1, y1, x2, y2, (int)backupDC);
if (backupDC != NULL) {
backupDC->BitBlt(x1, y1, x2-x1+1, y2-y1+1, *ModelDC, x1, y1, SRCCOPY);
}
}
#endif
void graph_buffer_end(void)
{
if (bufferflag) {
buffer_flush();
}
bufferflag = FALSE;
#if 0
if (backupDC != NULL) {
printf("Free MemoryDC\n");
delete ModelDC;
ModelDC = backupDC;
backupDC = NULL;
lastcolor = -1;
}
#endif
}