// Draws the data in a new window. void ImageData::Display() const { #ifndef GRAPHICS_DISABLED const int kTextSize = 64; // Draw the image. Pix* pix = GetPix(); if (pix == NULL) return; int width = pixGetWidth(pix); int height = pixGetHeight(pix); ScrollView* win = new ScrollView("Imagedata", 100, 100, 2 * (width + 2 * kTextSize), 2 * (height + 4 * kTextSize), width + 10, height + 3 * kTextSize, true); win->Image(pix, 0, height - 1); pixDestroy(&pix); // Draw the boxes. win->Pen(ScrollView::RED); win->Brush(ScrollView::NONE); win->TextAttributes("Arial", kTextSize, false, false, false); for (int b = 0; b < boxes_.size(); ++b) { boxes_[b].plot(win); win->Text(boxes_[b].left(), height + kTextSize, box_texts_[b].string()); TBOX scaled(boxes_[b]); scaled.scale(256.0 / height); scaled.plot(win); } // The full transcription. win->Pen(ScrollView::CYAN); win->Text(0, height + kTextSize * 2, transcription_.string()); // Add the features. win->Pen(ScrollView::GREEN); win->Update(); window_wait(win); #endif }
void C4MapCreator::ValidateTextureIndices(C4TextureMap &rTextureMap) { int32_t iX,iY; for (iY=0; iY<MapHgt; iY++) for (iX=0; iX<MapWdt; iX++) if (!rTextureMap.GetEntry(GetPix(iX,iY))) SetPix(iX,iY,0); }
/*********************************************************************\ Function name : CDialogUserArea::CreateElementBegin Description : Created at : 15.08.01, @ 19:47:00 Created by : Thomas Kunert Modified by : \*********************************************************************/ void CDialogUserArea::CreateElementBegin(Int32 lID, GeDialog *pDlg) { pDlg->AddUserArea(lID, m_lFlags, CONVERT_WIDTH(m_lInitW), CONVERT_HEIGHT(m_lInitH)); pDlg->AttachUserArea(m_wndUser, lID, USERAREA_0); Float chr; Int32 w = CONVERT_WIDTH(m_lInitW); Int32 h = CONVERT_WIDTH(m_lInitH); chr = GetChr(w) / 10.0; m_wndUser.m_lMinSizeX = GetPix(w) + Int32(m_wndUser.DrawGetTextWidth("8") * chr + 0.5); chr = GetChr(h) / 10.0; m_wndUser.m_lMinSizeY = GetPix(h) + Int32(m_wndUser.DrawGetFontHeight() * chr + 0.5); m_wndUser.m_pParent = pDlg; m_wndUser.m_lID = lID; }
void C4MapCreator::SetPix(int32_t x, int32_t y, BYTE col) { // Safety if (!Inside<int32_t>(x,0,MapWdt-1) || !Inside<int32_t>(y,0,MapHgt-1)) return; // Exclusive if (Exclusive>-1) if (GetPix(x,y)!=Exclusive) return; // Set pix MapBuf->SetPix(x,y,col); }
void CSurface8::AllowColor(BYTE iRngLo, BYTE iRngHi, BOOL fAllowZero) { // change colors int xcnt, ycnt; if (iRngHi < iRngLo) return; for (ycnt = 0; ycnt < Hgt; ycnt++) { for (xcnt = 0; xcnt < Wdt; xcnt++) { BYTE px = GetPix(xcnt, ycnt); if (px || !fAllowZero) if ((px < iRngLo) || (px > iRngHi)) SetPix(xcnt, ycnt, iRngLo + px % (iRngHi - iRngLo + 1)); } } }
// Gets anything and everything with a non-NULL pointer, prescaled to a // given target_height (if 0, then the original image height), and aligned. // Also returns (if not NULL) the width and height of the scaled image. // The return value is the scale factor that was applied to the image to // achieve the target_height. float ImageData::PreScale(int target_height, Pix** pix, int* scaled_width, int* scaled_height, GenericVector<TBOX>* boxes) const { int input_width = 0; int input_height = 0; Pix* src_pix = GetPix(); ASSERT_HOST(src_pix != NULL); input_width = pixGetWidth(src_pix); input_height = pixGetHeight(src_pix); if (target_height == 0) target_height = input_height; float im_factor = static_cast<float>(target_height) / input_height; if (scaled_width != NULL) *scaled_width = IntCastRounded(im_factor * input_width); if (scaled_height != NULL) *scaled_height = target_height; if (pix != NULL) { // Get the scaled image. pixDestroy(pix); *pix = pixScale(src_pix, im_factor, im_factor); if (*pix == NULL) { tprintf("Scaling pix of size %d, %d by factor %g made null pix!!\n", input_width, input_height, im_factor); } if (scaled_width != NULL) *scaled_width = pixGetWidth(*pix); if (scaled_height != NULL) *scaled_height = pixGetHeight(*pix); } pixDestroy(&src_pix); if (boxes != NULL) { // Get the boxes. boxes->truncate(0); for (int b = 0; b < boxes_.size(); ++b) { TBOX box = boxes_[b]; box.scale(im_factor); boxes->push_back(box); } if (boxes->empty()) { // Make a single box for the whole image. TBOX box(0, 0, im_factor * input_width, target_height); boxes->push_back(box); } } return im_factor; }
// Draws the data in a new window. void ImageData::Display() const { const int kTextSize = 64; int x_max, y_max; WordFeature::ComputeSize(features_, &x_max, &y_max); ScrollView* win = new ScrollView("Imagedata", 100, 100, 2 * (x_max + 2 * kTextSize), 2 * (y_max + 4 * kTextSize), x_max + 10, y_max + 3 * kTextSize, true); // Draw the image. Pix* pix = GetPix(); int height = 256; if (pix != NULL) { height = pixGetHeight(pix); win->Image(pix, 0, height - 1); pixDestroy(&pix); } // Draw the boxes. win->Pen(ScrollView::RED); win->Brush(ScrollView::NONE); win->TextAttributes("Arial", kTextSize, false, false, false); for (int b = 0; b < boxes_.size(); ++b) { boxes_[b].plot(win); win->Text(boxes_[b].left(), y_max + kTextSize, box_texts_[b].string()); TBOX scaled(boxes_[b]); scaled.scale(256.0 / height); scaled.plot(win); } // The full transcription. win->Pen(ScrollView::CYAN); win->Text(0, y_max + kTextSize * 2, transcription_.string()); // Add the features. win->Pen(ScrollView::GREEN); WordFeature::Draw(features_, win); win->Update(); window_wait(win); }
// Gets anything and everything with a non-NULL pointer, prescaled to a // given target_height (if 0, then the original image height), and aligned. // Also returns (if not NULL) the width and height of the scaled image. void ImageData::PreScale(int target_height, Pix** pix, int* scaled_width, int* scaled_height, GenericVector<TBOX>* boxes) const { int input_width = 0; int input_height = 0; Pix* src_pix = GetPix(); ASSERT_HOST(src_pix != NULL); input_width = pixGetWidth(src_pix); input_height = pixGetHeight(src_pix); if (target_height == 0) target_height = input_height; float im_factor = static_cast<float>(target_height) / input_height; if (scaled_width != NULL) *scaled_width = IntCastRounded(im_factor * input_width); if (scaled_height != NULL) *scaled_height = target_height; if (pix != NULL) { // Get the scaled image. pixDestroy(pix); *pix = pixScale(src_pix, im_factor, im_factor); if (scaled_width != NULL) *scaled_width = pixGetWidth(*pix); if (scaled_height != NULL) *scaled_height = pixGetHeight(*pix); } pixDestroy(&src_pix); if (boxes != NULL) { // Get the boxes. boxes->truncate(0); for (int b = 0; b < boxes_.size(); ++b) { TBOX box = boxes_[b]; box.scale(im_factor); boxes->push_back(box); } } }
void CSurface8::MapBytes(BYTE *bpMap) { if (!bpMap) return; for (int cnt=0; cnt<Wdt*Hgt; cnt++) SetPix(cnt%Wdt, cnt/Wdt, bpMap[GetPix(cnt%Wdt, cnt/Wdt)]); }
uint16 input_polygon2d(Vex2D* v) { uint16 total_v = 0; uint16 cursor_x = LCD_WIDTH / 2, cursor_y = LCD_HEIGHT / 2; uint16 old_x = cursor_x, old_y = cursor_y; uint16 old_value = GetPix(old_x, old_y); _Bool start = 1; do { if(cursor_x != old_x || cursor_y != old_y || start) { DrawPix(old_x, old_y, old_value ? A_NORMAL : A_REVERSE); old_value = GetPix(cursor_x, cursor_y); old_x = cursor_x; old_y = cursor_y; DrawPix(cursor_x, cursor_y, A_NORMAL); start = 0; idle(); if(_keytest(RR_DIAMOND)) { idle(); idle(); idle(); idle(); } } if(_keytest(RR_W)) { if(cursor_y > 0) --cursor_y; } else if(_keytest(RR_S)) { if(cursor_y + 1 < LCD_HEIGHT) ++cursor_y; } else if(_keytest(RR_A)) { if(cursor_x > 0) --cursor_x; } if(_keytest(RR_D)) { if(cursor_x + 1 < LCD_WIDTH) ++cursor_x; } else if(_keytest(RR_ENTER)) { v[total_v++] = (Vex2D) { cursor_x, cursor_y }; if(total_v > 1) draw_line(v[total_v - 2], v[total_v - 1] ); while(_keytest(RR_ENTER)) ; } else if(_keytest(RR_ESC)) { while(_keytest(RR_ESC)) ; draw_line(v[0], v[total_v - 1]); return total_v; } } while(1); }
void C4MapCreator::Create(CSurface8 *sfcMap, C4SLandscape &rLScape, C4TextureMap &rTexMap, BOOL fLayers, int32_t iPlayerNum) { double fullperiod = 20.0 * pi; BYTE ccol; int32_t cx, cy; // Safeties if (!sfcMap) return; iPlayerNum = BoundBy<int32_t>(iPlayerNum, 1, C4S_MaxPlayer); // Set creator variables MapBuf = sfcMap; MapWdt = MapBuf->Wdt; MapHgt = MapBuf->Hgt; // Reset map (0 is sky) MapBuf->ClearBox8Only(0, 0, MapBuf->Wdt, MapBuf->Hgt); // Surface ccol = rTexMap.GetIndexMatTex(rLScape.Material, "Smooth") + MapIFT; float amplitude = (float)rLScape.Amplitude.Evaluate(); float phase = (float)rLScape.Phase.Evaluate(); float period = (float)rLScape.Period.Evaluate(); if (rLScape.MapPlayerExtend) period *= Min(iPlayerNum, C4S_MaxMapPlayerExtend); float natural = (float)rLScape.Random.Evaluate(); int32_t level0 = Min(MapWdt, MapHgt) / 2; int32_t maxrange = level0 * 3 / 4; double cy_curve, cy_natural; // -1.0 - +1.0 ! double rnd_cy, rnd_tend; // -1.0 - +1.0 ! rnd_cy = (double)(Random(2000 + 1) - 1000) / 1000.0; rnd_tend = (double)(Random(200 + 1) - 100) / 20000.0; for (cx = 0; cx < MapWdt; cx++) { rnd_cy += rnd_tend; rnd_tend += (double)(Random(100 + 1) - 50) / 10000; if (rnd_tend > +0.05) rnd_tend = +0.05; if (rnd_tend < -0.05) rnd_tend = -0.05; if (rnd_cy < -0.5) rnd_tend += 0.01; if (rnd_cy > +0.5) rnd_tend -= 0.01; cy_natural = rnd_cy * natural / 100.0; cy_curve = sin(fullperiod * period / 100.0 * (float)cx / (float)MapWdt + 2.0 * pi * phase / 100.0) * amplitude / 100.0; cy = level0 + BoundBy((int32_t)((float)maxrange * (cy_curve + cy_natural)), -maxrange, +maxrange); SetPix(cx, cy, ccol); } // Raise bottom to surface for (cx = 0; cx < MapWdt; cx++) for (cy = MapHgt - 1; (cy >= 0) && !GetPix(cx, cy); cy--) SetPix(cx, cy, ccol); // Raise liquid level Exclusive = 0; ccol = rTexMap.GetIndexMatTex(rLScape.Liquid, "Smooth"); int32_t wtr_level = rLScape.LiquidLevel.Evaluate(); for (cx = 0; cx < MapWdt; cx++) for (cy = MapHgt * (100 - wtr_level) / 100; cy < MapHgt; cy++) SetPix(cx, cy, ccol); Exclusive = -1; // Layers if (fLayers) { // Base material Exclusive = rTexMap.GetIndexMatTex(rLScape.Material, "Smooth") + MapIFT; int32_t cnt, clayer, layer_num, sptx, spty; // Process layer name list for (clayer = 0; clayer < C4MaxNameList; clayer++) if (rLScape.Layers.Name[clayer][0]) { // Draw layers ccol = rTexMap.GetIndexMatTex(rLScape.Layers.Name[clayer], "Rough") + MapIFT; layer_num = rLScape.Layers.Count[clayer]; layer_num = layer_num * MapWdt * MapHgt / 15000; for (cnt = 0; cnt < layer_num; cnt++) { // Place layer sptx = Random(MapWdt); for (spty = 0; (spty < MapHgt) && (GetPix(sptx, spty) != Exclusive); spty++) ; spty += 5 + Random((MapHgt - spty) - 10); DrawLayer(sptx, spty, Random(15), ccol); } } Exclusive = -1; } }