void m_select(int oldsize, int newsize, int *index) { int i; double cur, step, sum; cur = 0.0; step = ((double)newsize)/oldsize; // printf("old size is %d, new size is %d, step is %f\n", oldsize, newsize, step); if (oldsize<newsize) { printf("not supported"); return; } if (newsize>oldsize/2+1) { m_select(oldsize, oldsize-newsize, index); reverse(oldsize, index); return; } sum=0; for (i=0; i<oldsize; i++) { sum+=step; if (sum-cur>0.5) { index[i]=1; cur++; } else index[i]=0; } }
void Population::Select() { m_select(*this); }
void CEditorAction::Render(CRect &Pos, CDC& dc,bool EventSelected, CChronoEventEditor& Ed, int renderType, bool bEnabled) { COLORREF ActionBG =m_select(&Ed)? ACTION_BG_SEL : (EventSelected? ACTION_BG_EVSEL : ACTION_BG); // Animating if(m_Anim.m_bDestroyed) { if(renderType == 3) { Pos.OffsetRect(0,m_Anim.Space); } if(renderType == 1) { Pos.OffsetRect(-30 + m_Anim.Space, 0); } //dc.FillSolidRect(Calc,BG); return; } switch(renderType) { /* case 0: { if(m_select(&Ed)) { dc.FillSolidRect(Pos,ActionBG); dc.Draw3dRect(Pos,ACTION_BG_SEL2,ACTION_BG_SEL2); } HBITMAP load = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_DOT)); HDC hdcScreenCompat = CreateCompatibleDC(dc.m_hDC); HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcScreenCompat, load); BitBlt(dc.m_hDC, Pos.left + 1, Pos.top + 1, 16, 16, hdcScreenCompat, 0, 0, SRCCOPY); SelectObject(hdcScreenCompat, hbmpOld); DeleteDC(hdcScreenCompat); DeleteObject(load); } break;*/ case 1: { if(m_select(&Ed)) { Pos.InflateRect(3,3); dc.FillSolidRect(Pos,ActionBG); dc.Draw3dRect(Pos,ACTION_BG_SEL2,ACTION_BG_SEL2); Pos.DeflateRect(3,3); } int icon = 0; if(m_Family) ((EventSheetEditor*)(&Ed))->m_familyhbitmaps.Lookup(oid, icon); else ((EventSheetEditor*)(&Ed))->m_objecthbitmaps.Lookup(oid, icon); static HDC dcMem = CreateCompatibleDC(dc.m_hDC); HBITMAP old = (HBITMAP)SelectObject(dcMem, Ed.GetIcon(icon)); BitBlt(dc.m_hDC,Pos.left, Pos.top ,16 ,16,dcMem,0,0,SRCCOPY); SelectObject(dcMem, old); //DeleteDC(dcMem); - its static so we cant delete it m_Anim.Space = 30; } break; case 2: { CHTMLFont f; f.SetBold(false); f.SetSize(8); f.SetName("Arial"); f.SetImage(false); if (!bEnabled) f.SetStrike(true); CRect Calc = Pos; Calc.bottom += m_rect(&Ed).Height(); // Draw the action CString Out = m_Text; g_HTMLDraw.DrawText(&dc, Out, f, Calc, 0, &Ed, &m_imgs,¶ms); m_Readable = Out; Pos.bottom = Pos.top + Calc.Height(); Calc = Pos; dc.FillSolidRect(Pos,ActionBG); // We may be hovering over something. CPoint mouse; GetCursorPos(&mouse); Ed.ScreenToClient(&mouse); if(Pos.PtInRect(mouse) && m_select(&Ed)) { for(int p = 0; p < params.size(); p++) for(int d = 0; d < params[p]->displayrects.size(); d++) if(params[p]->displayrects[d].PtInRect(mouse)) { for(int a = 0; a < params[p]->displayrects.size(); a++) dc.FillSolidRect(params[p]->displayrects[a], RGB(100,255,100)); continue; } } // End hover Out = m_Text; g_HTMLDraw.DrawText(&dc, Out, f, Calc, 0, &Ed, &m_imgs,¶ms); m_Readable = Out; if(m_select(&Ed)) dc.Draw3dRect(Calc,ACTION_BG_SEL2,ACTION_BG_SEL2); } break; case 3: { CHTMLFont f; f.SetBold(false); f.SetSize(8); f.SetName("Arial"); f.SetImage(false); if (!bEnabled) f.SetStrike(true); CRect Calc = Pos; Calc.bottom += m_rect(&Ed).Height(); CString newtext; CObjType* objectType = ((EventSheetEditor*)&Ed)->application->FindObjTypeFromNumber(oid); int icon = 0; if(m_Family) ((EventSheetEditor*)(&Ed))->m_familyhbitmaps.Lookup(oid, icon); else ((EventSheetEditor*)(&Ed))->m_objecthbitmaps.Lookup(oid, icon); bool show_name = true; bool show_icon = true; bool show_quotes = true; if (m_Text.Find("#noname") != -1) show_name = false; if (m_Text.Find("#noicon") != -1) show_icon = false; if (m_Text.Find("#noquotes") != -1) show_quotes = false; CString display_text = m_Text; display_text.Replace("#noname", ""); display_text.Replace("#noicon", ""); display_text.Replace("#noquotes", ""); if (!show_quotes) display_text.Replace("\"", ""); if (show_name && show_icon) newtext.Format("<img>%d</img> %s: %s", icon, objectType->GetName(), display_text); else if (show_name && !show_icon) newtext.Format("%s: %s", objectType->GetName(), display_text); else if (!show_name && show_icon) newtext.Format("<img>%d</img> %s", icon, display_text); else newtext.Format("%s", display_text); CString Out = newtext; g_HTMLDraw.DrawText(&dc, Out, f, Calc, 0, &Ed, &m_imgs,¶ms); dc.FillSolidRect(Calc,ActionBG); //We may be hovering over something. CPoint mouse; GetCursorPos(&mouse); Ed.ScreenToClient(&mouse); if(Calc.PtInRect(mouse) && m_select(&Ed)) { for(int p = 0; p < params.size(); p++) for(int d = 0; d < params[p]->displayrects.size(); d++) if(params[p]->displayrects[d].PtInRect(mouse)) { for(int a = 0; a < params[p]->displayrects.size(); a++) dc.FillSolidRect(params[p]->displayrects[a], RGB(100,255,100)); continue; } } // End hover Calc = Pos; Calc.bottom += m_rect(&Ed).Height(); // Get readable text g_HTMLDraw.DrawText(&dc, newtext, f, Calc, 0, &Ed, &m_imgs,¶ms); m_Readable = newtext.Right(newtext.GetLength() - newtext.ReverseFind(':')); Pos.bottom = Pos.top + Calc.Height(); if(m_select(&Ed)) dc.Draw3dRect(Calc,ACTION_BG_SEL2,ACTION_BG_SEL2); m_Anim.Space = Calc.Height(); } break; } m_visible = true; m_rect(&Ed) = Pos; if(renderType == 1) { Pos.InflateRect(3,3); m_rect(&Ed) = Pos; Pos.DeflateRect(3,3); } }
Masek::filter *Masek::imresize(filter *im, double scaling) { filter *newim; int *index0, *index1; int i, j, x, y; newim = (filter*)malloc(sizeof(filter)); if (newim) { newim->hsize[0] = (int)(im->hsize[0]*scaling+AdjPrecision); if (newim->hsize[0] <1) newim->hsize[0] = 1; newim->hsize[1] = (int)(im->hsize[1]*scaling+AdjPrecision); if (newim->hsize[1]<1) newim->hsize[1] = 1; newim->data =(double*) malloc(sizeof(double)*newim->hsize[0]*newim->hsize[1]); if (newim->data) { index0 = (int*)malloc(sizeof(int)*im->hsize[0]); index1 = (int*)malloc(sizeof(int)*im->hsize[1]); if (!index0 || !index1) { free(im->data); free(im); free(newim); free(newim->data); return NULL; } m_select(im->hsize[0], newim->hsize[0], index0); m_select(im->hsize[1], newim->hsize[1], index1); /* fid = fopen("index0.txt", "w"); for (i = 0; i<newim->hsize[0]; i++) fprintf(fid, "%d %d\n", i+1, index0[i]); fclose(fid); fid = fopen("index1.txt", "w"); for (i = 0; i<newim->hsize[0]; i++) fprintf(fid, "%d %d\n", i+1, index1[i]); fclose(fid); */ for (i=0, y=0; i<im->hsize[0]; i++) { if (index0[i]>0) { for (j=0, x=0; j<im->hsize[1]; j++) { if (index0[i]>0 && index1[j]>0) { newim->data[y*newim->hsize[1]+x]=im->data[i*im->hsize[1]+j]; x++; } } y++; } } free(index0); free(index1); } } free(im->data); free(im); return newim; }
void CEditorCondition::Render(CRect &Pos, CDC &dc, bool EventSelected, CChronoEventEditor& Ed, bool bBookmarked, bool bEnabled) { COLORREF BG; BG = m_select(&Ed)? CONDITION_BG_SEL : (EventSelected? CONDITION_BG_EVSEL : CONDITION_BG); if(IsTrigger(NULL)) { BG = m_select(&Ed)? CONDITION_BG_SEL : (EventSelected? CONDITION_BG_EVSEL : EVENT_BG); } // Animating if(m_Anim.m_bDestroyed) { CRect Calc = Pos; Pos.OffsetRect(0,m_Anim.Space); Calc.bottom = Pos.bottom; dc.FillSolidRect(Calc,BG); return; } CRect Box = Pos; Box.bottom+= m_rect(&Ed).Height(); CRect Calc = Pos; Calc.bottom = Box.bottom; CHTMLFont f; f.SetBold(false); f.SetSize(8); f.SetName("Segoe UI"); f.SetImage(false); // Is it enabled? if (!bEnabled) f.SetStrike(true); CString Out; Out.Format("%s", m_Text); g_HTMLDraw.DrawText(&dc, Out, f, Calc, 0, &Ed, &m_imgs,¶ms); m_Readable.Format("%s", Out); dc.FillSolidRect(Calc,BG); { CRect Calc2 = Calc; CRect Calc = Pos; Calc.bottom = Box.bottom; //We may be hovering over something. CPoint mouse; GetCursorPos(&mouse); Ed.ScreenToClient(&mouse); if(Calc2.PtInRect(mouse) && m_select(&Ed)) { for(int p = 0; p < params.size(); p++) for(int d = 0; d < params[p]->displayrects.size(); d++) if(params[p]->displayrects[d].PtInRect(mouse)) { for(int a = 0; a < params[p]->displayrects.size(); a++) dc.FillSolidRect(params[p]->displayrects[a], RGB(100,255,100)); continue; } } // End hover CString Out; bool show_quotes = true; if (m_Text.Find("#noquotes") != -1) show_quotes = false; CString display_text = m_Text; display_text.Replace("#noquotes", ""); if (!show_quotes) display_text.Replace("\"", ""); Out.Format("%s", display_text); g_HTMLDraw.DrawText(&dc, Out, f, Calc, 0, &Ed, &m_imgs,¶ms); m_Readable.Format("%s", Out); if(m_select(&Ed)) dc.Draw3dRect(Calc2,CONDITION_BG_SEL2,CONDITION_BG_SEL2); } m_rect(&Ed) = Calc; Pos.OffsetRect(CPoint(0,Calc.Height())); m_Anim.Space = Calc.Height(); if(IsLoop(NULL)) { Pos.left += 10; } }