int disk_error_handler(int errval, int ax, int bp, int si) { rect R, R2; char tbuf[128]; int err; int centerx = sR.Xmax / 2; int centery = sR.Ymax / 2; int height = 2 * FontHeight + 10; int width = sR.Xmax / 2; R.Xmin = sR.Xmax / 4; R.Xmax = R.Xmin + width; R.Ymin = centery - height / 2; R.Ymax = R.Ymin + height; PushRect(&R, &err); if (ax < 0) sprintf(tbuf, "Device error %x: %x %p", errval, ax, MK_FP(bp, si)); else sprintf(tbuf, "Disk error on drive %c", 'A' + (ax & 0xff)); PenColor(MENUBACK); PaintRect(&R); PenColor(MENUTEXT); BackColor(MENUBACK); R2 = R; InsetRect(&R2, 2, 2); FrameRect(&R2); TextAlign(alignCenter, alignTop); MoveTo(centerx, R.Ymin + 4); DrawString(tbuf); MoveTo(centerx, R.Ymin + FontHeight + 4); DrawString("Hit any key to continue"); getch(); PopRect(&err); hardretn(-1); #pragma warn -rvl }
void drawChargeButton(void) { /* This one is a bit sneaky. We might not have a single charge... */ int i; HideCursor(); set_samecharges(); if (samecharges) { if (charge_thing == DIFFERENT) { RasterOp(zREPz); PenColor(BLUE); PaintRect(&chargeR); tools[0].t->value = chargeunit; CreateNumberToolTitle(tools[0].t, tools[0].text,WHITE,BLUE); mainR[5] = &tools[0].t->TB.nR; mainR[6] = &tools[0].t->mR; mainR[7] = &tools[0].t->pR; } else drawone(&ChargeTool,chargeunit); charge_thing = SAME; } else { if (charge_thing == SAME) { rect R = chargeR; RasterOp(zREPz); InsetRect(&R,-2,0); PenColor(BLUE); PaintRect(&R); PaintRadioButton(&chargeR,false,false,chargemsg); for(i=0;i<3;i++) mainR[i+5] = &chargeR; } charge_thing = DIFFERENT; } ShowCursor(); }
static void textbox(char **textlines) { int items = 0, i; int height, width; rect R; rect tR; int cx, cy; char *msg1 = "Click or press any key to continue"; for (items = width = 0; textlines[items]; items++) width = max(width, StringWidth(textlines[items]) + 16); width = max(width, StringWidth(msg1) + 16); Centers(&sR, &cx, &cy); height = FontHeight * (items + 1) + 16; R.Xmin = cx - width / 2; R.Xmax = R.Xmin + width - 1; R.Ymin = cy - height / 2; R.Ymax = R.Ymin + height - 1; framelines(&R); BasicCenteredBox(&tR, width, height, DARKGRAY, textlines[0], WHITE); TextAlign(alignLeft, alignTop); for (i = 1; i < items; i++) { MoveTo(tR.Xmin + 4, tR.Ymin + 8 + FontHeight * i); PenColor(WHITE); BackColor(DARKGRAY); DrawString(textlines[i]); } MoveTo(cx, tR.Ymin + 8 + FontHeight * i + 4); TextAlign(alignCenter, alignTop); DrawString(msg1); while (1) { event e; KeyEvent(true, &e); if (e.ASCII || e.ScanCode || (e.State & 0x700)) break; } WaitForNothing(); PopRect(&i); framelines(&R); }
void framelines(rect * R) { RasterOp(zXORz); PenColor(WHITE); MoveTo(sssR->Xmin, sssR->Ymin); LineTo(R->Xmin, R->Ymin); MoveTo(sssR->Xmax, sssR->Ymin); LineTo(R->Xmax, R->Ymin); MoveTo(sssR->Xmin, sssR->Ymax); LineTo(R->Xmin, R->Ymax); MoveTo(sssR->Xmax, sssR->Ymax); LineTo(R->Xmax, R->Ymax); RasterOp(zREPz); }
// CFepLayoutChoiceList::Draw // Draw a choice list. // (other items were commented in a header). // --------------------------------------------------------------------------- // EXPORT_C void CFepLayoutChoiceList::Draw() { if(!AbleToDraw()) return; SetBorderColor( PenColor() ); DrawChoiceListBackground(Rect()); //draw with border if(iWndControl) { iWndControl->DrawNow(); return; } //draw background for(int ii = 0; ii < iItemList.Count(); ++ii) { DrawItem(ii, EFalse); } }
void PaintQuitButton(int inout) { rect R = QuitButtonR; int cx, cy; HideCursor(); RasterOp(zREPz); Centers(&R, &cx, &cy); PaintRadioButton(&R, inout, inout, ""); TextAlign(alignCenter, alignTop); PenColor(WHITE); BackColor(inout ? RED : DARKGRAY); MoveTo(cx, R.Ymin + 4); DrawString("Alt-X"); MoveTo(cx, R.Ymin + FontHeight + 4); DrawString("to Exit"); PushButton(&R, inout); ExtraHilite(&R, inout); if (inout) DoublePress(&R, true, RED); ShowCursor(); }
void slide_stamps(void) { int i; bitmap *b = thePort->portBMap; if (stamp_err) { stamp_err = 0; return; } HideCursor(); for (i = 2; i > 0; i--) { CopyBits(b, b, &stampingR[i - 1], &stampingR[i], &stampingR[i], zREPz); PenColor(WHITE); FrameRect(&stampingR[i]); } CopyBits(b, b, &stampR, &stampingR[0], &stampingR[0], zREPz); FrameRect(&stampingR[0]); ShowCursor(); }
void setupcontrols(void) { rect R; int i; RasterOp(zREPz); ChargeTool.type = GS_INTEGER; ChargeTool.value = chargeunit; ChargeTool.lo = -500; ChargeTool.hi = 500; current_main_item = -1; CapRadTool.type = GS_UNSIGNED; CapRadTool.value = xsection; CapRadTool.lo = 0; CapRadTool.hi = 20; RadiusTool.type = GS_UNSIGNED; RadiusTool.value = magnetradius; RadiusTool.lo = 1; RadiusTool.hi = 60; PullTool.type = GS_INTEGER; PullTool.value = centerpull; PullTool.lo = -500; PullTool.hi = 500; FreqTool.type = GS_UNSIGNED; FreqTool.value = freq; FreqTool.lo = 2; FreqTool.hi = 10000; FricTool.type = GS_FLOAT; FricTool.value = friction; FricTool.p1 = 4; FricTool.p2 = 2; FricTool.lo = 0; FricTool.hi = 500; R.Xmin = sR.Xmax / 4; R.Ymin = 0; R.Xmax = sR.Xmax; R.Ymax = sR.Ymax; displayRect = R; R.Xmin = 0; R.Ymin = 0; R.Xmax = sR.Xmax / 4 - 9; R.Ymax = sR.Ymax; controlRect = menuRect = R; PenColor(BLUE); PaintRect(&R); PenColor(WHITE); FrameRect(&R); R.Xmin = controlRect.Xmin + 4; R.Xmax = controlRect.Xmax - 4; R.Ymin = controlRect.Ymin + 4; R.Ymax = R.Ymin + FontHeight + 4; main_items = 0; for (i = 0; i < 4; i++) { buttonR[i] = R; mainR[main_items++] = &buttonR[i]; PaintRadioButton(&R, false, false, msgs[i]); OffsetRect(&R, 0, 3 * FontHeight / 2); } R.Ymax += FontHeight; QuitButtonR = R; PaintQuitButton(false); mainR[main_items++] = &QuitButtonR; R.Ymin = R.Ymax + FontHeight; R.Ymax = R.Ymin + FontHeight + 4; R.Xmin = StringWidth("Charge") + 8; for (i = 0; i < 6; i++) { tools[i].t->tR = R; CreateNumberToolTitle(tools[i].t, tools[i].text,WHITE,BLUE); mainR[main_items++] = &tools[i].t->TB.nR; mainR[main_items++] = &tools[i].t->mR; mainR[main_items++] = &tools[i].t->pR; /* The charge rect is sneaky. */ if (i == 0) { chargeR = R; chargeR.Xmin = QuitButtonR.Xmin; charge_thing = SAME; drawChargeButton(); } OffsetRect(&R, 0, 3 * FontHeight / 2); } /* Now let's work on the bottom ones. */ R.Ymin = sR.Ymax - 3*(3*FontHeight/2); R.Ymax = R.Ymin + FontHeight + 4; R.Xmin = 4; randomize_posR = R; PaintRadioButton(&R,false,false,randomposmsg); mainR[main_items++] = &randomize_posR; OffsetRect(&R,0,3*FontHeight/2); randomize_chargeR = R; PaintRadioButton(&R,false,false,randomchargemsg); mainR[main_items++] = &randomize_chargeR; OffsetRect(&R,0,3*FontHeight/2); CreateRadioPanel(&R,RSS,runstopstepR,3,stopped); for(i=0;i<3;i++) mainR[main_items++] = &runstopstepR[i]; }
void main(int argc, char *argv[]) { double r, g, b; uint rows, cols; char fname[256]; double colormag; time_t tstart, tend; int nrgbr = 63, nrgbg = 63, nrgbb = 63; OctreeType *octree; RGBType color; FILE *f; char title[40]; char description[128]; ulong i; uint j; int n; RGBType palette[256]; ulong image_start; union REGS regs; int resx, resy; int px, py; int ii; int cols2, rows2; int k; int cli; int maxr=0, maxg=0, maxb=0; #if defined METAWINDO rect screen; #endif printf("Image file : "); scanf("%s",fname); if ((f = fopen(fname,"rb")) == NULL) { printf("%s not found.\n",fname); exit(1); } /* ** Read the image file header */ fgets(title,40,f); fgets(description,128,f); fscanf(f,"%d %d",&cols,&rows); fscanf(f,"%lf",&colormag); image_start = ftell(f); cols2 = cols/2; rows2 = rows/2; time(&tstart); /* ** Initialize the color octree */ octree = CreateOctNode(0); /* ** Loop through the image and store each unique color. */ for (i = 0L; i < (ulong)rows*(ulong)cols; i++) { /* ** Show progress... */ if ((i % (ulong)cols) == 0L) printf("%ld\r",i/cols); fscanf(f,"%lf %lf %lf",&r,&g,&b); /* ** Convert input floating point values to bytes. NOTE: We assume that ** all input values are between 0..1.0 */ color.r = (unsigned char)(r * nrgbr); color.g = (unsigned char)(g * nrgbg); color.b = (unsigned char)(b * nrgbb); if (color.r > nrgbr) color.r = nrgbr; if (color.g > nrgbg) color.g = nrgbg; if (color.b > nrgbb) color.b = nrgbb; /* ** Insert this color into the octree */ InsertTree(&octree, &color, 0); /* ** If there are too many colors in the tree as a result of this ** insert, reduce the octree */ while (TotalLeafNodes() > npal) { ReduceTree(); } } /* ** Make a pass through the completed octree to average down the ** rgb components. When done, 'n' contains the actual number of ** colors in the palette table. */ n = 0; MakePaletteTable(octree, palette, &n); /* ** How long did it take? */ time(&tend); printf("Processed %ld pixels per second\ninto %d quantized colors\n", ((long)rows*(long)cols)/(tend-tstart), n); j = 0; while (j != 3) { printf("Output to (1)monitor or (2).PCX file or (3) quit: "); scanf("%s",title); j = atoi(title); if (j == 2) { fseek(f,image_start,0); SaveAsPCX(f, octree, cols, rows, nrgbr, nrgbg, nrgbb, npal, palette); } else if (j == 1) { #if defined METAWINDO /* ** NOTE: This section requires MetaWINDOW graphics lib ** ** Let the user choose his graphics device and resolution */ MetQuery(argc,argv); if (InitGraphics(GrafixCard) != 0) { printf("\n---Error initializing graphics device---\n"); exit(1); } SetDisplay(GrafPg0); BackColor(0); /* ** Set the VGA palette */ for (j = 0; j < n; j++) { regs.h.al = 0x10; regs.h.ah = 0x10; regs.h.bl = j; regs.h.bh = 0; regs.h.ch = (int)(palette[j].g); regs.h.cl = (int)(palette[j].b); regs.h.dh = (int)(palette[j].r); int86(0x10,®s,®s); } /* ** Center the image on the screen */ ScreenRect(&screen); resx = screen.Xmax; resy = screen.Ymax; px = resx/2 - npal; /* ** Display a color bar at the top of the screen */ for (ii = 0; ii < npal; ii++){ PenColor(ii); SetPixel(ii*2+px,1); SetPixel(ii*2+px+1,1); SetPixel(ii*2+px,2); SetPixel(ii*2+px+1,2); SetPixel(ii*2+px,3); SetPixel(ii*2+px+1,3); SetPixel(ii*2+px,4); SetPixel(ii*2+px+1,4); } fseek(f,image_start,0); py = resy/2 - rows2 - 1; for (ii = 0; ii < rows ; ii++) { px = resx/2 - cols2; for (k = 0; k < cols; k++) { if (fscanf(f,"%f %f %f",&r,&g,&b) == EOF) { goto pdone; } color.r = (byte)(nrgbr * r); color.g = (byte)(nrgbg * g); color.b = (byte)(nrgbb * b); cli = QuantizeColor(octree, &color); PenColor(cli); SetPixel(px,py); px++; } py++; } pdone: getch(); SetDisplay(TextPg0); StopGraphics(); #endif } } }
void create_slider_base_width(slider * s, rect * mR, int x, int y, int floater, int tinies, int frame, int numbers, int width) { rect R; int row; double range, foffset; int offset; point p; int zwidth; int zepps; int i; R.Xmin = mR->Xmin + x; R.Xmax = mR->Xmax - x; R.Ymin = mR->Ymin + y; R.Ymax = R.Ymin + slider_height(s); s->tR = R; s->bubblewidth = width; #ifndef NOFRAME /* Box the whole thing */ if (frame) { PenColor(BUTTONFRAME); FrameRect(&R); } #endif row = R.Ymin + 2; #ifndef NOTITLE if (s->title) { int cx; cx = R.Xmin + (R.Xmax - R.Xmin) / 2; PenColor(BLACK); BackColor(MENUBACK); TextAlign(alignCenter, alignTop); MoveTo(cx, row); DrawString(s->title); row += FontHeight + 4; } #else row += FontHeight + 4; #endif #ifndef NONUMBERS if (numbers) { int w = 8 * 10; R.Xmin = s->tR.Xmin + 4; R.Xmax = R.Xmin + w - 1; R.Ymin = row - FontHeight / 4; R.Ymax = R.Ymin + FontHeight + 4; s->TB.nR = R; PaintNumberBoxEntry(&s->TB, s->value, (floater) ? GS_FLOAT : GS_UNSIGNED); s->sR.Xmin = R.Xmax + 8; } else { s->sR.Xmin = s->tR.Xmin + 2; } #else s->sR.Xmin = s->tR.Xmin + 2; #endif s->sR.Xmax = s->tR.Xmax - 2; s->sR.Ymin = row; s->sR.Ymax = row + (4 * FontHeight) / 5; PenColor(BUTTONBACK); PaintRect(&s->sR); PushButton(&s->sR, true); /* * Now figure out where we want the slider piece to be. We XOR the * thing into place, to make it easier to move it. And we just paint * it by drawing a 10-wide vertical line. */ range = s->max - s->min; foffset = s->value - s->min; offset = foffset / range * (s->sR.Xmax - s->sR.Xmin); p.X = s->sR.Xmin + offset; p.X = max(s->sR.Xmin + 5, p.X); p.X = min(s->sR.Xmax - 5, p.X); R.Xmin = p.X - width / 2; R.Xmax = p.X + width / 2 - 1; R.Ymin = s->sR.Ymin + 2; R.Ymax = s->sR.Ymax - 2; while (R.Xmin < s->sR.Xmin + 2) OffsetRect(&R, 1, 0); while (R.Xmax > s->sR.Xmax - 2) OffsetRect(&R, -1, 0); s->bR = R; PenColor(LIGHTGRAY); PaintRect(&s->bR); PushButton(&s->bR, false); /* Now position and paint the value box. */ s->old_value = s->value; /* create the zed box */ #ifdef NOTINIES if (tinies) { int cx, cy; Centers(&s->sR, &cx, &cy); zwidth = (s->sR.Xmax - s->sR.Xmin - 10) / 6; row = s->tR.Ymax - FontHeight / 2 - 4; for (i = 0; i < 3; i++) { rect R1, R2; R1.Xmin = cx + i * zwidth + 2 * (i + 1); R1.Xmax = R1.Xmin + zwidth - 1; R1.Ymin = row; R1.Ymax = row + FontHeight / 2; R2.Xmax = cx - i * zwidth - 2 * (i + 1); R2.Xmin = R2.Xmax - zwidth + 1; R2.Ymin = row; R2.Ymax = row + FontHeight / 2; s->zR[3 + i] = R1; s->zR[2 - i] = R2; } zepps = -3; for (i = 0; i < 6; i++) { rect R; int cy; int zwidth3 = zwidth / 3; int zstart; int dashwidth = zwidth3 - 4; R = s->zR[i]; dashwidth = min(dashwidth, s->zR[i].Ymax - s->zR[i].Ymin - 4); Centers(&R, &cx, &cy); PenColor(8); PaintRect(&R); PushButton(&R, false); PenColor(7); switch (zepps) { case -3: case 3: zstart = cx - (3 * dashwidth / 2 + 4); dash_or_plus(zstart, cy + 1, dashwidth, zepps == 3); zstart = cx - dashwidth / 2; dash_or_plus(zstart, cy + 1, dashwidth, zepps == 3); zstart = cx + dashwidth / 2 + 4; dash_or_plus(zstart, cy + 1, dashwidth, zepps == 3); break; case -2: case 2: zstart = R.Xmin + zwidth / 2 - dashwidth - 2; dash_or_plus(zstart, cy + 1, dashwidth, zepps == 2); zstart = R.Xmin + zwidth / 2 + 2; dash_or_plus(zstart, cy + 1, dashwidth, zepps == 2); break; case -1: case 1: zstart = R.Xmin + zwidth / 2 - dashwidth / 2; dash_or_plus(zstart, cy + 1, dashwidth, zepps == 1); break; } zepps++; if (zepps == 0) zepps++; } } #endif }
void InfoBox(void) { rect tR; int row; int width = 2 * sR.Xmax / 3; int height; int cx, cy; char tbuf[128]; int i; long l = realfarcoreleft(); for (i = 0; infomsgs[i]; i++); height = (i + 5) * FontHeight + FontHeight; HideCursor(); strcpy(tbuf,PROGRAM_NAME); for(i=0;tbuf[i];i++) if (tbuf[i] == '_') tbuf[i] = ' '; BasicCenteredBox(&tR, width, height, DARKGRAY, tbuf, WHITE); Centers(&tR, &cx, &cy); row = tR.Ymin + FontHeight + 8; TextAlign(alignCenter, alignTop); MoveTo(cx, row); PenColor(WHITE); BackColor(DARKGRAY); #ifdef RELEASE sprintf(tbuf, "Version 1.00"); #else sprintf(tbuf, "Version %3.2f " __DATE__, VERSION); #endif DrawString(tbuf); row += FontHeight; for (i = 0; infomsgs[i]; i++, row += FontHeight) { MoveTo(cx, row); DrawString(infomsgs[i]); } row += FontHeight; sprintf(tbuf, "%ld bytes free", l); MoveTo(cx, row); DrawString(tbuf); row += FontHeight; MoveTo(cx, row); DrawString("Press any key or click to continue"); while (1) { event e; if (KeyEvent(false, &e)) break; } PopRect(&i); ShowCursor(); }