int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) { WIN_DialogData *dialog; int i, x, y; UINT_PTR which; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; HFONT DialogFont; SIZE Size; RECT TextSize; wchar_t* wmessage; TEXTMETRIC TM; const int ButtonWidth = 88; const int ButtonHeight = 26; const int TextMargin = 16; const int ButtonMargin = 12; /* Jan 25th, 2013 - [email protected] * * * I've tried to make this more reasonable, but I've run in to a lot * of nonsense. * * The original issue is the code was written in pixels and not * dialog units (DLUs). All DialogBox functions use DLUs, which * vary based on the selected font (yay). * * According to MSDN, the most reliable way to convert is via * MapDialogUnits, which requires an HWND, which we don't have * at time of template creation. * * We do however have: * The system font (DLU width 8 for me) * The font we select for the dialog (DLU width 6 for me) * * Based on experimentation, *neither* of these return the value * actually used. Stepping in to MapDialogUnits(), the conversion * is fairly clear, and uses 7 for me. * * As a result, some of this is hacky to ensure the sizing is * somewhat correct. * * Honestly, a long term solution is to use CreateWindow, not CreateDialog. * * * In order to get text dimensions we need to have a DC with the desired font. * I'm assuming a dialog box in SDL is rare enough we can to the create. */ HDC FontDC = CreateCompatibleDC(0); { /* Create a duplicate of the font used in system message boxes. */ LOGFONT lf; NONCLIENTMETRICS NCM; NCM.cbSize = sizeof(NCM); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0); lf = NCM.lfMessageFont; DialogFont = CreateFontIndirect(&lf); } /* Select the font in to our DC */ SelectObject(FontDC, DialogFont); { /* Get the metrics to try and figure our DLU conversion. */ GetTextMetrics(FontDC, &TM); s_BaseUnitsX = TM.tmAveCharWidth + 1; s_BaseUnitsY = TM.tmHeight; } /* Measure the *pixel* size of the string. */ wmessage = WIN_UTF8ToString(messageboxdata->message); SDL_zero(TextSize); Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT); /* Add some padding for hangs, etc. */ TextSize.right += 2; TextSize.bottom += 2; /* Done with the DC, and the string */ DeleteDC(FontDC); SDL_free(wmessage); /* Increase the size of the dialog by some border spacing around the text. */ Size.cx = TextSize.right - TextSize.left; Size.cy = TextSize.bottom - TextSize.top; Size.cx += TextMargin * 2; Size.cy += TextMargin * 2; /* Ensure the size is wide enough for all of the buttons. */ if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin; /* Add vertical space for the buttons and border. */ Size.cy += ButtonHeight + TextMargin; dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title); if (!dialog) { return -1; } if (!AddDialogStatic(dialog, TextMargin, TextMargin, TextSize.right - TextSize.left, TextSize.bottom - TextSize.top, messageboxdata->message)) { FreeDialogData(dialog); return -1; } /* Align the buttons to the right/bottom. */ x = Size.cx - (ButtonWidth + ButtonMargin) * messageboxdata->numbuttons; y = Size.cy - ButtonHeight - ButtonMargin; for (i = messageboxdata->numbuttons - 1; i >= 0; --i) { SDL_bool isDefault; if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { isDefault = SDL_TRUE; } else { isDefault = SDL_FALSE; } if (!AddDialogButton(dialog, x, y, ButtonWidth, ButtonHeight, buttons[i].text, i, isDefault)) { FreeDialogData(dialog); return -1; } x += ButtonWidth + ButtonMargin; } /* FIXME: If we have a parent window, get the Instance and HWND for them */ which = DialogBoxIndirect(NULL, (DLGTEMPLATE*)dialog->lpDialog, NULL, (DLGPROC)MessageBoxDialogProc); *buttonid = buttons[which].buttonid; FreeDialogData(dialog); return 0; }
void GridDisplay::PaintFixed(Draw &w, bool firstx, bool firsty, int x, int y, int cx, int cy, const Value &val, dword style, Font &fnt, bool indicator, bool moved, int sortmode, int sortcol, int sortcnt, bool horizontal) { real_size.cx = 0; real_size.cy = 0; bool chameleon = style & GD::CHAMELEON; bool highlight = style & GD::HIGHLIGHT; bool readonly = style & GD::READONLY; if(chameleon) { int ncx = cx; int nx = x; int ht = HeaderCtrl::StyleDefault().gridadjustment; if(firstx) { if(ncx >= -ht) { ncx -= ht; if(ncx < 0) ncx = 0; } } else nx -= ht; int q = CTRL_NORMAL; if(highlight) q = CTRL_HOT; if(readonly) q = CTRL_DISABLED; ChPaint(w, nx, y, ncx, cy, HeaderCtrl::StyleDefault().look[q]); } else { if(theme < 0) w.DrawRect(x, y, cx, cy, highlight ? Blend(SColorFace(), White, 128) : SColorFace()); else { int sx = cx > 1 ? cx : 1; int sy = cy - 1; if(sx > 0 && sy > 0) w.DrawImage(x, y, sx, sy, highlight ? hdrhigh : vhdr[theme]()); } //Color dark(76, 83, 92); Color dark(155, 154, 153); //Color dark(155, 154, 153); Color bright(White); if(!firstx) w.DrawRect(x, y, 1, cy, bright); if(!firsty) w.DrawRect(x, y, cx, 1, bright); if(firstx) w.DrawRect(x, y, 1, cy, dark); if(firsty) w.DrawRect(x, y, cx, 1, dark); w.DrawRect(x + cx - 1, y, 1, cy, dark); w.DrawRect(x, y + cy - 1, cx, 1, dark); } int tx = x + lm; if(firsty) { if(!leftImg.IsEmpty()) { Size isz = leftImg.GetSize(); w.DrawImage(tx, y + (cy - isz.cy) / 2, leftImg); tx += isz.cx + 3; } if(!rightImg.IsEmpty()) { Size isz = rightImg.GetSize(); w.DrawImage(x + cx - isz.cx - 3, y + (cy - isz.cy) / 2, rightImg); } if(!centerImg.IsEmpty()) { Size isz = centerImg.GetSize(); w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, centerImg); } } if(moved) DrawBorder(w, x, y, cx, cy, BlackBorder); Color col = style & GD::READONLY ? Gray : Black; if(sortmode > 0) { Size isz = GridImg::SortAsc().GetSize(); int yf = y + (cy - isz.cy) / 2; int xf = tx + 2; tx = xf + isz.cx + 1; if(sortcol > 0 && sortcnt > 1) { String tcol = AsString(sortcol); Size tsz = GetTextSize(tcol, fnt); w.DrawText(tx, y + (cy - tsz.cy) / 2, tcol, fnt); tx += tsz.cx; } bool asc = sortmode == 1; if(reverse_sort_icon) asc = !asc; w.DrawImage(xf, yf, asc ? GridImg::SortAsc() : GridImg::SortDsc(), col); tx += 3; } if(indicator) { w.Clip(x, y, cx, cy); Image img; if((style & GD::CURSOR) && (style & GD::SELECT)) { img = GridImg::FocSel(); } else if(style & GD::CURSOR) { img = GridImg::Focused(); } else if(style & GD::SELECT) { img = GridImg::Selected(); } if(!img.IsEmpty()) { Size isz = img.GetSize(); int xp = IsNull(val) ? x + (cx - isz.cx) / 2 : tx; w.DrawImage(xp, y + (cy - isz.cy) / 2, img, col); if(!IsNull(val)) tx += isz.cx + 3; } w.End(); } if(cx > lm + rm && cy > tm + bm) { int nx = x + lm; int ny = y + tm; int ncx = cx - lm - rm; int ncy = cy - tm - bm; w.Clip(nx, ny, ncx, ncy); int al = style & GD::ALIGN ? style & GD::ALIGN : align; Color fg = style & GD::READONLY ? SColorDisabled() : SColorText(); DrawText(w, tx, nx, ny, ncx, ncy, al, GetStdConvertedValue(val), fnt, fg, SColorPaper, 0, 0, 0, style & GD::WRAP); w.End(); } }
void GridDisplay::Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style, Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe) { real_size.cx = 0; real_size.cy = 0; if(cx == 0 || cy == 0) return; Color mg = bg; int al = style & GD::ALIGN ? style & GD::ALIGN : align; if(cx > lm + rm && cy > tm + bm) { int nx = x + lm; int ny = y + tm; int ncx = cx - lm - rm; int ncy = cy - tm - bm; if(IsNull(bgImg)) { if(lm > 0) w.DrawRect(x, y, lm, cy, mg); if(rm > 0) w.DrawRect(x + cx - rm, y, rm, cy, mg); if(tm > 0) w.DrawRect(x, y, cx, tm, mg); if(bm > 0) w.DrawRect(x, y + cy - bm, cx, bm, mg); w.DrawRect(nx, ny, ncx, ncy, bg); } else w.DrawImage(x, y, cx, cy, bgImg); w.Clip(nx, ny, ncx, ncy); if(!leftImg.IsEmpty()) { Size isz = leftImg.GetSize(); w.DrawImage(nx, ny + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(leftImg) : leftImg); nx += isz.cx + 3; ncx -= isz.cx + 3; } if(!rightImg.IsEmpty()) { Size isz = rightImg.GetSize(); w.DrawImage(nx + ncx - isz.cx, y + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(rightImg) : rightImg); } if(!centerImg.IsEmpty()) { Size isz = centerImg.GetSize(); w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(centerImg) : centerImg); } if(!(style & GD::NOTEXT)) { DrawText(w, nx, nx, ny, ncx, ncy, al, GetStdConvertedValue(val), fnt, fg, bg, found, fs, fe, style & GD::WRAP); } w.End(); } else w.DrawRect(x, y, cx, cy, bg); }
void WdeHandleDrawItem( DRAWITEMSTRUCT *dis ) { HBRUSH back_brush; COLORREF back_color; COLORREF fore_color; COLORREF old_back_color; COLORREF old_fore_color; HDC mem_dc; HBITMAP old_bitmap; HBITMAP check_bitmap; BITMAP bm; BITMAP check_bm; int x; int y; int border_width; RECT rc; WdeToolBitMapType *od_data; border_width = GetSystemMetrics( SM_CXBORDER ); if( dis->CtlType == ODT_MENU ) { od_data = (WdeToolBitMapType *)dis->itemData; check_bitmap = LoadBitmap( NULL, MAKEINTRESOURCE( OBM_CHECK ) ); GetObject( check_bitmap, sizeof( BITMAP ), &check_bm ); if( dis->itemState & ODS_SELECTED ) { back_brush = CreateSolidBrush( GetSysColor( COLOR_HIGHLIGHT ) ); back_color = GetSysColor( COLOR_HIGHLIGHT ); fore_color = GetSysColor( COLOR_HIGHLIGHTTEXT ); } else { back_brush = CreateSolidBrush( GetSysColor( COLOR_MENU ) ); back_color = GetSysColor( COLOR_MENU ); fore_color = GetSysColor( COLOR_MENUTEXT ); } FillRect( dis->hDC, &dis->rcItem, back_brush ); mem_dc = CreateCompatibleDC( dis->hDC ); old_bitmap = SelectObject( mem_dc, od_data->hbmp ); GetObject( od_data->hbmp, sizeof( BITMAP ), &bm ); x = dis->rcItem.left + check_bm.bmWidth + border_width; y = dis->rcItem.top + (dis->rcItem.bottom - dis->rcItem.top) / 2 - bm.bmHeight / 2; if( dis->itemState & ODS_SELECTED ) { PatBlt( mem_dc, 0, 0, bm.bmWidth, bm.bmHeight, DSTINVERT ); BitBlt( dis->hDC, x, y, bm.bmWidth, bm.bmHeight, mem_dc, 0, 0, SRCPAINT ); PatBlt( mem_dc, 0, 0, bm.bmWidth, bm.bmHeight, DSTINVERT ); } else { BitBlt( dis->hDC, x, y, bm.bmWidth, bm.bmHeight, mem_dc, 0, 0, SRCAND ); } if( dis->itemState & ODS_CHECKED ) { SelectObject( mem_dc, check_bitmap ); x = dis->rcItem.left + border_width; y = dis->rcItem.top + (dis->rcItem.bottom - dis->rcItem.top) / 2 - check_bm.bmHeight / 2; if( dis->itemState & ODS_SELECTED ) { PatBlt( mem_dc, 0, 0, check_bm.bmWidth, check_bm.bmHeight, DSTINVERT ); BitBlt( dis->hDC, x, y, check_bm.bmWidth, check_bm.bmHeight, mem_dc, 0, 0, SRCPAINT ); PatBlt( mem_dc, 0, 0, check_bm.bmWidth, check_bm.bmHeight, DSTINVERT ); } else { BitBlt( dis->hDC, x, y, check_bm.bmWidth, check_bm.bmHeight, mem_dc, 0, 0, SRCAND ); } } CopyRect( &rc, &dis->rcItem ); rc.left += bm.bmWidth + check_bm.bmWidth + border_width * 2 + 4; old_fore_color = SetTextColor( dis->hDC, fore_color ); old_back_color = SetBkColor( dis->hDC, back_color ); DrawText( dis->hDC, od_data->string, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); SetTextColor( dis->hDC, old_fore_color ); SetBkColor( dis->hDC, old_back_color ); SelectObject( mem_dc, old_bitmap ); DeleteObject( back_brush ); DeleteDC( mem_dc ); } }
void wxSVGCanvas::RenderElement(wxSVGElement* elem, const wxSVGRect* rect, const wxSVGMatrix* parentMatrix, const wxCSSStyleDeclaration* parentStyle, wxSVGSVGElement* ownerSVGElement, wxSVGElement* viewportElement, wxProgressDialog* progressDlg) { wxSVGMatrix matrix(*parentMatrix); wxCSSStyleRef style(*parentStyle); elem->SetOwnerSVGElement(ownerSVGElement); elem->SetViewportElement(viewportElement); switch (elem->GetDtd()) { case wxSVG_SVG_ELEMENT: { wxSVGSVGElement* element = (wxSVGSVGElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; if (element->GetWidth().GetAnimVal().GetUnitType() == wxSVG_LENGTHTYPE_UNKNOWN) ((wxSVGAnimatedLength&) element->GetWidth()).SetAnimVal( wxSVGLength(wxSVG_LENGTHTYPE_PERCENTAGE, 100)); if (element->GetHeight().GetAnimVal().GetUnitType() == wxSVG_LENGTHTYPE_UNKNOWN) ((wxSVGAnimatedLength&) element->GetHeight()).SetAnimVal( wxSVGLength(wxSVG_LENGTHTYPE_PERCENTAGE, 100)); element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); if (rect && element->GetParent()) { wxSVGRect rect2 = *rect; wxSVGElement* parent = (wxSVGElement*) element->GetParent(); wxSVGTransformable* transformable = wxSVGTransformable::GetSVGTransformable(*parent); if (transformable) rect2 = rect2.MatrixTransform(transformable->GetCTM().Inverse()); RenderChilds(elem, &rect2, &matrix, &style, element, element, progressDlg); } else RenderChilds(elem, rect, &matrix, &style, element, element, progressDlg); break; } case wxSVG_G_ELEMENT: { wxSVGGElement* element = (wxSVGGElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); RenderChilds(elem, rect, &matrix, &style, ownerSVGElement, viewportElement, progressDlg); break; } case wxSVG_LINE_ELEMENT: { wxSVGLineElement* element = (wxSVGLineElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawLine(element, &matrix, &style); break; } case wxSVG_POLYLINE_ELEMENT: { wxSVGPolylineElement* element = (wxSVGPolylineElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawPolyline(element, &matrix, &style); break; } case wxSVG_POLYGON_ELEMENT: { wxSVGPolygonElement* element = (wxSVGPolygonElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawPolygon(element, &matrix, &style); break; } case wxSVG_RECT_ELEMENT: { wxSVGRectElement* element = (wxSVGRectElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawRect(element, &matrix, &style); break; } case wxSVG_CIRCLE_ELEMENT: { wxSVGCircleElement* element = (wxSVGCircleElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawCircle(element, &matrix, &style); break; } case wxSVG_ELLIPSE_ELEMENT: { wxSVGEllipseElement* element = (wxSVGEllipseElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawEllipse(element, &matrix, &style); break; } case wxSVG_PATH_ELEMENT: { wxSVGPathElement* element = (wxSVGPathElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawPath(element, &matrix, &style); break; } case wxSVG_TSPAN_ELEMENT: break; case wxSVG_TEXT_ELEMENT: { wxSVGTextElement* element = (wxSVGTextElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawText(element, &matrix, &style); break; } case wxSVG_IMAGE_ELEMENT: { wxSVGImageElement* element = (wxSVGImageElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN || element->GetOpacity() == 0) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); DrawImage(element, &matrix, &style, rect, progressDlg); break; } case wxSVG_VIDEO_ELEMENT: { wxSVGVideoElement* element = (wxSVGVideoElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN || element->GetOpacity() == 0) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); #ifdef USE_LIBAV DrawVideo(element, &matrix, &style); #else wxSVGGElement* gElem = new wxSVGGElement(); gElem->SetOwnerSVGElement(ownerSVGElement); gElem->SetViewportElement(viewportElement); gElem->SetStyle(element->GetStyle()); wxSVGRectElement* rectElem = new wxSVGRectElement(); rectElem->SetX(element->GetX().GetAnimVal()); rectElem->SetY(element->GetY().GetAnimVal()); rectElem->SetWidth(element->GetWidth().GetAnimVal()); rectElem->SetHeight(element->GetHeight().GetAnimVal()); rectElem->SetFill(wxSVGPaint(0,0,0)); gElem->AppendChild(rectElem); wxSVGTextElement* textElem = new wxSVGTextElement; textElem->SetX((double)element->GetX().GetAnimVal()); textElem->SetY(element->GetY().GetAnimVal()+(double)element->GetHeight().GetAnimVal()/10); textElem->SetFontSize((double)element->GetHeight().GetAnimVal()/15); textElem->SetFill(wxSVGPaint(255,255,255)); textElem->SetStroke(wxSVGPaint(255,255,255)); textElem->AddChild(new wxSvgXmlNode(wxSVGXML_TEXT_NODE, wxT(""), wxT(" [") + element->GetHref() + wxT("]"))); gElem->AppendChild(textElem); // render RenderElement(gElem, rect, &matrix, &style, ownerSVGElement, viewportElement, progressDlg); // delete shadow tree delete gElem; #endif break; } case wxSVG_USE_ELEMENT: { wxSVGUseElement* element = (wxSVGUseElement*) elem; if (element->GetVisibility() == wxCSS_VALUE_HIDDEN) break; element->UpdateMatrix(matrix); style.Add(element->GetStyle()); style.Add(element->GetAnimStyle()); // test if visible if (element->GetWidth().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN && element->GetHeight().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN) { if (rect && !ownerSVGElement->CheckIntersection(*elem, *rect)) break; wxSVGPoint point(element->GetX().GetAnimVal() + element->GetWidth().GetAnimVal(), element->GetY().GetAnimVal() + element->GetHeight().GetAnimVal()); point = point.MatrixTransform(matrix); if (point.GetX() < 0 || point.GetY() < 0) break; } // get ref element wxString href = element->GetHref(); if (href.length() == 0 || href.GetChar(0) != wxT('#')) break; href.Remove(0, 1); wxSVGElement* refElem = (wxSVGElement*) ownerSVGElement->GetElementById(href); if (!refElem) break; // create shadow tree wxSVGGElement* gElem = new wxSVGGElement(); gElem->SetOwnerDocument(elem->GetOwnerDocument()); gElem->SetOwnerSVGElement(ownerSVGElement); gElem->SetViewportElement(viewportElement); gElem->SetStyle(element->GetStyle()); if (element->GetX().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN) gElem->Translate(element->GetX().GetAnimVal(), element->GetY().GetAnimVal()); if (refElem->GetDtd() == wxSVG_SYMBOL_ELEMENT || refElem->GetDtd() == wxSVG_SVG_ELEMENT) { wxSVGSVGElement* svgElem; if (refElem->GetDtd() == wxSVG_SVG_ELEMENT) svgElem = (wxSVGSVGElement*) refElem->CloneNode(); else { svgElem = new wxSVGSVGElement(); wxSvgXmlElement* child = refElem->GetChildren(); while (child) { svgElem->AddChild(child->CloneNode()); child = child->GetNext(); } svgElem->SetViewBox(((wxSVGSymbolElement*) refElem)->GetViewBox()); svgElem->SetPreserveAspectRatio(((wxSVGSymbolElement*) refElem)->GetPreserveAspectRatio()); } if (element->GetWidth().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN) svgElem->SetWidth(element->GetWidth().GetAnimVal()); if (element->GetHeight().GetAnimVal().GetUnitType() != wxSVG_LENGTHTYPE_UNKNOWN) svgElem->SetHeight(element->GetHeight().GetAnimVal()); gElem->AddChild(svgElem); LoadImages(refElem, svgElem, progressDlg); } else gElem->AddChild(refElem->CloneNode()); // render RenderElement(gElem, rect, &matrix, &style, ownerSVGElement, viewportElement, progressDlg); // delete shadow tree delete gElem; break; } default: break; } }
A4(PRIVATE, void, dobuttons, INTEGER, id, INTEGER, offsetx, INTEGER, offsety, BOOLEAN, demo_button_p) { struct bdef *bp; struct sdef *sp; struct pdef *pp; int i; EventRecord evt; int done; int tcnt, twid; Point p; #define BILLBUTTONS /* */ #if defined (BILLBUTTONS) INTEGER h, v; #endif /* BILLBUTTONS */ char *textp; if ((bp = (struct bdef *) findid(id))) { for (i = 0; i < Cx(bp->nbut); i++) { /* Offset buttons; this hack is to center the splash screen * on non-512x342 root windows...yuck! */ C_OffsetRect (&bp->buts[i].butloc, offsetx, offsety); if ((sp = (struct sdef *)findid(CW(bp->buts[i].butstrid)))) { if (demo_button_p && sp->text[0] == 'O' && sp->text[1] == 'K') textp = "Demo"; else textp = sp->text; tcnt = strlen(textp); twid = TextWidth((Ptr) textp, 0, tcnt); MoveTo((CW(bp->buts[i].butloc.left) + CW(bp->buts[i].butloc.right) - twid) / 2, (CW(bp->buts[i].butloc.top) + CW(bp->buts[i].butloc.bottom)) / 2 + 4); DrawText((Ptr) textp, 0, tcnt); } #if defined (BILLBUTTONS) h = CW(bp->buts[i].butloc.right) - CW(bp->buts[i].butloc.left); v = (CW(bp->buts[i].butloc.bottom) - CW(bp->buts[i].butloc.top))/2; if (h > v) h = v; if (!(ROMlib_options & ROMLIB_RECT_SCREEN_BIT)) FrameRoundRect(&bp->buts[i].butloc, h, v); else FrameRect(&bp->buts[i].butloc); #else /* BILLBUTTONS */ if (!(ROMlib_options & ROMLIB_RECT_SCREEN_BIT)) FrameRoundRect(&bp->buts[i].butloc, 10, 10); else FrameRect(&bp->buts[i].butloc); #endif /* BILLBUTTONS */ } for (done = 0; !done;) { C_GetNextEvent(mDownMask|keyDownMask, &evt); if (evt.what == CWC(mouseDown) || evt.what == CWC(keyDown)) { p.h = CW(evt.where.h); p.v = CW(evt.where.v); for (i = 0; !done && i < CW(bp->nbut); i++) { if (PtInRect(p, &bp->buts[i].butloc) || ((evt.what == CWC(keyDown)) && (((CL(evt.message) & charCodeMask) == '\r') || ((CL(evt.message) & charCodeMask) == NUMPAD_ENTER))) ) { if ((pp = (struct pdef *) findid(CW(bp->buts[i].butprocid)))) /* NOTE: we will have to do a better job here sometime */ (*(void (*)(void))MR(pp->proc))(); done = 1; } } if (!done) SysBeep(1); } } if (evt.what == CWC(mouseDown)) while (!C_GetNextEvent(mUpMask, &evt)) ; /* Move all buttons back. */ for (i = 0; i < Cx(bp->nbut); i++) C_OffsetRect (&bp->buts[i].butloc, -offsetx, -offsety); } }
//----------------------------------------------------------------------------- // Window message handler //----------------------------------------------------------------------------- LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { static WCHAR s_szMessage[1024] = {0}; switch( msg ) { case WM_KEYDOWN: { // Upon a game event, play a cue. For this simple tutorial, // pressing the space bar is a game event that will play a cue if( wParam == VK_SPACE ) g_audioState.pSoundBank->Play( g_audioState.iZap, 0, 0, NULL ); // To play a zero-latency cue: // 1) prepare it // 2) wait for it to be prepared // 3) play it with using the cue instance returned from the Prepare() function. if( wParam == 'A' ) { // The Play() call on a cue will only succeed if the cue is either preparing or // prepared meaning it can not be playing, etc. DWORD dwState; g_audioState.pZeroLatencyRevCue->GetState( &dwState ); if( ( dwState & ( XACT_CUESTATE_PREPARING | XACT_CUESTATE_PREPARED ) ) != 0 ) g_audioState.pZeroLatencyRevCue->Play(); } if( wParam == VK_ESCAPE ) PostQuitMessage( 0 ); break; } case WM_TIMER: { // Update message string every so often WCHAR szState[512]; if( g_audioState.pZeroLatencyRevCue ) { DWORD dwState; g_audioState.pZeroLatencyRevCue->GetState( &dwState ); switch( dwState ) { case XACT_CUESTATE_CREATED: StringCchCopy( szState, 512, L"Created, but nothing else" ); break; case XACT_CUESTATE_PREPARING: StringCchCopy( szState, 512, L"Preparing to play" ); break; case XACT_CUESTATE_PREPARED: StringCchCopy( szState, 512, L"Prepared, but not yet played" ); break; case XACT_CUESTATE_PLAYING: StringCchCopy( szState, 512, L"Playing, but can be paused" ); break; case XACT_CUESTATE_STOPPING: StringCchCopy( szState, 512, L"Stopping" ); break; case XACT_CUESTATE_STOPPED: StringCchCopy( szState, 512, L"Stopped" ); break; case XACT_CUESTATE_PAUSED: StringCchCopy( szState, 512, L"Paused" ); break; } } else { StringCchCopy( szState, 512, L"Not created" ); } EnterCriticalSection( &g_audioState.cs ); WCHAR sz[512]; StringCchPrintf( sz, 512, L"Press space to play an XACT cue called 'zap' which plays\n" L"from an in-memory wave bank\n" L"\n" L"Press 'A' to play a zero-latency cue when it is preparing or prepared.\n" L"When this cue stops, the tutorial releases it and prepares a new cue\n" L"Cue state: %s\n" L"\n" L"This tutorial is also playing background music in that is\n" L"contained in a streaming wave bank. When the background\n" L"music stops, a new song cue is played by the tutorial.\n" L"Currently playing: Song %d\n", szState, g_audioState.nCurSongPlaying + 1 ); LeaveCriticalSection( &g_audioState.cs ); if( wcscmp( sz, s_szMessage ) != 0 ) { // Repaint the window if needed StringCchCopy( s_szMessage, 1024, sz ); InvalidateRect( g_hWnd, NULL, TRUE ); UpdateWindow( g_hWnd ); } break; } case WM_PAINT: { // Paint some simple explanation text PAINTSTRUCT ps; HDC hDC = BeginPaint( hWnd, &ps ); SetBkColor( hDC, 0xFF0000 ); SetTextColor( hDC, 0xFFFFFF ); RECT rect; GetClientRect( hWnd, &rect ); rect.top = 70; DrawText( hDC, s_szMessage, -1, &rect, DT_CENTER ); EndPaint( hWnd, &ps ); return 0; } case WM_DESTROY: { PostQuitMessage( 0 ); break; } } return DefWindowProc( hWnd, msg, wParam, lParam ); }
/* * DisplayNumericStat: Display the given numeric type stat from the current group on the * main window. */ void DisplayNumericStat(Statistic *s) { RECT r; HDC hdc; HFONT hOldFont; char *name, *str; AREA stats_area; AREA a; // ajw - Avoid drawing if Inventory is selected as the "group". if( StatsGetCurrentGroup() == STATS_INVENTORY ) return; StatsGetArea(&stats_area); r.left = 0; r.right = stats_area.cx / 2; r.top = s->y; r.bottom = r.top + s->cy; /* If stat is out of stats area, abort */ if (r.bottom > stats_area.cy || s->num <= top_stat) return; hdc = GetDC(hStats); // DrawWindowBackground(hdc, &r, stats_area.x + r.left, stats_area.y + r.top); DrawWindowBackgroundColor( pinventory_bkgnd(), hdc, &r, stats_area.x + r.left, stats_area.y + r.top, -1 ); hOldFont = (HFONT) SelectObject(hdc, GetFont(FONT_STATS)); SetBkMode(hdc, TRANSPARENT); name = LookupNameRsc(s->name_res); // Draw with drop shadow SetTextColor(hdc, GetColor(COLOR_STATSBGD)); DrawText(hdc, name, strlen(name), &r, DT_LEFT); OffsetRect(&r, 1, 1); SetTextColor(hdc, GetColor(COLOR_STATSFGD)); DrawText(hdc, name, strlen(name), &r, DT_LEFT); switch (s->numeric.tag) { case STAT_RES: r.left = stats_area.cx / 2; r.right = stats_area.cx; DrawWindowBackgroundColor( pinventory_bkgnd(), hdc, &r, stats_area.x + r.left, stats_area.y + r.top, -1 ); str = LookupNameRsc(s->numeric.value); DrawText(hdc, str, strlen(str), &r, DT_RIGHT); break; case STAT_INT: // Draw background around stat bar a.x = stats_area.cx / 2; a.cx = stats_bar_width; a.y = s->y + (s->cy - STATS_BAR_HEIGHT) / 2; a.cy = STATS_BAR_HEIGHT; InterfaceDrawBarBorder( pinventory_bkgnd(), hdc, &a ); break; } SelectObject(hdc, hOldFont); ReleaseDC(hStats, hdc); InvalidateRect( s->hControl, NULL, FALSE ); }
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { HDC hdc; // Handle to our device context PAINTSTRUCT ps; // Paint structure for the WM_PAINT message static int scrollAmt; // This holds the amount we've scrolled down static SCROLLINFO scrollInfo; // This is the Windows struct that will hold the information // about our vertical scroll bar // Do different this depending on the message switch(message) { case WM_CREATE: scrollAmt = 0; // When we create the window, set our "scrollAmt" to zero, // since we haven't scrolled yet // Now we set the fields of the SCROLLINFO // This will ALWAYS needs to be set to the size of SCROLLINFO scrollInfo.cbSize = sizeof(SCROLLINFO); // This is the lowest amount (y-pos) that we can scroll to scrollInfo.nMin = 0; // This is the maximum amount (y-pos) that we can scroll to // So why did we choose 256? Well we don't know how large our text file is // going to be and how far we will need to be able scroll down. To do this in // a more robust way, we should first load our text file, see how much we need // to scroll down and then set the maximum amount we can scroll. But since we // know the file being loaded ahead of time, we take a small shortcut and hard code // a value that will allow us to the see the entire file scrollInfo.nMax = 256; // This represents the size of the page that is being scrolled on. So in a MS Word // application, depending on the layout, this might number might change. What it is // used to determine is the size of your scroll thumb (that's the little sliding // piece in the scroll bar). The larger the number, the bigger the thumb. scrollInfo.nPage = 1; // A SCROLLINFO has multiple member variables that can be set. When we pass the // structure to Windows to internally set these variables, Windows doesn't know which ones // we truly want to use. This is where the "fMask" variable comes in. We set it with a bunch // of flags that represent the variables in the struct, that we actually want to set. // The SIF_PAGE flag says "We've set the nPage variable, please use it". // The SIF_RANGE flag says "We've set the nMin and nMax variables, please use them." scrollInfo.fMask = SIF_PAGE | SIF_RANGE; // Now that we've set our SCROLLINFO, we need to let the window know about it. // The following function does that for it, it's parameters are: // hwnd -- The handle to our window // SB_VERT -- A flag specify what type of scroll bar we're dealing with, SB_VERT means // vertical scroll bar // &scrollInfo -- The address of the SCROLLINFO struct we filled // false -- A boolean value saying whether we want to redraw the scroll bar or not. SetScrollInfo(hwnd,SB_VERT,&scrollInfo,false); return 0; // This message is sent to a window when a scroll event occurs in a window's standard // vertical scroll bar case WM_VSCROLL: // If we get a vertical scrolling message, we need to check what the message is // all about. The LOWORD of the wparam tells us what the message is switch(LOWORD(wparam)) // Switch on the message { case SB_LINEUP: // The up arrow of the scroll bar has been clicked // If the scrollAmt is already at the minimum Y position then we can't move // up anymore so simply return if(scrollAmt == scrollInfo.nMin) return 0; else scrollAmt = scrollAmt - 1; // Otherwise, we want to scroll up by one unit break; case SB_LINEDOWN: // The down arrow of the scroll bar has been clicked // If the scrollAmt is already at the maximum Y position then we can't move // down anymore so simply return if(scrollAmt == scrollInfo.nMax) return 0; else scrollAmt = scrollAmt + 1; // Otherwise we want to scroll down by one unit break; // The user has dragged the thumb (that's the box inbetween the left and right arrows on // the scroll bar) by clicking it, dragging it, and then releasing the mouse button case SB_THUMBPOSITION: // We need to know the new position of the scroll bar. It is given to us // by the HIWORD of the WPARAM scrollAmt = HIWORD(wparam); break; default: // **NOTE** There are other messages that could be sent but we're not // going to do anything if we receive 'em. As always, for the // full unedited scoop, check out MSDN. break; } // end of switch(LOWORD(wparam)) // Alright if we get here, we know that we've updated our scroll bar's position // so we need to fill the SCROLLINFO with that information and then tell the // window about it scrollInfo.nPos = scrollAmt; // Set the new position scrollInfo.fMask = SIF_POS; // Set the flag saying "We're use the nPos value in SCROLLINFO" // Set the new position. // **NOTE** We pass true because we want the scroll bar redrawn to update it's // thumb position SetScrollInfo(hwnd, SB_VERT, &scrollInfo, true); // Lastly, we need to redraw the window to display the correct portion of the // text. What InvalidateRect does for us is specify a "dirty" region of // the window that needs to be repainted. When the window doesn't have any other messages // in it's message queue, it will generate a WM_PAINT message, and repaint all the // areas in it's dirty region. // By parameter: // hwnd -- Handle to the window who is to be repainted // NULL -- Rectangle area of the window to repaint. By passing NULL we are requesting // that the entire client area of the window be repainted // TRUE -- This is a boolean value that says whether the background should be redrawn // or not. For us, our background is solid white, and we want it redrawn so // the text doesn't draw over itself. Typically, this value will be set // to true. InvalidateRect(hwnd,NULL,TRUE); return 0; // This message is sent when the window needs to be repainted case WM_PAINT: // Begin painting to the window and get the HDC associated // with the window hdc = BeginPaint(hwnd, &ps); // The paint struct contains the area of the window for redrawing. We // want to subtract off the amount we've scrolled down, so that we show the // correct portion of text based on where we have vertically scrolled. ps.rcPaint.top -= scrollAmt; if(gText) { // DrawText(), as the name implies, this function draws text to the screen // By parameter: // hdc -- The handle to the device context to draw to // gText -- Pointer to the string for drawing // strlen(gText) -- Length of the string to draw // &(ps.rcPaint) -- Pointer to the bounding rectangle of where to draw the text // DT_WORDBREAK -- This parameter is for optional flags to DrawText(). This // specific flag says that if the text extends past the right // side of it's bounding rectangle, do a word wrap and continue // the text on the next line. DrawText(hdc, gText, strlen(gText), &(ps.rcPaint), DT_WORDBREAK); } // We've finished painting to the window EndPaint(hwnd, &ps); return 0; // When the program is destroyed case WM_DESTROY: PostQuitMessage(0); return 0; } // end of switch(message) return DefWindowProc(hwnd, message, wparam, lparam); }
// ---------------------------------------------------------------------- // Windows proc for the one and only window in this app. // // ---------------------------------------------------------------------- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HBRUSH hbrLit = NULL; static HBRUSH hbrUnlit = NULL; static HFONT hFont = NULL; static UINT_PTR nTimerId = 101; switch (message) { case WM_CREATE: { // Make BLACK the transparency color SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 0, LWA_COLORKEY); // Initialize the DPI scalar. InitializeDPIScale(hWnd); // Create brushes and font that will be used in WM_PAINT hbrLit = CreateSolidBrush(RGB(0,128,255)); hbrUnlit = CreateSolidBrush(RGB(0,64,128)); hFont = CreateFont(DPIScale(64), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, L"Segoe UI"); // Position at the center of the primary monitor POINT const ptZeroZero = {}; HMONITOR hMonitor = MonitorFromPoint(ptZeroZero, MONITOR_DEFAULTTOPRIMARY); MONITORINFO mi = {sizeof(mi)}; GetMonitorInfo(hMonitor, &mi); SIZE const size = { g_currentVolume.cSteps * DPIScale(10), DPIScale(60) }; POINT const pt = { mi.rcMonitor.left + (mi.rcMonitor.left + mi.rcMonitor.right - size.cx) / 2, mi.rcMonitor.top + (mi.rcMonitor.top + mi.rcMonitor.bottom - size.cy) / 2 }; SetWindowPos(hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, SWP_SHOWWINDOW); break; } case WM_DESTROY: { DeleteObject(hbrLit); DeleteObject(hbrUnlit); DeleteObject(hFont); PostQuitMessage(0); return 0; } case WM_ERASEBKGND: { // Don't do any erasing here. It's done in WM_PAINT to avoid flicker. return 1; } case WM_VOLUMECHANGE: { // get the new volume level g_pVolumeMonitor->GetLevelInfo(&g_currentVolume); // make window visible for 2 seconds ShowWindow(hWnd, SW_SHOW); InvalidateRect(hWnd, NULL, TRUE); nTimerId = SetTimer(hWnd, 101, 2000, NULL); return 0; } case WM_ENDPOINTCHANGE: { g_pVolumeMonitor->ChangeEndpoint(); return 0; } case WM_TIMER: { // make the window go away ShowWindow(hWnd, SW_HIDE); KillTimer(hWnd, nTimerId); return 0; } case WM_PAINT: { PAINTSTRUCT ps; HPAINTBUFFER hBufferedPaint = NULL; RECT rc; GetClientRect(hWnd, &rc); HDC hdc = BeginPaint(hWnd, &ps); if (g_bDblBuffered) { // Get doublebuffered DC HDC hdcMem; hBufferedPaint = BeginBufferedPaint(hdc, &rc, BPBF_COMPOSITED, NULL, &hdcMem); if (hBufferedPaint) { hdc = hdcMem; } } // black background (transparency color) FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); // Draw LEDs for (UINT i = 0; i < (g_currentVolume.cSteps-1); i++) { RECT const rcLed = { DPIScale(i * 10), DPIScale(10), DPIScale(i * 10 + 8), rc.bottom-DPIScale(15) }; if ((i < g_currentVolume.nStep) && (!g_currentVolume.bMuted)) FillRect(hdc, &rcLed, hbrLit); else FillRect(hdc, &rcLed, hbrUnlit); } if (g_currentVolume.bMuted) { HGDIOBJ hof = SelectObject(hdc, hFont); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(255, 64, 64)); RECT rcText = rc; rcText.bottom -= DPIScale(11); DrawText(hdc, L"MUTED", -1, &rcText, DT_CENTER | DT_SINGLELINE | DT_VCENTER); SelectObject(hdc, hof); } if (hBufferedPaint) { // end painting BufferedPaintMakeOpaque(hBufferedPaint, NULL); EndBufferedPaint(hBufferedPaint, TRUE); } EndPaint(hWnd, &ps); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
//Main program loop - Run gets called until it returns false bool Run() { //Main loop - get keypresses and interpret them keystate=GetRemoteKeys(); if(keystate & KEY_HOME) { return false; } switch(mode) { case 0: { //Splash screen if (keystate & KEY_INPUT2) { //Button B //Start game InitialiseGame(); PlaySound(SOUND_BEEP); } if (keystate & KEY_INPUT1) { //Button A //show help ShowHelp(); PlaySound(SOUND_BEEP); } } break; case 2: { //Help - wait for 'OK' press if (keystate & KEY_INPUT2) { //Button B //Reset back to splash screen ResetTimer(); mode=0; Splash(); PlaySound(SOUND_BEEP); } } break; case 1: { //Game if (keystate & KEY_INPUT1) { //Button A //Reset back to splash screen ResetTimer(); mode=0; Splash(); } if (keystate & KEY_RUN) { //Go button //Fire! PlaySound(SOUND_SHOOT); refreshCount = 0; int hit; hit = LineHitsObject(cameraPos, cameraAngle); if (hit == tankObjectIndex) { //we hit the tank! score += 100; CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); DrawExplosion(); DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); PlaySound(SOUND_EXPLOSION); PlaceTank(cameraPos, cameraAngle); } } //Have the movement sticks changed? This bit doesn't care about buttons if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) { MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); arrowRefAngle=cameraAngle.y; baselinePos=cameraPos; ResetTimer(); oldKeystate = keystate; if (keystate==0) //we've just stopped moving refreshCount=0; } if (mode==1) { if (sweepStepCount == SWEEPSTEPS) sweepStepCount=0; if (--behaviourCount<0) ChooseBehaviour(); MoveTank(); MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); //is it time to reset the tank model? Otherwise it gradually gets distorted if (--resetCount<0) { //Refresh the tank model which is prone to getting distorted //due to cumulative inaccuracies of sin/cos approximations Point3d angle=world.objects[tankObjectIndex].heading; Point3d tankPos=world.objects[tankObjectIndex].centre; world.objects[tankObjectIndex]=tank; MoveObject(&(world.objects[tankObjectIndex]), tankPos); RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y); resetCount=50; } //Is it time to redraw the world? if (--refreshCount<0) { //Seems a bit brutal to have to close graphics but it's //the only way to clear the screen that'll let us draw //on it properly again - ClearScreen or ClearRectangle mess up CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); refreshCount=2; } DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); //just in case we changed mode... if (mode==0) Splash(); } } } Sleep(50); return true; }
/*----------------------------------------------------------------------------- * Draw * The Draw function is the main loop for the Graphics process. Draws each * viewport and the lines within them *-----------------------------------------------------------------------------*/ void Draw( void ) { char buf[BUF_SIZ]; GLdouble answer[MATRIX_SIZE]; GLdouble attempt[MATRIX_SIZE]; /* Clear the screen ... */ glClear( GL_COLOR_BUFFER_BIT ); if(gameComplete) { DrawText(-25.0, -25.0, DEFAULT_FONT, "GAME OVER! YOU WIN!"); } else if(levelComplete) { DrawText(-25.0, -25.0, DEFAULT_FONT, "LEVEL COMPLETE!"); } else { glPushMatrix( ); /* Draw the Outlines for Transforms */ glCallList('a'); glCallList('s'); /* Draw the Axes */ glBegin( GL_LINES ); glColor3f( 0.5, 0.5, 0.5 ); glVertex3f( 100.0, 0.0, 0.0 ); glVertex3f(-100.0, 0.0, 0.0 ); glVertex3f( 0.0, 100.0, 0.0 ); glVertex3f( 0.0,-100.0, 0.0 ); glColor3f( 1.0, 1.0, 1.0 ); glEnd( ); glPopMatrix( ); /* Draw the first set of Available Transforms */ glPushMatrix( ); /* Move to origin of first list */ glTranslatef( 115.0, 90.0, 0.0 ); /* List drawing */ CreateTransforms( &tlAvailableTransforms, VERTICAL, AVAILABLE ); glPopMatrix( ); /* Draw the second set of Used Transforms */ glPushMatrix( ); /* Move to origin of first list */ glTranslatef( -85.0, -120.0, 0.0 ); /* List drawing */ CreateTransforms( &tlSelectedTransforms, HORIZONTAL, SELECTED ); glPopMatrix( ); glPushMatrix( ); /* Do all level transforms */ RunTransformList( &tlLevel ); /* Create model house */ glLoadName( 1 ); glCallList( 'l' ); /* Get the modelview matrix */ glGetDoublev( GL_MODELVIEW_MATRIX, answer ); glPopMatrix( ); /* Create the new house */ glPushMatrix( ); /* Do all user selected transforms */ RunTransformList( &tlSelectedTransforms ); /* Create attempt house */ glLoadName( HOUSE ); glCallList( 'h' ); /* Get the modelview matrix */ glGetDoublev( GL_MODELVIEW_MATRIX, attempt ); glPopMatrix( ); /* Compare the model */ if(CompareMatrices(answer, attempt)) { levelComplete = TRUE; glutPostRedisplay( ); } } /* Flush the buffer */ glutSwapBuffers(); return; }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hwndAddButton, hwndClearButton, hwndOutputText, hwndInputText, hwndLondonButton, hwndParisButton, hwndBerlinButton, hwndBuButton ; //all the handles to different controls PAINTSTRUCT ps; RECT rect; HDC hdc; //device context handle LRESULT textSize; char * message = new char[100]; //Text buffer char * placeholder = new char[26]; placeholder = "Add information..."; HFONT textFont,hFontOld; //Font handles int screenW; //characters ave width of string int screenH; //characters ave height of string HBRUSH color; switch (msg) /* handle the messages */ { case WM_CREATE: //Getting information about the average height and width of a letter screenW = GetSystemMetrics(SM_CXSCREEN); screenH = GetSystemMetrics(SM_CYSCREEN); //Getting the dimensions of the window area GetClientRect(hwnd, &rect); SetWindowPos( hwnd, 0, (screenW - rect.right)/2, (screenH - rect.bottom)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE); hwndAddButton = CreateWindowEx( (DWORD)WS_EX_CLIENTEDGE, TEXT("button"), // The class name required is button TEXT("Add"), // the caption of the button WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON, // the styles 440, 150, // the left and top co-ordinates 70, 30, // width and height hwnd, // parent window handle (HMENU)IDC_ADD_BUTTON, // the ID of your button hInst, // the instance of your application NULL); hwndClearButton = CreateWindowEx( (DWORD)WS_EX_CLIENTEDGE, TEXT("button"), // The class name required is button TEXT("Clear"), // the caption of the button WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles 440, 190, // the left and top co-ordinates 70, 30, // width and height hwnd, // parent window handle (HMENU)IDC_CLEAR_BUTTON, // the ID of your button hInst, // the instance of your application NULL); // extra bits you dont really need hwndOutputText = CreateWindowEx( (DWORD)NULL, TEXT("edit"), // The class name required is edit TEXT(""), // Default text. WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY, // Textbox styles 40, 130, // the left and top co-ordinates 390, 110, // width and height hwnd, // parent window handle (HMENU)IDC_OUTPUT_TEXT, // the ID of your editbox hInst, // the instance of your application NULL); // extra bits you dont really need hwndInputText = CreateWindowEx( (DWORD)NULL, TEXT("edit"), // The class name required is edit TEXT(placeholder), // Default text. WS_VISIBLE | WS_CHILD | WS_EX_CLIENTEDGE | ES_MULTILINE, // Textbox styles 40, 260, // the left and top co-ordinates 390, 20, // width and height hwnd, // parent window handle (HMENU)IDC_INPUT_TEXT, // the ID of your editbox hInst, // the instance of your application NULL); // extra bits you dont really need hwndLondonButton = CreateWindowEx( (DWORD)WS_EX_DLGMODALFRAME, TEXT("button"), // The class name required is button TEXT("London"), // the caption of the button WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, // the styles 40, 70, // the left and top co-ordinates 80, 30, // width and height hwnd, // parent window handle (HMENU)IDC_LONDON_BUTTON, // the ID of your button hInst, // the instance of your application NULL); hwndParisButton = CreateWindowEx( (DWORD)WS_EX_DLGMODALFRAME, TEXT("button"), // The class name required is button TEXT("Paris"), // the caption of the button WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, // the styles 190, 70, // the left and top co-ordinates 80, 30, // width and height hwnd, // parent window handle (HMENU)IDC_PARIS_BUTTON, // the ID of your button hInst, // the instance of your application NULL); hwndBerlinButton = CreateWindowEx( (DWORD)WS_EX_DLGMODALFRAME, TEXT("button"), // The class name required is button TEXT("Berlin"), // the caption of the button WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, // the styles 350, 70, // the left and top co-ordinates 80, 30, // width and height hwnd, // parent window handle (HMENU)IDC_BERLIN_BUTTON, // the ID of your button hInst, // the instance of your application NULL); hwndBuButton = CreateWindowEx( (DWORD)WS_EX_DLGMODALFRAME, TEXT("button"), // The class name required is button TEXT("Choose"), // the caption of the button WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, // the styles 440, 280, // the left and top co-ordinates 70, 48, // width and height hwnd, // parent window handle (HMENU)IDC_BU_BUTTON, // the ID of your button hInst, // the instance of your application NULL); break; // WM_SIZE?? /*This message limits the window's minimal height and width** */ case WM_GETMINMAXINFO: { ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 554; ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 376; break; } case WM_COMMAND: //Handling button presses switch(LOWORD(wParam)) { case IDC_ADD_BUTTON: //sending the message from the edit box to the list box textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message); message[textSize] = _T('\0'); if(strlen(message) && strcmp(message, placeholder)) { char *item = new char[200]; if(items) strcpy(item, "\r\n > "); else strcpy(item, " > "); // Managing the new string strcat(item, message); SendMessage(hwndOutputText, EM_REPLACESEL, TRUE, (LPARAM)item); // Appending a new item in the list SendMessage(hwndInputText, WM_SETTEXT, TRUE,(LPARAM)""); // Clearing the text input delete [] item; // Managing the memory items += 1; // Incrementing the number of items SendMessage( hwndInputText, WM_SETTEXT, TRUE, (LPARAM)placeholder); // Recovering the placeholder focused = 0; } RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE); break; case IDC_CLEAR_BUTTON: SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)""); break; case IDC_INPUT_TEXT: if(HIWORD(wParam) == EN_SETFOCUS) { textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message); message[textSize] = _T('\0'); if(!strcmp(message, placeholder)) { SendMessage(hwndInputText, WM_SETTEXT, TRUE,(LPARAM)""); // Clearing the text input focused = 1; RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE); } } else if(HIWORD(wParam) == EN_KILLFOCUS) { textSize = SendMessage(hwndInputText, WM_GETTEXT, 100, (LPARAM)message); message[textSize] = _T('\0'); if(!strcmp(message, "")) { SendMessage( hwndInputText, WM_SETTEXT, TRUE, (LPARAM)placeholder); // Recovering the placeholder focused = 0; RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE); } } break; case IDC_LONDON_BUTTON: SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)" London, England’s capital, set on the River Thames, " " is a 21st-century city with history stretching back to Roman times." " At its centre stand the imposing Houses of Parliament, the iconic ‘Big Ben’ " " clock tower and Westminster Abbey, site of British monarch coronations." " Across the Thames, the London Eye observation wheel provides panoramic views " " of the South Bank cultural complex, and the entire city." " London attracts 27 million overnight-stay visitors every year." " London is a major global centre of higher education teaching and research and " " its 43 universities form the largest concentration of higher education institutes in Europe."); break; case IDC_PARIS_BUTTON: SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)" Paris is the capital and most populous city of France. " " Situated on the Seine River, in the north of the country, it is in the centre of the Île-de-France region, also known as the région parisienne, Paris Region." " Since the 19th century, the built-up area of Paris has grown far beyond its administrative borders;" " together with its suburbs, the whole agglomeration has a population of 10,550,350" " Paris was founded in the 3rd century BC by a Celtic people called the Parisii, who gave the city its name." " By the 12th century, Paris was the largest city in the western world, a prosperous trading centre, " " and the home of the University of Paris, one of the first in Europe." " In the 18th century, it was the centre stage for the French Revolution, and became an important centre of " " finance, commerce, fashion, science, and the arts, a position it still retains today. " " The city is a major rail, highway, and air-transport hub, served by the two international airports Paris-Charles de Gaulle and Paris-Orly." ); break; case IDC_BERLIN_BUTTON: SendMessage(hwndOutputText, WM_SETTEXT, 0, (LPARAM)" Berlin is the capital of Germany and one of the 16 states of Germany. With a population of 3.5 million people," " it is the second most populous city proper and the seventh most populous urban area in the European Union." " Located in northeastern Germany on the banks of Rivers Spree and Havel, it is the centre of the" " Berlin-Brandenburg Metropolitan Region, which has about six million residents from over 180" " nations.Due to its location in the European Plain, Berlin is influenced by a temperate seasonal" " climate. Around one-third of the city's area is composed of forests, parks, gardens, rivers and lakes."); break; case IDC_BU_BUTTON: if (MessageBox(NULL, TEXT("Are you sure you want to choose that destination?"), TEXT("The city you love"), MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) == IDYES) { return MessageBox(NULL, TEXT("Great Decision !!!"), TEXT("Congratulations!"), MB_OK | MB_ICONASTERISK); }; break; } break; case WM_CTLCOLOREDIT: if(GetDlgCtrlID((HWND)lParam) == IDC_INPUT_TEXT) { hdc = (HDC)wParam; //Get handles if(focused) { color = CreateSolidBrush(RGB(255, 255, 255)); SetTextColor(hdc, RGB(0,0,0)); // Text color SetBkMode(hdc, TRANSPARENT); // EditBox Backround Mode SetBkColor(hdc,(LONG)color); // Backround color for EditBox } else { color = CreateSolidBrush(RGB(255, 255, 255)); SetTextColor(hdc, RGB(110,123,139)); // Text color SetBkMode(hdc, TRANSPARENT); // EditBox Backround Mode SetBkColor(hdc,(LONG)color); // Backround color for EditBox } return (LONG)color; // Paint it } break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); // Getting coordinates of window client area SetBkMode(hdc, TRANSPARENT); // Set the background to be transparent SetTextColor(hdc, RGB(255,231,186)); // Setting the text color to a pale orange DrawText(hdc, "\nTravel and discover", -1, &rect, DT_CENTER | DT_TOP); // Drawing the text on top aligning it to center textFont = CreateFont(0, 0, 0, 0, FW_SEMIBOLD, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman"); // Creating the text font to semibold, italic, choosing Times New Roman font hFontOld = (HFONT)SelectObject(hdc,textFont); // Setting the text font SetTextColor(hdc,RGB(238,173,14)); // Setting the text color to a dark orange SetBkMode(hdc, TRANSPARENT); // Set the background to be transparent DrawText(hdc, "\n\nChoose your destination", -1, &rect, DT_CENTER | DT_TOP); // Drawing the text on top aligning it to center SetTextColor(hdc, RGB(0, 100, 0)); // Resetting the color to black EndPaint(hwnd, &ps); break; case WM_DRAWITEM: if ((UINT)wParam == IDC_LONDON_BUTTON) { LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam; SIZE size; char szLondonBtnText[7]; strcpy(szLondonBtnText, "London"); GetTextExtentPoint32(lpdis->hDC, szLondonBtnText, strlen(szLondonBtnText), &size); SetTextColor(lpdis->hDC, RGB(245,245,220)); SetBkColor(lpdis->hDC, RGB(150,104,108)); ExtTextOut( lpdis->hDC, ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2, ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2, ETO_OPAQUE | ETO_CLIPPED, &lpdis->rcItem, szLondonBtnText, strlen(szLondonBtnText), NULL); DrawEdge( lpdis->hDC, &lpdis->rcItem, (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT); return TRUE; } else if ((UINT)wParam == IDC_PARIS_BUTTON) { LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam; SIZE size; char szParisBtnText[6]; strcpy(szParisBtnText, "Paris"); GetTextExtentPoint32(lpdis->hDC, szParisBtnText, strlen(szParisBtnText), &size); SetTextColor(lpdis->hDC, RGB(245,245,220)); SetBkColor(lpdis->hDC, RGB(150,104,108)); ExtTextOut( lpdis->hDC, ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2, ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2, ETO_OPAQUE | ETO_CLIPPED, &lpdis->rcItem, szParisBtnText, strlen(szParisBtnText), NULL); DrawEdge( lpdis->hDC, &lpdis->rcItem, (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT); return TRUE; } else if ((UINT)wParam == IDC_BERLIN_BUTTON) { LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam; SIZE size; char szBerlinBtnText[7]; strcpy(szBerlinBtnText, "Berlin"); GetTextExtentPoint32(lpdis->hDC, szBerlinBtnText, strlen(szBerlinBtnText), &size); SetTextColor(lpdis->hDC, RGB(245,245,220)); SetBkColor(lpdis->hDC, RGB(150,104,108)); ExtTextOut( lpdis->hDC, ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2, ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2, ETO_OPAQUE | ETO_CLIPPED, &lpdis->rcItem, szBerlinBtnText, strlen(szBerlinBtnText), NULL); DrawEdge( lpdis->hDC, &lpdis->rcItem, (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT); return TRUE; } else if ((UINT)wParam == IDC_BU_BUTTON) { LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT*)lParam; SIZE size; char szBuBtnText[7]; strcpy(szBuBtnText, "Choose"); GetTextExtentPoint32(lpdis->hDC, szBuBtnText, strlen(szBuBtnText), &size); SetTextColor(lpdis->hDC, RGB(245,245,220)); SetBkColor(lpdis->hDC, RGB(50,174,208)); ExtTextOut( lpdis->hDC, ((lpdis->rcItem.right - lpdis->rcItem.left) - size.cx) / 2, ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2, ETO_OPAQUE | ETO_CLIPPED, &lpdis->rcItem, szBuBtnText, strlen(szBuBtnText), NULL); DrawEdge( lpdis->hDC, &lpdis->rcItem, (lpdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT); return TRUE; } break; case WM_SYSCOMMAND: switch(wParam) { case SC_MINIMIZE: return MessageBox(NULL, TEXT("STOP! Do not do it!"), TEXT("Minimize Button Clicked!"), MB_OK | MB_ICONSTOP); case SC_MAXIMIZE: return MessageBox(NULL, TEXT("Hey! You just clicked Maximize button"), TEXT("Maximize Button Clicked!"), MB_OK | MB_ICONEXCLAMATION); case SC_CLOSE: if(MessageBox(hwnd, "Are you sure that you want to close this window?", "Close Travel App", MB_OKCANCEL) == IDOK) DestroyWindow(hwnd); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, msg, wParam, lParam); } return 0; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){ //tab controls INITCOMMONCONTROLSEX ic; static RECT rcDisp; //trackbar static HWND hTrack = NULL; // buttons and edit(read-only) handles static HWND hOpen = NULL; static HWND hPlay = NULL; static HWND hPause = NULL; static HWND hStop = NULL; static HWND hLoop = NULL; static HWND hDown = NULL; static HWND hUp = NULL; static HWND hExit = NULL; static HDC hdc; PAINTSTRUCT ps; DWORD dw; int i, ia; short s; static LPDWORD lpPixel; static BITMAPINFO bmpInfo; static int iWidth, iHeight; static LPDWORD lpPixelCursor; static BITMAPINFO bmpInfoCursor; static int iWidthCursor, iHeightCursor, iTimeCursor; static int iPixel = 0; HBITMAP hBmp; static HDC hdc_mem; // file static OPENFILENAME ofn; static char szFile[MAX_PATH]; static char szFileTitle[MAX_PATH]; //wav file static HWAVEOUT hWaveOut; static WAVEFORMATEX wfe; static WAVEHDR whdr; const RECT rcWave = {10, 10, 1225, 447};//10, 20, 1235, 550 //10, 10, 631, 381 const RECT rcBar = {10, 390, 631, 401}; static RECT rcInfo[] = {{1, 1060, 900, 20}, {2000, 1060, 110, 20}, {2220, 1060, 110, 20}, {2335, 1060, 108, 20}}; static RECT rcMove = rcInfo[0]; static MMTIME mmTime; static DWORD maxTime; DWORD dwOffset; // wave static POINT ptWaveL[1226], ptWaveR[1226];//621 static WORD wHalfMaxAmp; static HPEN hPenL, hPenR; static int hueL, hueR, hueLR; // volume static DWORD dwVolStart; static WORD wVolNow; DWORD dwVolTemp; // font static HFONT hFont[3]; static BYTE rr = 0, gg = 128, bb = 128; // open, pause, exit static BYTE r = 0, g = 128, b = 128; // play static BYTE rs = 0, gs = 128, bs = 128; // stop static BYTE vr1 = 0, vg1 = 128, vb1 = 128; // volume-down static BYTE vr2 = 0, vg2 = 128, vb2 = 128; // volume-up static BYTE rLoop = 0, gLoop = 128, bLoop = 128; // loop //text static char strFile[1024]; static char strTime[32]; static char strVol[16]; static char strState[16]; static SIZE sizeFile; static BOOL open = FALSE; static BOOL play = FALSE; static BOOL pause = FALSE; static BOOL loop = FALSE; switch( msg ){ case WM_CREATE: DragAcceptFiles(hwnd, TRUE); // background bmp lpPixel = bmptoDIB("480127.bmp", &bmpInfo); iWidth = bmpInfo.bmiHeader.biWidth; iHeight = bmpInfo.bmiHeader.biHeight; // get Window's device context handle hdc = GetDC( hwnd ); hBmp = CreateCompatibleBitmap(hdc, iWidth, iHeight); // make memory device context hdc_mem = CreateCompatibleDC(hdc); // select bitmap which is loaded SelectObject( hdc_mem, hBmp ); DeleteObject(hBmp); ReleaseDC(hwnd, hdc); // initialize OPENFILENAME ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "WAVE_FORMAT_PCM(*.wav)\0*.wav\0"; ofn.lpstrFile = szFile; ofn.nMaxFile = MAX_PATH; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST; ofn.lpstrDefExt = "wav"; ofn.lpstrTitle = "Select PCM type of Wav file"; // create pen hPenL = CreatePen(PS_SOLID, 1, RGB(255,255,0)); // hPenR = CreatePen(PS_SOLID, 1, RGB(0,255,255)); // // initialize a coordinate for wave for(i = 0; i< sizeof(ptWaveL)/sizeof(ptWaveL[0]); i++) { ptWaveL[i].x = 10+i; ptWaveL[i].y = -10; ptWaveR[i].x = 10+i; ptWaveR[i].y = -10; } // change background mode SetBkMode(hdc_mem, TRANSPARENT); hFont[0] = CreateFont(18, 0, 0, 0, FW_BOLD, TRUE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "Times New Roman"); hFont[1] = CreateFont(24, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "Arial Black"); hFont[2] = CreateFont(12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "Times New Roman"); // initialize MMTIME mmTime.wType = TIME_BYTES; // store an initial value for volume and show the volume waveOutGetVolume(hWaveOut, &dwVolStart); wVolNow = LOWORD(dwVolStart); wsprintf(strVol, "%03d/128", (wVolNow +1)/512); // show state wsprintf(strState, "NoData"); //button hOpen = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Open") , WS_CHILD | WS_VISIBLE , 15, 620 , 70 , 30 , hwnd , (HMENU)ID_OPEN, ((LPCREATESTRUCT)(lp))->hInstance , NULL); hPlay = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Play") , WS_CHILD | WS_VISIBLE , 90, 620 , 70 , 30 , hwnd , (HMENU)ID_PLAY, ((LPCREATESTRUCT)(lp))->hInstance , NULL); hPause = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Pause") , WS_CHILD | WS_VISIBLE , 165 , 620 , 70 , 30 , hwnd , (HMENU)ID_PAUSE, ((LPCREATESTRUCT)(lp))->hInstance , NULL); hStop = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Stop") , WS_CHILD | WS_VISIBLE , 240 , 620 , 70 , 30 , hwnd , (HMENU)ID_STOP, ((LPCREATESTRUCT)(lp))->hInstance , NULL); hLoop = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Loop") , WS_CHILD | WS_VISIBLE , 900 , 620 , 70 , 30 , hwnd , (HMENU)ID_LOOP, ((LPCREATESTRUCT)(lp))->hInstance , NULL); hDown = CreateWindowEx(0, TEXT("BUTTON"), TEXT("-") , WS_CHILD | WS_VISIBLE , 1000 , 620 , 40 , 30 , hwnd , (HMENU)ID_DOWN, ((LPCREATESTRUCT)(lp))->hInstance, NULL); hUp = CreateWindowEx(0, TEXT("BUTTON"), TEXT("+") , WS_CHILD | WS_VISIBLE , 1050 , 620 , 40 , 30 , hwnd , (HMENU)ID_UP, ((LPCREATESTRUCT)(lp))->hInstance , NULL); hExit = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Exit") , WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 1160, 620 , 70 , 30 , hwnd , (HMENU)ID_EXITT, ((LPCREATESTRUCT)(lp))->hInstance, NULL); //track bar ic.dwSize = sizeof(INITCOMMONCONTROLSEX); ic.dwICC = ICC_BAR_CLASSES; InitCommonControlsEx(&ic); hTrack = CreateWindowEx(0, TRACKBAR_CLASS, "", WS_CHILD | WS_VISIBLE | TBS_HORZ | TBS_AUTOTICKS, 10, 580, 1230, 25, hwnd, (HMENU)IDC_TRACKBAR, ((LPCREATESTRUCT)(lp))->hInstance, NULL); // TrackProc = (WNDPROC)GetWindowLong(hTrack, GWL_WNDPROC); //SetWindowLong(hTrack, GWL_WNDPROC, (LONG)TrackProc); // SendMessage(hTrack, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELPARAM(0, 100)); return 0; case WM_SIZE: return 0; /*case WM_NOTIFY: switch (((NMHDR *)lp)->code){ case TCN_SELCHANGE: if (TabCtrl_GetCurSel(hTab) == 0){ InvalidateRect(hTab, &rcDisp, FALSE); InvalidateRect(hStatic, NULL, FALSE); }else if(TabCtrl_GetCurSel(hTab) == 1){ InvalidateRect(hStatic, NULL, FALSE); }else{ } break; case TCN_SELCHANGING: return FALSE; } return 0; */ case WM_COMMAND: switch(LOWORD(wp)) { case ID_TAB: break; case ID_OPTIONS_DOWNLOADMUSIC: //////////////////////// CREATE UDP SOCKET FROM MENU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! break; case ID_OPTIONS_MICROPHONE: ///////////////////// CREATE MICROPHONE FROM MENU !!!!!!!!!!!!!!!!!!!! break; case ID_DIRECTX_MULTIPLAYER: hTab = MakeTabCtrl(hwnd); // PostMessage(hStatic, ID_STATIC, (WPARAM)0, (LPARAM)0); break; case ID_DIRECTX_TABCLOSEFORMULTIPLAYER: break; case ID_OPEN: // when "Open" is pushed if(GetOpenFileName(&ofn)) { if(open) { play=FALSE; pause=FALSE; KillTimer(hwnd, 1); rcMove.left = rcInfo[0].left; iTimeCursor = 0; waveOutReset(hWaveOut); waveOutUnprepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR)); waveOutClose(hWaveOut); HeapFree(GetProcessHeap(), 0, whdr.lpData); } if(waveIn(ofn.lpstrFile, &hWaveOut, &wfe, &whdr)) { for(i=0;i<sizeof(ptWaveL)/sizeof(ptWaveL[0]);i++) { ptWaveL[i].y = -10; //default value ptWaveR[i].y = -10; //default value } strFile[0] = NULL; strTime[0] = NULL; wsprintf(strState, "NoData"); InvalidateRect(hwnd, &rcWave, FALSE); InvalidateRect(hwnd, &rcInfo[0], FALSE); InvalidateRect(hwnd, &rcInfo[1], FALSE); InvalidateRect(hwnd, &rcInfo[3], FALSE); return 0; } waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfe, (DWORD)hwnd, 0, CALLBACK_WINDOW); waveOutPrepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR)); wHalfMaxAmp = pow(2, wfe.wBitsPerSample-1); //half of the max amplitud for(i=0;i<sizeof(ptWaveL)/sizeof(ptWaveL[0]);i++) ptWaveL[i].y=250; //screen center for wave if(wfe.nChannels == 2) { for(i = 0 ; i < sizeof(ptWaveR)/sizeof(ptWaveR[0]) ; i++) ptWaveR[i].y = 250; //screen center for wave } else { for(i = 0 ; i < sizeof(ptWaveR)/sizeof(ptWaveR[0]) ; i++) ptWaveR[i].y = -10; //default value } wsprintf(strFile,"%s :- %d bits / %s / %d Hz", ofn.lpstrFileTitle,wfe.wBitsPerSample, (wfe.nChannels==2)?"stereo":"mono",wfe.nSamplesPerSec); SelectObject(hdc_mem,hFont[2]); GetTextExtentPoint32(hdc_mem,strFile,(int)strlen(strFile),&sizeFile); maxTime=100*whdr.dwBufferLength/wfe.nAvgBytesPerSec; wsprintf(strTime,"00:00:00/%02d:%02d:%02d", (maxTime/100)/60,(maxTime/100)%60,maxTime%100); //total time open=TRUE; wsprintf(strState,"ready"); InvalidateRect(hwnd,&rcWave,FALSE); InvalidateRect(hwnd,&rcInfo[0],FALSE); InvalidateRect(hwnd,&rcInfo[1],FALSE); InvalidateRect(hwnd,&rcInfo[3],FALSE); } return 0; case ID_PLAY: // when "Play" is pressed if(!open || play) return 0; //file is open but not playing play=TRUE; wsprintf(strState,"playing"); InvalidateRect(hwnd,&rcInfo[3],FALSE); if(pause) { pause=FALSE; waveOutRestart(hWaveOut); } else { iTimeCursor=0; waveOutWrite(hWaveOut,&whdr,sizeof(WAVEHDR)); } SetTimer(hwnd,1,50,NULL); break; case ID_PAUSE: // when "Pause" button is pushed if(!play && !pause) return 0; //playing or pause if(pause) { pause=FALSE; play=TRUE; wsprintf(strState,"playing"); waveOutRestart(hWaveOut); SetTimer(hwnd,1,50,NULL); } else { pause=TRUE; play=FALSE; wsprintf(strState,"pause"); waveOutPause(hWaveOut); KillTimer(hwnd,1); } InvalidateRect(hwnd,&rcInfo[3],FALSE); break; case ID_STOP: // when "Stop" button is pressed if(!open) return 0; if(play) { //pushed during playing play=FALSE; pause=FALSE; iTimeCursor=0; waveOutReset(hWaveOut); //MM_WOM_DONE message is sent } else { for(i=0;i<sizeof(ptWaveL)/sizeof(ptWaveL[0]);i++) ptWaveL[i].y=250; //center for wave drawn if(wfe.nChannels==2) for(i=0;i<sizeof(ptWaveR)/sizeof(ptWaveR[0]);i++) ptWaveR[i].y=250; //center for wave drawn if(pause) { //pushed during pause play=FALSE; pause=FALSE; waveOutReset(hWaveOut); rcMove.left=rcInfo[0].left; wsprintf(strState,"ready"); InvalidateRect(hwnd,&rcWave,FALSE); InvalidateRect(hwnd,&rcInfo[0],FALSE); InvalidateRect(hwnd,&rcInfo[3],FALSE); } //pushed again after pause iTimeCursor=0; wsprintf(strTime,"00:00:00/%02d:%02d:%02d", (maxTime/100)/60,(maxTime/100)%60,maxTime%100); //total time InvalidateRect(GetTopWindow(hwnd),&rcInfo[1],FALSE); } break; case ID_LOOP: if(loop) { loop=FALSE; } else { loop=TRUE; } break; case ID_DOWN://- waveOutGetVolume(hWaveOut,&dwVolTemp); ia=LOWORD(dwVolTemp); // store in wVolNow after mute cancellation ia-=512; wVolNow=(ia<0)?0:ia; waveOutSetVolume(hWaveOut,MAKELONG(wVolNow,wVolNow)); wsprintf(strVol,"%03d/128",(wVolNow+1)/512); InvalidateRect(hwnd,&rcInfo[2],FALSE); break; case ID_UP: waveOutGetVolume(hWaveOut,&dwVolTemp); ia=LOWORD(dwVolTemp); // store in wVolNow after mute cancellation ia+=512; wVolNow=(ia>0xFFFF)?0xFFFF:ia; waveOutSetVolume(hWaveOut,MAKELONG(wVolNow,wVolNow)); wsprintf(strVol,"%03d/128",(wVolNow+1)/512); InvalidateRect(hwnd,&rcInfo[2],FALSE); break; case ID_EXITT: case ID_EXIT_EXIT: KillTimer(hwnd,1); // SetWindowLong(hTrack, GWL_WNDPROC, (LONG)TrackProc); // DestroyWindow(hTrack); ExitProcess(-1); DestroyWindow(hwnd); break; } return 0; /*case WM_HSCROLL: if( (HWND)lp == GetDlgItem( hwnd, IDC_SLIDER ) ){ pos = SendMessage( (HWND)lp, TBM_GETPOS, 0, 0 ); } return 0;*/ case WM_DROPFILES: //drag and drop for file DragQueryFile((HDROP)wp, 0, strFile, sizeof(strFile)); DragFinish((HDROP)wp); //when open button is pushed if(open) { play = FALSE; pause = FALSE; KillTimer(hwnd, 1); rcMove.left = rcInfo[0].left; iTimeCursor = 0; waveOutReset(hWaveOut); waveOutUnprepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR)); waveOutClose(hWaveOut); HeapFree(GetProcessHeap(), 0, whdr.lpData); } if(waveIn(strFile, &hWaveOut, &wfe, &whdr)) { //finished abnormaly for(i = 0 ; i < sizeof(ptWaveL)/sizeof(ptWaveL[0]) ; i++) { ptWaveL[i].y = -10; //default value ptWaveR[i].y = -10; //default value } strFile[0] = NULL; strTime[0] = NULL; wsprintf(strState, "NoData"); InvalidateRect(hwnd, &rcWave, FALSE); InvalidateRect(hwnd, &rcInfo[0], FALSE); InvalidateRect(hwnd, &rcInfo[1], FALSE); InvalidateRect(hwnd, &rcInfo[3], FALSE); return 0; } waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfe, (DWORD)hwnd, 0, CALLBACK_WINDOW); waveOutPrepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR)); wHalfMaxAmp=pow(2, wfe.wBitsPerSample - 1); //half of the max amplitud for(i=0;i<sizeof(ptWaveL)/sizeof(ptWaveL[0]);i++) ptWaveL[i].y=250; //screen center for wave if(wfe.nChannels == 2) { for(i = 0 ; i < sizeof(ptWaveR)/sizeof(ptWaveR[0]) ; i++) ptWaveR[i].y = 250; //screen center for wave } else { for(i = 0 ; i < sizeof(ptWaveR)/sizeof(ptWaveR[0]) ; i++) ptWaveR[i].y = -10; //default value } wsprintf(strFile, "%s :- %d bits / %s / %d Hz", PathFindFileName(strFile), wfe.wBitsPerSample, (wfe.nChannels==2)?"stereo":"mono", wfe.nSamplesPerSec); SelectObject(hdc_mem, hFont[2]); GetTextExtentPoint32(hdc_mem, strFile, (int)strlen(strFile), &sizeFile); maxTime = 100*whdr.dwBufferLength/wfe.nAvgBytesPerSec; wsprintf(strTime,"00:00:00/%02d:%02d:%02d", (maxTime/100)/60,(maxTime/100)%60,maxTime%100); //total time open=TRUE; wsprintf(strState, "ready"); InvalidateRect(hwnd, &rcWave, FALSE); InvalidateRect(hwnd, &rcInfo[0], FALSE); InvalidateRect(hwnd, &rcInfo[1], FALSE); InvalidateRect(hwnd, &rcInfo[3], FALSE); return 0; case MM_WOM_DONE: pause = FALSE; waveOutReset(hWaveOut); if(loop && play) { iTimeCursor = 0; waveOutWrite(hWaveOut, &whdr, sizeof(WAVEHDR)); return 0; } if(play) { //play completed iTimeCursor = 600; wsprintf(strTime,"%02d:%02d:%02d/%02d:%02d:%02d", (maxTime/100)/60,(maxTime/100)%60,maxTime%100, //current time (maxTime/100)/60,(maxTime/100)%60,maxTime%100); //total time } for(i = 0 ; i < sizeof(ptWaveL)/sizeof(ptWaveL[0]) ; i++) ptWaveL[i].y=250; //center for wave drawn 195 if(wfe.nChannels == 2) for(i=0 ; i<sizeof(ptWaveR)/sizeof(ptWaveR[0]) ; i++) ptWaveR[i].y=250; //center for wave drawn 195 play = FALSE; rcMove.left = rcInfo[0].left; wsprintf(strState, "ready"); KillTimer(hwnd, 1); InvalidateRect(hwnd, &rcWave, FALSE); InvalidateRect(hwnd, &rcInfo[0], FALSE); InvalidateRect(hwnd, &rcInfo[1], FALSE); InvalidateRect(hwnd, &rcInfo[3], FALSE); return 0; case WM_TIMER: rcMove.left-= 1; if(rcMove.left<-sizeFile.cx) rcMove.left = rcInfo[0].right; waveOutGetPosition(hWaveOut, &mmTime, sizeof(MMTIME)); dwOffset = mmTime.u.cb; iTimeCursor = (double)dwOffset/whdr.dwBufferLength*600; //change Cursor coordinate for(i = -612 ; i <= 612 ; i++) //-310 310 { //left s = 0; dw = dwOffset + i*wfe.nBlockAlign; if(0 <= dw && dw < whdr.dwBufferLength) { CopyMemory(&s, whdr.lpData+dw, wfe.wBitsPerSample/8); if(wfe.wBitsPerSample == 8) s-= 128; // shift no volume(128) to 0 } ptWaveL[i+612].y = 185*(-s)/wHalfMaxAmp + 250; //ptWaveL[i+310].y + 195; } if(wfe.nChannels == 2) { //stereo for(i = -612 ; i <= 612 ; i++)//-310 310 { //right s = 0; dw = dwOffset + i*wfe.nBlockAlign + wfe.wBitsPerSample/8; if(0 <= dw && dw < whdr.dwBufferLength) { CopyMemory(&s, whdr.lpData + dw, wfe.wBitsPerSample/8); if(wfe.wBitsPerSample == 8) s-=128; //shift no volume(128) to 0 } ptWaveR[i+612].y = 185*(-s)/wHalfMaxAmp + 250; //ptWaveR[i+310].y +195 } } dw = (double)dwOffset/wfe.nAvgBytesPerSec*100; wsprintf(strTime, "%02d:%02d:%02d/%02d:%02d:%02d", (dw/100)/60,(dw/100)%60,dw%100, //current time (maxTime/100)/60,(maxTime/100)%60,maxTime%100); //total time InvalidateRect(hwnd, &rcWave, FALSE); InvalidateRect(hwnd, &rcInfo[0], FALSE); InvalidateRect(hwnd, &rcInfo[1], FALSE); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); StretchDIBits(hdc_mem, 0, 0, iWidth, iHeight, 0, 0, iWidth, iHeight, lpPixel, &bmpInfo, DIB_RGB_COLORS, SRCCOPY); ///////////////////////////////////////// SelectObject(hdc_mem, hFont[2]); SetTextColor(hdc_mem, RGB(255, 255, 0)); DrawText(hdc_mem, strFile, (int)strlen(strFile), &rcMove, DT_SINGLELINE | DT_VCENTER); DrawText(hdc_mem,strTime, (int)strlen(strTime), &rcInfo[1], DT_SINGLELINE | DT_CENTER | DT_VCENTER); DrawText(hdc_mem, strVol, (int)strlen(strVol), &rcInfo[2], DT_SINGLELINE | DT_CENTER | DT_VCENTER); DrawText(hdc_mem, strState, (int)strlen(strState), &rcInfo[3], DT_SINGLELINE | DT_CENTER | DT_VCENTER); SelectObject(hdc_mem, hPenR); Polyline(hdc_mem, ptWaveR, sizeof(ptWaveR)/sizeof(ptWaveR[0])); SelectObject(hdc_mem, hPenL); Polyline(hdc_mem, ptWaveL, sizeof(ptWaveL)/sizeof(ptWaveL[0])); // measure when strFile is over limitation StretchDIBits(hdc_mem, 0, 450, 20, 20, 0, 10, 20, 20, lpPixel, &bmpInfo, DIB_RGB_COLORS, SRCCOPY); ////////////////////////////////////////////////////// BitBlt(hdc, 0, 0, iWidth, iHeight, hdc_mem, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: SetWindowLong(hTrack, GWL_WNDPROC, (LONG)TrackProc); DestroyWindow(hTrack); PostQuitMessage(0); return 0; default: return DefWindowProc(hwnd, msg, wp, lp); } return 0; }
VOID Dx11Overlay::DrawText( WCHAR* Text ) { DrawText(Text, 0xFFFFFF00); }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; int wmId, wmEvent; PAINTSTRUCT ps; TCHAR szHello[MAX_LOADSTRING]; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_SAVE: { TCHAR szPathName[_MAX_PATH]; OPENFILENAME ofn; int cbSize = sizeof(OPENFILENAME); szPathName[0] = 0; memset(&ofn, 0, cbSize); ofn.lStructSize = cbSize; ofn.hwndOwner = hWnd; ofn.lpstrFilter = TEXT("Text files\0*.txt\0All files\0*.*\0"); ofn.lpstrCustomFilter = NULL; ofn.nFilterIndex = 1; ofn.lpstrFile = szPathName; ofn.nMaxFile = sizeof(szPathName) / sizeof(TCHAR); ofn.Flags = OFN_OVERWRITEPROMPT | OFN_SHOWHELP; ofn.lpstrDefExt = TEXT("txt"); GetSaveFileName(&ofn); MessageBox(hWnd, szPathName, _T("File Name Selected"), MB_OK); } break; case IDM_HELP_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDOK: SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd); SendMessage (hWnd, WM_CLOSE, 0, 0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: s_sai.cbSize = sizeof(SHACTIVATEINFO); hwndCB = CreateRpCommandBar(hWnd); break; case WM_PAINT: RECT rt; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rt); LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: CommandBar_Destroy(hwndCB); PostQuitMessage(0); break; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
int Render3DEnvironment() { int ret; ret = E3DGetKeyboardCnt( keybuf ); _ASSERT( !ret ); ret = ChangeMiddleGray(); _ASSERT( !ret ); //テクスチャにシーンをレンダリング ret = E3DBeginScene( scid_org, 0 ); if( ret ){ _ASSERT( 0 ); return 1; } int status; ret = E3DChkInView( scid_org, hsid0, &status ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRender( scid_org, hsid0, 0, 1, 0, 0 );//不透明 if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DRender( scid_org, hsid0, 1, 1, 0, 0 );//半透明 if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DEndScene(); if( ret ){ _ASSERT( 0 ); return 1; } //ダウンスケール ret = E3DDownScaleRTTexture4x4( scid_small, texid_org ); if( ret ){ _ASSERT( 0 ); return 1; } //トーンマップでシーンの明るさを計測 ret = E3DRenderToneMap( tonemapid, texid_small ); if( ret ){ _ASSERT( 0 ); return 1; } //HDRの明るい部分を抜き出してLDRに変換 ret = E3DBrightPassRTTextureHDR( scid_bright, texid_small, middlegray, threshold, offset, tonemapid ); if( ret ){ _ASSERT( 0 ); return 1; } //ダウンスケール ret = E3DDownScaleRTTexture2x2( scid_bloom0, texid_bright ); if( ret ){ _ASSERT( 0 ); return 1; } //ガウスぼかしその1 ret = E3DBlurTextureGauss5x5( scid_bloom1, texid_bloom0, 10.0f ); if( ret ){ _ASSERT( 0 ); return 1; } //ガウスぼかしその2 ret = E3DBlurTextureGauss( scid_bloom2, scid_work, texid_work, texid_bloom1, 1.0f ); if( ret ){ _ASSERT( 0 ); return 1; } //元画像と明るい部分のぼかし画像とシーンの明るさ情報から最終イメージをレンダー ret = E3DRenderHDRFinal( scid_final, texid_org, texid_bloom2, tonemapid, middlegray ); if( ret ){ _ASSERT( 0 ); return 1; } //メイン画面に表示 ret = E3DBeginScene( scid, 0 ); _ASSERT( !ret ); ret = E3DBeginSprite(); _ASSERT( !ret ); //元画像を表示 float scalex = 1.0f; float scaley = 1.0f; D3DXVECTOR3 tra = D3DXVECTOR3( 0.0f, 0.0f, 0.1f ); ret = E3DRenderSprite( spid1, scalex, scaley, tra ); _ASSERT( !ret ); //ブルーム処理後の最終イメージを表示 tra.x = (float)spw1; tra.y = 0.0f; ret = E3DRenderSprite( spid2, scalex, scaley, tra ); _ASSERT( !ret ); ret = E3DEndSprite(); _ASSERT( !ret ); ret = DrawText(); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DEndScene(); _ASSERT( !ret ); ret = E3DPresent( scid ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DWaitbyFPS( 60, &retfps ); if( ret ){ _ASSERT( 0 ); return 1; } return 0; }
/** * Responsible for drawing each list item. */ void ToggleListView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CListCtrl& ListCtrl=GetListCtrl(); int nItem = lpDrawItemStruct->itemID; // get item data LV_ITEM lvi; _TCHAR szBuff[MAX_PATH]; memset(&lvi, 0, sizeof(LV_ITEM)); lvi.mask = LVIF_TEXT; lvi.iItem = nItem; lvi.pszText = szBuff; lvi.cchTextMax = sizeof(szBuff); ListCtrl.GetItem(&lvi); RECT rDraw; CopyRect ( &rDraw, &lpDrawItemStruct->rcItem ); rDraw.right = rDraw.left + TOGGLELIST_ITEMHEIGHT; rDraw.top ++; rDraw.right ++; FrameRect ( lpDrawItemStruct->hDC, &rDraw, (HBRUSH)GetStockObject ( BLACK_BRUSH ) ); rDraw.right --; FillRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_3DFACE ) ); Draw3dRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_3DHILIGHT ), GetSysColorBrush ( COLOR_3DSHADOW ) ); InflateRect ( &rDraw, -3, -3 ); Draw3dRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_3DSHADOW ), GetSysColorBrush ( COLOR_3DHILIGHT ) ); switch(GetToggleState(lvi.iItem)) { case TOGGLE_STATE_DISABLED: if(disabledIcon) { DrawIconEx ( lpDrawItemStruct->hDC, rDraw.left, rDraw.top, disabledIcon, 16, 16,0, NULL, DI_NORMAL ); } break; case TOGGLE_STATE_ON: if(onIcon) { DrawIconEx ( lpDrawItemStruct->hDC, rDraw.left, rDraw.top, onIcon, 16, 16,0, NULL, DI_NORMAL ); } break; case TOGGLE_STATE_OFF: if(offIcon) { DrawIconEx ( lpDrawItemStruct->hDC, rDraw.left, rDraw.top, offIcon, 16, 16,0, NULL, DI_NORMAL ); } break; }; CopyRect ( &rDraw, &lpDrawItemStruct->rcItem ); rDraw.left += TOGGLELIST_ITEMHEIGHT; rDraw.left += 1; if ( lpDrawItemStruct->itemState & ODS_SELECTED ) { FillRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_HIGHLIGHT ) ); } else { FillRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_WINDOW ) ); } rDraw.left += TEXT_OFFSET; int colorIndex = ( (lpDrawItemStruct->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT ); SetTextColor ( lpDrawItemStruct->hDC, GetSysColor ( colorIndex ) ); DrawText ( lpDrawItemStruct->hDC, szBuff, strlen(szBuff), &rDraw, DT_LEFT|DT_VCENTER|DT_SINGLELINE ); }
void CTetrisDlg::UpdateWindow() { CDC wndMemDC; wndMemDC.CreateCompatibleDC(&m_memDC); wndMemDC.SelectObject(m_window); BLENDFUNCTION bf; bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = 255; bf.AlphaFormat = AC_SRC_ALPHA; ::AlphaBlend(m_memDC, 328, 10, 308, 629, wndMemDC, 0, 0, 308, 629, bf); wndMemDC.DeleteDC(); SetFontSize(30); CString str; DrawText(360, 32, 600, 64, str = "NEXT TETROMINO:", DT_LEFT); CDC blockMemDC; blockMemDC.CreateCompatibleDC(&m_memDC); blockMemDC.SelectObject(m_block); BYTE x = (m_nextColor - 1) << 5; switch((m_gameParam & 0xE0) >> 5) { case 1: m_memDC.StretchBlt(414, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(446, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(478, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(510, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); break; case 2: m_memDC.StretchBlt(430, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(494, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(494, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); break; case 3: m_memDC.StretchBlt(430, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(494, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(430, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); break; case 4: m_memDC.StretchBlt(446, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(478, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(446, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(478, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); break; case 5: m_memDC.StretchBlt(462, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(494, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(430, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); break; case 6: m_memDC.StretchBlt(430, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(494, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); break; case 7: m_memDC.StretchBlt(430, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 96, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(462, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); m_memDC.StretchBlt(494, 128, 32, 32, &blockMemDC, x, 0, 32, 32, SRCCOPY); } blockMemDC.DeleteDC(); DrawText(360, 192, 600, 224, str = "LEVEL:", DT_LEFT); str.Format(_T("%d"), m_level + 1); DrawText(360, 192, 600, 224, str, DT_RIGHT); DrawText(360, 256, 600, 288, str = "SCORE:", DT_LEFT); str.Format(_T("%d"), m_score); DrawText(360, 256, 600, 288, str, DT_RIGHT); DrawText(360, 320, 600, 352, str = "LINES:", DT_LEFT); str.Format(_T("%d"), m_lines); DrawText(360, 320, 600, 352, str, DT_RIGHT); SetFontSize(m_mouseOver == 0x01 ? 36 : 30); DrawText(360, 384, 600, 416, str = "NEW", DT_CENTER); if(!(m_gameParam & 0x01) || (m_gameParam & 0x04)) { SetFontSize(30); DrawText(400, 448, 560, 480, str = "PAUSE", DT_LEFT, 0xA0A0A0); DrawText(400, 448, 560, 480, str = "STOP", DT_RIGHT, 0xA0A0A0); } else { SetFontSize(m_mouseOver == 0x02 ? 36 : 30); DrawText(400, 448, 560, 480, str = "PAUSE", DT_LEFT, m_gameParam & 0x02 ? 0x0000FF : 0xFFFFFF); SetFontSize(m_mouseOver == 0x04 ? 36 : 30); DrawText(400, 448, 560, 480, str = "STOP", DT_RIGHT, 0xFFFFFF); } SetFontSize(m_mouseOver == 0x08 ? 36 : 30); SetTextColor(m_memDC, 0xFFFFFF); DrawText(360, 512, 600, 544, str = "SOUND", DT_CENTER, m_gameParam & 0x08 ? 0x0000FF : 0xFFFFFF); SetFontSize(m_mouseOver == 0x10 ? 36 : 30); DrawText(360, 576, 600, 608, str = "EXIT", DT_CENTER); }
/* helper functions */ DWORD notification_daemon_main(LPVOID lpdwThreadParam) { HINSTANCE hDLLInstance = (HINSTANCE) GetModuleHandle(NULL); WNDCLASSEX wcex = {sizeof(WNDCLASSEX)}; TCHAR szTitle[] = TEXT("libnotify_notification"); TCHAR szWindowClass[] = TEXT("libnotify"); HDC hdc = NULL; HFONT hOldFont = NULL; RECT rc = {0}; MSG msg = {0}; /* register window class */ wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW; wcex.lpfnWndProc = thread_proc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hDLLInstance; wcex.hIcon = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = NULL; if(0 == RegisterClassEx(&wcex)) goto cleanup_and_exit; /* create the notification window */ notification_window = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED | WS_EX_TRANSPARENT, szWindowClass, szTitle, WS_OVERLAPPED | WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hDLLInstance, NULL); if(!notification_window) goto cleanup_and_exit; /* screen width / 3.5 is the maximum allowed notification width */ notification_window_width_max = (GetSystemMetrics(SM_CXSCREEN) * 2) / 7; icon_size = (uint16_t) GetSystemMetrics(SM_CXICON); icon_padding = icon_size / 3; /* icon spacing is a third of the icon width */ /* height and width set here are dummy, they will later be reset based on DrawText */ notification_window_width = notification_window_width_max; notification_window_height = notification_window_width / 4; SetWindowPos(notification_window, HWND_TOPMOST, 0, 0, notification_window_width, notification_window_height, SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOREPOSITION); SetLayeredWindowAttributes(notification_window, 0, notification_window_alpha, LWA_ALPHA); font_summary = CreateFont(0, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_ROMAN, NULL); if(!font_summary) goto cleanup_and_exit; font_body = CreateFont(0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_ROMAN, NULL); if(!font_body) goto cleanup_and_exit; hdc = GetDC(notification_window); if(hdc) { hOldFont = (HFONT) SelectObject(hdc, (HFONT) font_summary); if(hOldFont) { /* set the width and get the height for a single line (summary) from DrawText; for rational on width calc., see the above geometry */ rc.right = notification_window_width - (icon_size + (icon_padding * 3)); DrawText(hdc, TEXT("placeholder"), -1, &rc, DT_CALCRECT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); summary_body_divider = (uint16_t) rc.bottom; SelectObject(hdc, (HFONT) hOldFont); } ReleaseDC(notification_window, hdc); if(!hOldFont) goto cleanup_and_exit; } else goto cleanup_and_exit; SetEvent((HANDLE) lpdwThreadParam); while(GetMessage(&msg, NULL, 0, 0)) { if((msg.message == WM_LIBNOTIFYEXIT) || (msg.message == WM_QUIT)) { if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } KillTimer(notification_window, TIMER_ANIMATION); KillTimer(notification_window, TIMER_NOTIFICATION); if(font_summary) DeleteObject(font_summary); if(font_body) DeleteObject(font_body); break; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; /* cleanup and return */ cleanup_and_exit: if(font_summary) DeleteObject(font_summary); if(font_body) DeleteObject(font_body); return ((DWORD) -1); }
void DrawMenu() { ClearScreen(); switch(mode) { case 1: { //Step Programming menu //Status SetTextColor(green); DrawText(6, 5, "BigTrakr! Steps: %d", steps); //Menu options SetTextColor(white); DrawText(15, 22, "Forward"); DrawText(15, 37, "Back"); DrawText(15, 52, "Right"); DrawText(15, 67, "Left"); DrawText(15, 82, "Fire"); //Menu pointer DrawImage(markerImage,5,10+15*menuItem,white); //Number (lengths, degrees, lasers) SetTextColor(white); if(menuItem<3 || menuItem==5) { DrawText(90, 7 + 15*menuItem,"%d",menuNum); } else if (menuItem < 5) { DrawText(90, 7 + 15*menuItem,"%d",menuNum * 15); } //Number arrows prompting right stick adjustments SetTextColor(red); //DrawText(90, 13 + 15*(menuItem-1),"^"); //DrawText(90, 2 + 15*(menuItem+1),"v"); DrawImage(upImage, 92, 17+15*(menuItem-1), white); DrawImage(downImage, 92, 8 + 15*(menuItem+1), white); //Button identifiers SetTextColor(blue); DrawText(6, 100, "Clear"); DrawText(100,100, "Select"); } break; case 2: { //Additional menu //Status SetTextColor(green); DrawText(5, 5, "BigTrakr! Steps: %d", steps); //Menu options SetTextColor(white); DrawText(15, 22, "Free Roam"); DrawText(15, 37, "Load Route"); DrawText(15, 52, "Save Route"); DrawText(15, 67, "Recalibrate"); DrawText(15, 82, "About"); //Menu pointer DrawImage(markerImage,5,10+15*menuItem,white); //Button identifiers SetTextColor(blue); DrawText(6, 100, "Back"); DrawText(100,100, "Select"); } break; case 3: { //Recalibration mode switch(menuNum) { case 1: { //Ready SetTextColor(white); DrawText(6, 7, "To recalibrate"); DrawText(6, 22, "rotation, press"); DrawText(6, 37, "Button B to start"); DrawText(6, 52, "then press again"); DrawText(6, 67, "to stop when the"); DrawText(6, 82, "Trakr spins fully"); SetTextColor(blue); DrawText(6, 100, "Cancel"); DrawText(100,100, "Start"); } break; case 2: { SetTextColor(white); DrawText(6, 22, "Started..."); DrawText(6, 37, "Let the Trakr"); DrawText(6, 52, "spin 360 degrees"); DrawText(6, 67, "then press again"); SetTextColor(blue); DrawText(6, 100, "Cancel"); DrawText(100,100, "Stop"); } break; } } break; case 4: { //Free roam SetTextColor(white); DrawText(5, 5, "Free Roam"); SetTextColor(blue); if (IRState) DrawText(6, 100, "Light off"); else DrawText(6, 100, "Light on"); DrawText(100,100, "Close"); } break; case 5: { //About Splash(); SetTextColor(blue); if (IRState) DrawText(6, 100, "Light off"); else DrawText(6, 100, "Light on"); DrawText(100,100, "Close"); } } Show(); }
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { PNHMenuWindow data; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); switch( wParam ) { case MSNH_MSG_PUTSTR: { PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; HWND text_view; if( data->type!=MENU_TYPE_TEXT ) SetMenuType(hWnd, MENU_TYPE_TEXT); if( !data->text.text ) { data->text.text = mswin_init_text_buffer( program_state.gameover? FALSE : GetNHApp()->bWrapText ); if( !data->text.text ) break; } mswin_add_text(data->text.text, msg_data->attr, msg_data->text); text_view = GetDlgItem(hWnd, IDC_MENU_TEXT); if( !text_view ) panic("cannot get text view window"); mswin_render_text(data->text.text, text_view); } break; case MSNH_MSG_STARTMENU: { int i; if( data->type!=MENU_TYPE_MENU ) SetMenuType(hWnd, MENU_TYPE_MENU); if( data->menu.items ) free(data->menu.items); data->how = PICK_NONE; data->menu.items = NULL; data->menu.size = 0; data->menu.allocated = 0; data->done = 0; data->result = 0; for (i = 0; i < NUMTABS; ++i) data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE; } break; case MSNH_MSG_ADDMENU: { PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu)lParam; char *p, *p1; int new_item; HDC hDC; int column; HFONT saveFont; if( data->type!=MENU_TYPE_MENU ) break; if( strlen(msg_data->str)==0 ) break; if( data->menu.size==data->menu.allocated ) { data->menu.allocated += 10; data->menu.items = (PNHMenuItem)realloc(data->menu.items, data->menu.allocated*sizeof(NHMenuItem)); } new_item = data->menu.size; ZeroMemory( &data->menu.items[new_item], sizeof(data->menu.items[new_item])); data->menu.items[new_item].glyph = msg_data->glyph; data->menu.items[new_item].identifier = *msg_data->identifier; data->menu.items[new_item].accelerator = msg_data->accelerator; data->menu.items[new_item].group_accel = msg_data->group_accel; data->menu.items[new_item].attr = msg_data->attr; parse_menu_str(data->menu.items[new_item].str, msg_data->str, NHMENU_STR_SIZE); data->menu.items[new_item].presel = msg_data->presel; /* calculate tabstop size */ p = strchr(data->menu.items[new_item].str, '\t'); if( p ) { data->menu.items[new_item].has_tab = TRUE; hDC = GetDC(hWnd); saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE)); p1 = data->menu.items[new_item].str; column = 0; for (;;) { TCHAR wbuf[BUFSZ]; RECT drawRect; SetRect ( &drawRect, 0, 0, 1, 1 ); if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ DrawText(hDC, NH_A2W(p1, wbuf, BUFSZ), /*JP strlen(p1), */ -1, &drawRect, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS | DT_SINGLELINE ); data->menu.tab_stop_size[column] = max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left ); if (p != NULL) *p = '\t'; else /* last string so, */ break; ++column; p1 = p + 1; p = strchr(p1, '\t'); } SelectObject(hDC, saveFont); ReleaseDC(hWnd, hDC); } else { data->menu.items[new_item].has_tab = FALSE; } /* increment size */ data->menu.size++; } break; case MSNH_MSG_ENDMENU: { PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu)lParam; if( msg_data->text ) { strncpy( data->menu.prompt, msg_data->text, sizeof(data->menu.prompt)-1 ); } else { ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); } } break; } /* end switch */ }
void mswin_menu_window_size (HWND hWnd, LPSIZE sz) { TEXTMETRIC tm; HWND control; HGDIOBJ saveFont; HDC hdc; PNHMenuWindow data; int i; RECT rt, wrt; int extra_cx; GetClientRect(hWnd, &rt); sz->cx = rt.right - rt.left; sz->cy = rt.bottom - rt.top; GetWindowRect(hWnd, &wrt); extra_cx = (wrt.right-wrt.left) - sz->cx; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); if(data) { control = GetMenuControl(hWnd); hdc = GetDC(control); if( data->type==MENU_TYPE_MENU ) { /* Calculate the width of the list box. */ saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); GetTextMetrics(hdc, &tm); for(i=0; i<data->menu.size; i++ ) { LONG menuitemwidth = 0; int column; char *p, *p1; p1 = data->menu.items[i].str; p = strchr(data->menu.items[i].str, '\t'); column = 0; for (;;) { TCHAR wbuf[BUFSZ]; RECT tabRect; SetRect ( &tabRect, 0, 0, 1, 1 ); if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ DrawText(hdc, NH_A2W(p1, wbuf, BUFSZ), /*JP strlen(p1), */ -1, &tabRect, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE ); /* it probably isn't necessary to recompute the tab width now, but do so * just in case, honoring the previously computed value */ menuitemwidth += max(data->menu.tab_stop_size[column], tabRect.right - tabRect.left); if (p != NULL) *p = '\t'; else /* last string so, */ break; /* add the separation only when not the last item */ /* in the last item, we break out of the loop, in the statement just above */ menuitemwidth += TAB_SEPARATION; ++column; p1 = p + 1; p = strchr(p1, '\t'); } sz->cx = max(sz->cx, (LONG)(2*TILE_X + menuitemwidth + tm.tmAveCharWidth*12 + tm.tmOverhang)); } SelectObject(hdc, saveFont); } else { /* do not change size for text output - the text will be formatted to fit any window */ } sz->cx += extra_cx; ReleaseDC(control, hdc); } }
void CNSDateEdit::LayoutSubWindows( RECT *pRect ) { HDC hDC = ::GetDC( m_hWnd ); ASSERT( hDC ); int w = pRect->right - pRect->left; RECT r, rcSep, rcNum; TCHAR szSeparator[2], szFormat[30], *s; HFONT hFont = (HFONT)::GetStockObject( ANSI_VAR_FONT ); CFont *fontCur = CFont::FromHandle( hFont ); LOGFONT lf; GetObject( hFont, sizeof(lf), &lf); // Get locale info #ifdef WIN32 VERIFY( GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, szFormat, 30 ) > 0 ); VERIFY( GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SDATE, szSeparator, 2 ) > 0 ); #else static char cName [] = "intl" ; GetProfileString (cName, "sDate", "/", szSeparator, 2) ; int iDate = GetProfileInt (cName, "iDate", 0) ; sprintf( szFormat, "%c%s%c%s%c", iDate == 1 ? 'd' : iDate == 2 ? 'y' : 'M', szSeparator, iDate == 1 ? 'M' : iDate == 2 ? 'M' : 'd', szSeparator, iDate == 1 ? 'y' : iDate == 2 ? 'd' : 'y' ); #endif // Get font info ::SetRectEmpty(&rcSep); ::SetRectEmpty(&rcNum); DrawText( hDC, szSeparator, -1, &rcSep, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_CALCRECT ); DrawText( hDC, _T("0"), -1, &rcNum, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_CALCRECT ); ASSERT( w >= ( rcSep.right * 2 + rcNum.right * 8 ) ); // Start on the left int iHeight = lf.lfHeight; int iWidth = 0; r.top = pRect->top - ((pRect->top-pRect->bottom)+iHeight)/2 - 1; r.bottom = r.top + iHeight + 2; r.right = pRect->left + 1; // this loop parses the short date format, creating the fields as it goes s = strtok( szFormat, szSeparator ); for( int i = 0; (i < 3) && (s != NULL); i++ ) { switch ( s[0] ) { case 'M': case 'm': r.left = r.right + 1; r.right = r.left + rcNum.right * 2 + iWidth; // room for two characters m_MonthField.MoveWindow( &r ); m_MonthField.SetFont( fontCur ); m_pFields[i] = &m_MonthField; break; case 'Y': case 'y': r.left = r.right + 1; r.right = r.left + rcNum.right * 4 + iWidth; // room for four characters m_YearField.MoveWindow( &r ); m_YearField.SetFont( fontCur ); m_pFields[i] = &m_YearField; break; case 'D': case 'd': r.left = r.right + 1; r.right = r.left + rcNum.right * 2 + iWidth; // room for two characters m_DayField.MoveWindow( &r ); m_DayField.SetFont( fontCur ); m_pFields[i] = &m_DayField; break; default: DebugBreak(); } if ( i == 0 ) { r.left = r.right + 1; r.right = r.left + rcSep.right; m_Sep1 = r; } else if ( i == 1 ) { r.left = r.right + 1; r.right = r.left + rcSep.right; m_Sep2 = r; } s = strtok( NULL, szSeparator ); } r = *pRect; r.left = r.right - GetSystemMetrics(SM_CXVSCROLL); m_wndSpin.MoveWindow(&r); ::ReleaseDC( m_hWnd, hDC ); }
static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out, subpicture_region_t *p_region_in ) { filter_sys_t *p_sys = p_filter->p_sys; int i_font_color, i_font_alpha, i_font_size; uint8_t *p_bitmap; TCHAR *psz_string; int i, i_width, i_height; HBITMAP bitmap, bitmap_bak; BITMAPINFO *p_bmi; RECT rect = { 0, 0, 0, 0 }; /* Sanity check */ if( !p_region_in || !p_region_out ) return VLC_EGENERIC; if( !p_region_in->psz_text || !*p_region_in->psz_text ) return VLC_EGENERIC; psz_string = malloc( (strlen( p_region_in->psz_text )+1) * sizeof(TCHAR) ); if( !psz_string ) return VLC_ENOMEM; #ifdef UNICODE if( mbstowcs( psz_string, p_region_in->psz_text, strlen( p_region_in->psz_text ) * sizeof(TCHAR) ) < 0 ) { free( psz_string ); return VLC_EGENERIC; } #else strcpy( psz_string, p_region_in->psz_text ); #endif if( !*psz_string ) { free( psz_string ); return VLC_EGENERIC; } if( p_region_in->p_style ) { i_font_color = __MAX( __MIN( p_region_in->p_style->i_font_color, 0xFFFFFF ), 0 ); i_font_alpha = __MAX( __MIN( p_region_in->p_style->i_font_alpha, 255 ), 0 ); i_font_size = __MAX( __MIN( p_region_in->p_style->i_font_size, 255 ), 0 ); } else { i_font_color = p_sys->i_font_color; i_font_alpha = 255 - p_sys->i_font_opacity; i_font_size = p_sys->i_default_font_size; } SetFont( p_filter, i_font_size ); SetTextColor( p_sys->hcdc, RGB( (i_font_color >> 16) & 0xff, (i_font_color >> 8) & 0xff, i_font_color & 0xff) ); DrawText( p_sys->hcdc, psz_string, -1, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX ); i_width = rect.right; i_height = rect.bottom; p_bmi = malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*16); memset( p_bmi, 0, sizeof(BITMAPINFOHEADER) ); p_bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); p_bmi->bmiHeader.biWidth = (i_width+3) & ~3; p_bmi->bmiHeader.biHeight = - i_height; p_bmi->bmiHeader.biPlanes = 1; p_bmi->bmiHeader.biBitCount = 8; p_bmi->bmiHeader.biCompression = BI_RGB; p_bmi->bmiHeader.biClrUsed = 16; for( i = 0; i < 16; i++ ) { p_bmi->bmiColors[i].rgbBlue = p_bmi->bmiColors[i].rgbGreen = p_bmi->bmiColors[i].rgbRed = pi_gamma[i]; } bitmap = CreateDIBSection( p_sys->hcdc, p_bmi, DIB_RGB_COLORS, (void **)&p_bitmap, NULL, 0 ); if( !bitmap ) { msg_Err( p_filter, "could not create bitmap" ); free( psz_string ); return VLC_EGENERIC; } bitmap_bak = SelectObject( p_sys->hcdc, bitmap ); FillRect( p_sys->hcdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); if( !DrawText( p_sys->hcdc, psz_string, -1, &rect, DT_CENTER | DT_NOPREFIX ) ) { msg_Err( p_filter, "could not draw text" ); } p_region_out->i_x = p_region_in->i_x; p_region_out->i_y = p_region_in->i_y; Render( p_filter, p_region_out, p_bitmap, i_width, i_height ); SelectObject( p_sys->hcdc, bitmap_bak ); DeleteObject( bitmap ); free( psz_string ); return VLC_SUCCESS; }
LRESULT CALLBACK thread_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; RECT rc = {0}; UINT notify_duration = 0; HFONT hOldFont = NULL; switch (message) { case WM_LIBNOTIFYSHOW: if(notification_data) { /* deduce the allowed text width from the max width; see geometry for rationale */ rc.right = notification_window_width_max - (icon_size + (icon_padding * 3)); hdc = GetDC(hWnd); if(hdc) { HFONT hOldFont = NULL; HRGN hRgn = NULL; hOldFont = (HFONT) SelectObject(hdc, font_body); if(hOldFont) { DrawText(hdc, notification_data->body, -1, &rc, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING); SelectObject(hdc, hOldFont); } ReleaseDC(hWnd, hdc); if(!hOldFont) return 0; /* exit if font selection failed */ /* calculate the actual bounding rectangle from the DrawText output */ notification_window_height = summary_body_divider + rc.bottom + (icon_padding * 3); notification_window_width = rc.right + icon_size + (icon_padding * 3); /* word count * milliseconds per word */ notify_duration = word_count(notification_data->body) * milliseconds_per_word; /* in case the calculation renders too low a value, replace it with a de facto minimum */ notify_duration = MAX(notify_duration, min_notification_timeout); /* get the screen area uncluttered by the taskbar */ if(SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0)) { LONG window_x = 0, window_y = 0; /* system tray @ right bottom */ if((rc.bottom != GetSystemMetrics(SM_CYSCREEN)) || (rc.right != GetSystemMetrics(SM_CXSCREEN))) { window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notification_window_width; window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notification_window_height; } else if(rc.left != 0) /* left bottom */ { window_x = rc.left + (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor); window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notification_window_height; } else /* right top */ { window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notification_window_width; window_y = rc.top + (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor); } /* resize and reposition the window */ MoveWindow(hWnd, window_x, window_y, notification_window_width, notification_window_height, TRUE); /* set the new positions to be used by the mouse over hook */ notification_window_rect.left = window_x; notification_window_rect.top = window_y; notification_window_rect.right = window_x + notification_window_width; notification_window_rect.bottom = window_y + notification_window_height; /* make it as a rounded rect. */ hRgn = CreateRoundRectRgn(0, 0, notification_window_width, notification_window_height, rounded_rect_edge, rounded_rect_edge); SetWindowRgn(notification_window, hRgn, TRUE); /* since bRedraw is set to TRUE in SetWindowRgn invalidation isn't required */ /*InvalidateRect(hWnd, NULL, TRUE);*/ /* show the window and set the timers for animation and overall visibility */ ShowWindow(hWnd, SW_SHOWNOACTIVATE); SetTimer(notification_window, TIMER_ANIMATION, fade_duration, NULL); SetTimer(notification_window, TIMER_NOTIFICATION, notify_duration, NULL); } } } break; case WM_LIBNOTIFYCLOSE: /* clean up and reset flags */ { if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } KillTimer(hWnd, TIMER_ANIMATION); KillTimer(hWnd, TIMER_NOTIFICATION); is_fading_out = FALSE; ShowWindow(hWnd, SW_HIDE); } break; case WM_PAINT: if(notification_data && notification_data->summary && notification_data->body && notification_data->icon) { hdc = BeginPaint(hWnd, &ps); SetTextColor(hdc, RGB(255, 255, 255)); SetBkMode(hdc, TRANSPARENT); hOldFont = (HFONT) SelectObject(hdc, font_summary); if(hOldFont) { /* set the padding as left offset and center the icon horizontally */ DrawIcon(hdc, icon_padding, (notification_window_height / 2) - (icon_size / 2), notification_data->icon); /* calculate and DrawText for both summary and body based on the geometry given above */ rc.left = icon_size + (icon_padding * 2); rc.right = notification_window_width - icon_padding; rc.top = icon_padding; rc.bottom = summary_body_divider + (icon_padding * 2); DrawText(hdc, notification_data->summary, -1, &rc, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); if(SelectObject(hdc, font_body)) { rc.top = rc.bottom; rc.bottom = notification_window_height - icon_padding; DrawText(hdc, notification_data->body, -1, &rc, DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING); } SelectObject(hdc, hOldFont); } EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; case WM_TIMER: if(IsWindowVisible(hWnd)) { if(wParam == TIMER_ANIMATION) /* notification animation timer */ { if(is_fading_out) { if(notification_window_alpha > 5) { notification_window_alpha -= 25; SetLayeredWindowAttributes(notification_window, 0, notification_window_alpha, LWA_ALPHA); } else { /* once fully faded out, self destroy and reset the flags */ KillTimer(hWnd, TIMER_ANIMATION); is_fading_out = FALSE; notification_window_alpha = 0; PostMessage(hWnd, WM_LIBNOTIFYCLOSE, 0, 0); } } else { if(notification_window_alpha < 250) { notification_window_alpha += 25; SetLayeredWindowAttributes(notification_window, 0, notification_window_alpha, LWA_ALPHA); } else { /* self destory as alpha reaches the maximum */ KillTimer(hWnd, TIMER_ANIMATION); notification_window_alpha = 255; /* set the mouse over hook once the window is fully visible */ hook_mouse_over = SetWindowsHookEx(WH_MOUSE_LL, mouse_over_hook_proc, (HINSTANCE) GetModuleHandle(NULL), 0); } } } else /* notification duration timer */ { /* self destruct once timed out */ KillTimer(hWnd, TIMER_NOTIFICATION); /* kill the hook set by animation timer */ if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } /* start fading out sequence */ is_fading_out = TRUE; SetTimer(hWnd, 1, fade_duration, NULL); } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
bool Run() { //Main loop - get keypresses and interpret them keystate=GetRemoteKeys(); if(keystate != oldKeystate) { oldKeystate = keystate; if(keystate & KEY_HOME) { return false; } if (mode == 1 || mode == 2) { //menu navigation is only relevant to menu modes if(keystate & KEY_LEFT_BACK) { //Menu down if (menuItem<MAXMENU) { menuItem++; if(menuItem==3 || menuItem==4) { menuNum=6; } else if (menuItem == 5) { menuNum=3; } else { menuNum=1; } } } if(keystate & KEY_LEFT_FORWARD) { //Menu up if (menuItem>1) { menuItem--; if(menuItem==3 || menuItem==4) { menuNum=6; } else if (menuItem == 5) { menuNum=3; } else { menuNum=1; } } } } if (mode == 1) { if(keystate & KEY_RIGHT_FORWARD) { //Menu down if (menuNum<24) { menuNum++; } } if(keystate & KEY_RIGHT_BACK) { //Menu up if (menuNum>1) { menuNum--; } } if(keystate & KEY_INPUT1) { //Clear PlaySound(SOUND_FIRE); steps=0; menuItem=1; menuNum=1; mode=1; OpenMotors(); } if(keystate & KEY_INPUT2) { //Menu select if(steps+1<MAXSTEPS) { steps++; moveList[steps].cmd=menuItem; moveList[steps].num=menuNum; PlaySound(SOUND_BEEP); } } if(keystate & KEY_MENU) { //Switch to second menu mode=2; menuItem=1; menuNum=1; PlaySound(SOUND_BEEP); } } else if (mode == 2) { if(keystate & KEY_INPUT1) { //Switch back to first menu mode=1; menuItem=1; menuNum=1; PlaySound(SOUND_BEEP); } if (keystate & KEY_INPUT2) { //Menu select switch(menuItem) { case 1: { //Free Roam mode=4; PlaySound(SOUND_BEEP); CloseMotors(); } break; case 2: { //Load route LoadRoute(); ClearScreen(); PlaySound(SOUND_BEEP); SetTextColor(white); DrawText(5, 65, "Loading..."); Show(); Sleep(500); //Just so they notice... mode=2; } break; case 3: { //Save route PlaySound(SOUND_BEEP); SaveRoute(); ClearScreen(); SetTextColor(white); DrawText(5, 65, "Saving..."); Show(); Sleep(500); //Just so they notice... mode=2; } break; case 4: { //Recalibrate PlaySound(SOUND_BEEP); mode=3; //Recalibration mode menuNum=1; //Use menuNum as steps throught the process - 1=ready, 2=working } break; case 5: { //About PlaySound(SOUND_GO); mode=5; CloseMotors(); } break; } } if(keystate & KEY_MENU) { //Switch back to first menu mode=1; menuItem=1; menuNum=1; PlaySound(SOUND_BEEP); } } else if (mode==3) { //Recalibrate. if(keystate & KEY_INPUT1) { //Cancel PlaySound(SOUND_BEEP); SetMotors(0,0); mode=2; menuItem=4; menuNum=1; } if (keystate & KEY_INPUT2) { //Start/Stop PlaySound(SOUND_BEEP); switch (menuNum) { case 1: { //Start menuNum=2; ResetTimer(); SetMotors(10000,-10000); } break; case 2: { //Stop rotateSleep = ReadTimer() / 24; SetMotors(0,0); mode=2; menuItem=4; menuNum=1; SaveCalibration(); } } } } else if (mode==4 || mode==5) { if(keystate & KEY_MENU) { //Switch back to first menu PlaySound(SOUND_BEEP); mode=2; menuItem=1; menuNum=1; OpenMotors(); } if (keystate & KEY_INPUT1) { IRState = !IRState; SetIR(IRState); } if (keystate & KEY_INPUT2) { PlaySound(SOUND_BEEP); mode=2; menuItem=1; menuNum=1; OpenMotors(); } } if(keystate & KEY_RUN) { //Go ClearScreen(); Show(); PlaySound(SOUND_GO); //Cycle through steps and execute int count; SetTextColor(green); for(count=1; count<=steps;count++) { switch(moveList[count].cmd) { case 1: { //Forward ClearScreen(); DrawText(5, 100, "%d: Forward %d",count, moveList[count].num); Show(); SetMotors(10000,10000); Sleep(FORWARDSLEEP * moveList[count].num); SetMotors(0,0); } break; case 2: { //Back ClearScreen(); DrawText(5, 100, "%d: Back %d",count, moveList[count].num); Show(); SetMotors(-10000,-10000); Sleep(FORWARDSLEEP * moveList[count].num); SetMotors(0,0); } break; case 3: { //Right ClearScreen(); DrawText(5, 100, "%d: Right %d",count, moveList[count].num * 15); Show(); SetMotors(10000,-10000); Sleep(rotateSleep * moveList[count].num); SetMotors(0,0); } break; case 4: { //Left ClearScreen(); DrawText(5, 100, "%d: Left %d",count, moveList[count].num * 15); Show(); SetMotors(-10000,10000); Sleep(rotateSleep * moveList[count].num); SetMotors(0,0); } break; case 5: { //Fire ClearScreen(); SetTextColor(red); DrawText(10, 45, "PEW! PEW! PEW!"); SetTextColor(green); DrawText(5, 100, "%d: Fire %d",count, moveList[count].num); Show(); int fireCount; for(fireCount=0; fireCount<moveList[count].num; fireCount++) { PlaySound(SOUND_FIRE); } } } } //reset menu pointer menuItem=1; menuNum=1; PlaySound(SOUND_GO); } DrawMenu(); } Sleep(50); //to stop the radio being on full time return true; }
static VOID MonSelPaintMonitor(IN OUT PMONITORSELWND infoPtr, IN HDC hDC, IN DWORD Index, IN OUT PRECT prc, IN COLORREF crDefFontColor, IN BOOL bHideNumber) { HFONT hFont, hPrevFont; COLORREF crPrevText; if ((INT)Index == infoPtr->SelectedMonitor) { FillRect(hDC, prc, (HBRUSH)(COLOR_HIGHLIGHT + 1)); if (infoPtr->HasFocus && !(infoPtr->UIState & UISF_HIDEFOCUS)) { /* NOTE: We need to switch the text color to the default, because DrawFocusRect draws a solid line if the text is white! */ crPrevText = SetTextColor(hDC, crDefFontColor); DrawFocusRect(hDC, prc); SetTextColor(hDC, crPrevText); } } InflateRect(prc, -infoPtr->SelectionFrame.cx, -infoPtr->SelectionFrame.cy); Rectangle(hDC, prc->left, prc->top, prc->right, prc->bottom); InflateRect(prc, -1, -1); if (!bHideNumber) { hFont = MonSelGetMonitorFont(infoPtr, hDC, Index); if (hFont != NULL) { hPrevFont = SelectObject(hDC, hFont); DrawText(hDC, infoPtr->Monitors[Index].szCaption, -1, prc, DT_VCENTER | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE); SelectObject(hDC, hPrevFont); } } if (infoPtr->MonitorInfo[Index].Flags & MSL_MIF_DISABLED) { InflateRect(prc, 1, 1); MonSelDrawDisabledRect(infoPtr, hDC, prc); } }
LRESULT onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { LPDRAWITEMSTRUCT lpdis; PNHMenuItem item; PNHMenuWindow data; TEXTMETRIC tm; HGDIOBJ saveFont; HDC tileDC; short ntile; int t_x, t_y; int x, y; TCHAR wbuf[BUFSZ]; RECT drawRect; COLORREF OldBg, OldFg, NewBg; char *p, *p1; int column; lpdis = (LPDRAWITEMSTRUCT) lParam; /* If there are no list box items, skip this message. */ if (lpdis->itemID == -1) return FALSE; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); item = &data->menu.items[lpdis->itemID]; tileDC = CreateCompatibleDC(lpdis->hDC); saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); NewBg = mswin_get_color(NHW_MENU, MSWIN_COLOR_BG); OldBg = SetBkColor(lpdis->hDC, NewBg); OldFg = SetTextColor(lpdis->hDC, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); GetTextMetrics(lpdis->hDC, &tm); x = lpdis->rcItem.left + 1; /* print check mark if it is a "selectable" menu */ if( data->how!=PICK_NONE ) { if( NHMENU_IS_SELECTABLE(*item) ) { HGDIOBJ saveBrush; HBRUSH hbrCheckMark; char buf[2]; switch(item->count) { case -1: hbrCheckMark = CreatePatternBrush(data->bmpChecked); break; case 0: hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); break; default: hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); break; } y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; SetBrushOrgEx(lpdis->hDC, x, y, NULL); saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); SelectObject(lpdis->hDC, saveBrush); DeleteObject(hbrCheckMark); x += TILE_X + 5; if(item->accelerator!=0) { buf[0] = item->accelerator; buf[1] = '\x0'; SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom ); /*JP DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); */ DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); } x += tm.tmAveCharWidth + tm.tmOverhang + 5; } else { x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 10; } } /* print glyph if present */ if( item->glyph != NO_GLYPH ) { HGDIOBJ saveBmp; saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles); ntile = glyph2tile[ item->glyph ]; t_x = (ntile % TILES_PER_LINE)*TILE_X; t_y = (ntile / TILES_PER_LINE)*TILE_Y; y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; nhapply_image_transparent( lpdis->hDC, x, y, TILE_X, TILE_Y, tileDC, t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR ); SelectObject(tileDC, saveBmp); } x += TILE_X + 5; /* draw item text */ if( item->has_tab ) { p1 = item->str; p = strchr(item->str, '\t'); column = 0; SetRect( &drawRect, x, lpdis->rcItem.top, min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), lpdis->rcItem.bottom ); for (;;) { TCHAR wbuf[BUFSZ]; if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ DrawText(lpdis->hDC, NH_A2W(p1, wbuf, BUFSZ), /*JP strlen(p1), */ -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); if (p != NULL) *p = '\t'; else /* last string so, */ break; p1 = p + 1; p = strchr(p1, '\t'); drawRect.left = drawRect.right + TAB_SEPARATION; ++column; drawRect.right = min (drawRect.left + data->menu.tab_stop_size[column], lpdis->rcItem.right); } } else { TCHAR wbuf[BUFSZ]; SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom); DrawText(lpdis->hDC, NH_A2W(item->str, wbuf, BUFSZ), /*JP strlen(item->str), */ -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); } /* draw focused item */ if( item->has_focus ) { RECT client_rt; HBRUSH bkBrush; GetClientRect(lpdis->hwndItem, &client_rt); if( NHMENU_IS_SELECTABLE(*item) && data->menu.items[lpdis->itemID].count>0 && item->glyph != NO_GLYPH ) { if( data->menu.items[lpdis->itemID].count==-1 ) { _stprintf(wbuf, TEXT("Count: All") ); } else { _stprintf(wbuf, TEXT("Count: %d"), data->menu.items[lpdis->itemID].count ); } SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, lpdis->hDC, FALSE)); /* calculate text rectangle */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); /*JP DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, */ DrawText(lpdis->hDC, wbuf, -1, &drawRect, DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); /* erase text rectangle */ drawRect.left = max(client_rt.left+1, client_rt.right - (drawRect.right - drawRect.left) - 10); drawRect.right = client_rt.right-1; drawRect.top = lpdis->rcItem.top; drawRect.bottom = lpdis->rcItem.bottom; bkBrush = CreateSolidBrush( GetBkColor(lpdis->hDC) ); FillRect(lpdis->hDC, &drawRect, bkBrush ); DeleteObject( bkBrush ); /* draw text */ /*JP DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, */ DrawText(lpdis->hDC, wbuf, -1, &drawRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); } /* draw focus rect */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); DrawFocusRect(lpdis->hDC, &drawRect); } SetTextColor (lpdis->hDC, OldFg); SetBkColor (lpdis->hDC, OldBg); SelectObject(lpdis->hDC, saveFont); DeleteDC(tileDC); return TRUE; }
LRESULT DisViewBox_OnPaint(HWND hwnd, disview_struct *win, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; SIZE fontsize; TCHAR text[100]; TCHAR txt[100]; RECT rect; int lg; int ht; HDC mem_dc; HBITMAP mem_bmp; u32 nbligne; GetClientRect(hwnd, &rect); lg = rect.right - rect.left; ht = rect.bottom - rect.top; hdc = BeginPaint(hwnd, &ps); mem_dc = CreateCompatibleDC(hdc); mem_bmp = CreateCompatibleBitmap(hdc, lg, ht); SelectObject(mem_dc, mem_bmp); FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH)); SelectObject(mem_dc, GetStockObject(SYSTEM_FIXED_FONT)); GetTextExtentPoint32(mem_dc, "0", 1, &fontsize); nbligne = ht/fontsize.cy; SetTextColor(mem_dc, RGB(0,0,0)); if((win->mode==1) || ((win->mode==0) && (win->cpu->CPSR.bits.T == 0))) { u32 i; u32 adr; if (win->autoup||win->autogo) win->curr_ligne = (win->cpu->instruct_adr >> 2); adr = win->curr_ligne*4; for(i = 0; i < nbligne; ++i) { u32 ins = _MMU_read32(win->cpu->proc_ID, MMU_AT_DEBUG, adr); des_arm_instructions_set[INDEX(ins)](adr, ins, txt); sprintf(text, "%04X:%04X %08X %s", (int)(adr>>16), (int)(adr&0xFFFF), (int)ins, txt); DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX); rect.top+=fontsize.cy; adr += 4; } if(((win->cpu->instruct_adr&0x0FFFFFFF) >= (win->curr_ligne<<2))&&((win->cpu->instruct_adr&0x0FFFFFFF) <= (win->curr_ligne+(nbligne<<2)))) { HBRUSH brjaune = CreateSolidBrush(RGB(255, 255, 0)); SetBkColor(mem_dc, RGB(255, 255, 0)); rect.top = (((win->cpu->instruct_adr&0x0FFFFFFF)>>2) - win->curr_ligne)*fontsize.cy; rect.bottom = rect.top + fontsize.cy; FillRect(mem_dc, &rect, brjaune); des_arm_instructions_set[INDEX(win->cpu->instruction)](win->cpu->instruct_adr, win->cpu->instruction, txt); sprintf(text, "%04X:%04X %08X %s", (int)((win->cpu->instruct_adr&0x0FFFFFFF)>>16), (int)(win->cpu->instruct_adr&0xFFFF), (int)win->cpu->instruction, txt); DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX); DeleteObject(brjaune); }