void TestWidget::HandleMouseDrag ( const JPoint& pt, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { const JBoolean scrolled = ScrollForDrag(pt); JPainter* p = NULL; if (buttonStates.left() && pt != itsPrevPt && GetDragPainter(&p)) // no painter for multiple click { if (!scrolled) { p->Rect(JRect(itsStartPt, itsPrevPt)); } p->Rect(JRect(itsStartPt, pt)); } if (buttonStates.middle() && pt != itsPrevPt) { itsAnimButton->Place(pt.x, pt.y); } else if (buttonStates.right() && pt != itsPrevPt) { JRect r = itsAnimButton->GetFrame(); if (pt.x > r.left && pt.y > r.top) { itsAnimButton->SetSize(pt.x-r.left, pt.y-r.top); } } itsPrevPt = pt; }
JXImage::JXImage ( JXDisplay* display, Drawable source ) : JImage(0,0, display->GetColormap()) { JXImageFromDrawable(display, source, JRect()); }
JXImage::JXImage ( JXDisplay* display, JXColormap* colormap, Drawable source ) : JImage(0,0, colormap) { JXImageFromDrawable(display, colormap, source, JRect()); }
JEPSPrinter::JEPSPrinter ( const JFontManager* fontManager, const JColormap* colormap ) : JPainter(fontManager, colormap, JRect(0,0,0,0)), JPrinter(), JPSPrinterBase(colormap), itsBounds(0,0,0,0) { itsIncludePreviewFlag = kJFalse; PSResetCoordinates(); }
//////////////////////////////////////////// /// JSprite //////////////////////////////////////////// JSprite::JSprite( const unsigned image ) { texture = image; position = Vec2(); center = Vec2(); scale = Vec2( 1.0f, 1.0f ); rotation = 0.0f; alpha = 1.0f; textureCoord = JRect( 1.0f, 0.0f, 0.0f, 1.0f ); useCamera = true; color = Vec3( 1.0f, 0.0f, 1.0f ); blendMode = JBlend::Mode::Alpha; buildTransformation = true; }
void J1DSliderObj::update(JGraphics g, double dx, double dy, JRegion& rgn, double scale) { int dt = depth2+2; JRect rect = getIExtent(dx, dy, scale); if ((rect.width > dt) && (rect.height > dt)) { int oldv = value; JRect clip = rect, thumb; JRegion frgn(clip.shrinkBy(depth+1, depth+1)); if (type == HORIZONTAL) { int len = rect.width-dt-dt; if (oldf != factor) { oldf = factor; fraction = (factor*rect.width-dt)/len; fraction = max(0.0, min(1.0, fraction)); } int pos = (int)JMath::round(fraction*len); thumb = JRect(clip.x+pos, clip.y, dt, clip.height); } else { int len = rect.height-dt-dt; if (oldf != factor) { oldf = factor; fraction = (factor*rect.height-dt)/len; fraction = max(0.0, min(1.0, fraction)); } int pos = (int)JMath::round((1.0-fraction)*len); thumb = JRect(clip.x, clip.y+pos, clip.width, dt); } int vmin = getMin(); value = (int)JMath::round(fraction*(getMax()-vmin)+vmin); if (value != oldv) broadcast(0); g.setJColor(color); g.fill3DJRect(thumb, depth); g.setJRegion((frgn & rgn)-JRegion(thumb)); g.setJColor(bkgnd); g.fillJRect(clip); g.setJRegion(rgn); } }
void TestWidget::HandleMouseUp ( const JPoint& pt, const JXMouseButton button, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { JPainter* p = NULL; if (button == kJXLeftButton && GetDragPainter(&p)) // no painter for multiple click { p->Rect(JRect(itsStartPt, itsPrevPt)); DeleteDragPainter(); } }
void GRaggedFloatTableData::SetRow ( const JIndex index, const JArray<JFloat>& rowData ) { const JSize colCount = GetDataColCount(); assert( rowData.GetElementCount() == colCount ); for (JIndex i=1; i<=colCount; i++) { JArray<JFloat>* dataCol = itsCols->NthElement(i); dataCol->SetElement(index, rowData.GetElement(i)); } Broadcast(JTableData::RectChanged(JRect(index, 1, index+1, colCount+1))); }
void JListBox::paint(JGraphics g) { int dx = d2+d2, dy; int th = getBaseH(); int ns = section; JString text; JFontMetrics fm(g); JRect clip = g.getClipJRect(); JRect frame = JRect(0, 0, width-scroller->width, height); JRegion rgn(clip &= frame); JColor color = getForeground(); JColor bkgnd = getBackground(); JColor light = bkgnd.brighter(); clip &= frame.shrink(d, d); if (base+ns > content.size()) ns = content.size()-base; for (int i=0; i<ns; i++) { dy = i*th+d2; JRect cell(d2, dy, width-scroller->width-d2*2, th-d); JRect area = cell & clip; JRect inner = cell.shrink(d, d) & clip; if (area.isEmpty()) continue; JAssociation &obj = *(JAssociation*)content[i+base]; text = *(JString*)obj.key(); g.setClipJRect(cell & clip); g.setJColor(bkgnd); if (!(int)*(JInteger*)obj.value()) { g.fill3DJRect(cell, d); g.setJColor(light); g.setClipJRect(inner); g.drawJString(text, dx+1, dy+1); } else { g.fill3DJRect(cell, -d); g.setJColor(light); g.setClipJRect(inner); g.drawJString(text, dx-1, dy-1); } g.setJColor(color); g.drawJString(text, dx, dy); rgn -= JRegion(area); } g.setJRegion(rgn); g.setJColor(bkgnd); g.fill3DJRect(frame, -d); }
void JXWidget::SetBounds ( const JCoordinate w, const JCoordinate h ) { assert( !itsApertureBoundedFlag ); assert( w >= 0 && h >= 0 ); const JCoordinate dw = w - itsBoundsG.width(); const JCoordinate dh = h - itsBoundsG.height(); if (dw != 0 || dh != 0) { itsBoundsG = JXContainer::LocalToGlobal(JRect(0,0,h,w)); NotifyBoundsResized(dw,dh); Refresh(); } }
JPSPrinter::JPSPrinter ( const JFontManager* fontManager, const JColormap* colormap ) : JPagePrinter(fontManager, colormap, JRect()), JPSPrinterBase(colormap) { itsPaperType = kUSLetter; itsCopyCount = 1; itsFirstPageIndex = 0; itsLastPageIndex = 0; itsPageCount = 0; itsPG = NULL; PSResetCoordinates(); }
JBoolean JIntersection ( const JRect& r1, const JRect& r2, JRect* result ) { result->top = JMax(r1.top, r2.top); result->left = JMax(r1.left, r2.left); result->bottom = JMin(r1.bottom, r2.bottom); result->right = JMin(r1.right, r2.right); if (result->top < result->bottom && result->left < result->right) { return kJTrue; } else { *result = JRect(0,0,0,0); return kJFalse; } }
JXWidget::JXWidget ( JXContainer* enclosure, const HSizingOption hSizing, const VSizingOption vSizing, const JCoordinate x, const JCoordinate y, const JCoordinate w, const JCoordinate h ) : JXContainer(enclosure->GetWindow(), enclosure) { assert( enclosure != NULL ); assert( w > 0 && h > 0 ); itsHSizing = hSizing; itsVSizing = vSizing; itsBorderWidth = 0; itsBackColor = (GetColormap())->GetDefaultBackColor(); itsFocusColor = (GetColormap())->GetDefaultFocusColor(); itsDragPainter = NULL; itsAllowUnboundedScrollingFlag = kJFalse; itsWantInputFlag = kJFalse; itsWantTabFlag = kJFalse; itsWantModTabFlag = kJFalse; const JPoint pt = enclosure->LocalToGlobal(x,y); itsFrameG = JRect(pt.y, pt.x, pt.y+h, pt.x+w); itsApertureBoundedFlag = kJTrue; itsBoundsG = GetApertureGlobal(); Refresh(); }
void JXTabGroup::DrawScrollButtons ( JXWindowPainter& p, const JCoordinate lineHeight ) { itsScrollUpRect = itsScrollDownRect = JRect(0,0,0,0); if (!itsCanScrollUpFlag && !itsCanScrollDownFlag) { return; } const JCoordinate w = 2*(kArrowWidth + kBorderWidth); const JCoordinate h = kSelMargin + kBorderWidth + 2*kTextMargin + lineHeight; const JRect ap = GetAperture(); const JColormap* cmap = p.GetColormap(); if (itsEdge == kTop) { JRect r(ap.top, ap.right - w, ap.top + h, ap.right); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(kBorderWidth, 0); r.top = r.bottom = r.ycenter(); r.top -= kArrowWidth/2; r.bottom += kArrowWidth/2 + kArrowWidth%2; r.right = r.left + kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowLeft(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowLeft(p, r, kBorderWidth); } else { JXFillArrowLeft(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; r.left += kArrowWidth; r.right += kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowRight(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowRight(p, r, kBorderWidth); } else { JXFillArrowRight(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; } else if (itsEdge == kLeft) { JRect r(ap.top, ap.left, ap.top + w, ap.left + h); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(0, kBorderWidth); r.left = r.right = r.xcenter(); r.left -= kArrowWidth/2; r.right += kArrowWidth/2 + kArrowWidth%2; r.bottom = r.top + kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowUp(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowUp(p, r, kBorderWidth); } else { JXFillArrowUp(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; r.top += kArrowWidth; r.bottom += kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowDown(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowDown(p, r, kBorderWidth); } else { JXFillArrowDown(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; } else if (itsEdge == kBottom) { JRect r(ap.bottom - h, ap.right - w, ap.bottom, ap.right); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(kBorderWidth, 0); r.top = r.bottom = r.ycenter(); r.top -= kArrowWidth/2; r.bottom += kArrowWidth/2 + kArrowWidth%2; r.right = r.left + kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowLeft(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowLeft(p, r, kBorderWidth); } else { JXFillArrowLeft(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; r.left += kArrowWidth; r.right += kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowRight(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowRight(p, r, kBorderWidth); } else { JXFillArrowRight(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; } else if (itsEdge == kRight) { JRect r(ap.bottom - w, ap.right - h, ap.bottom, ap.right); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(0, kBorderWidth); r.left = r.right = r.xcenter(); r.left -= kArrowWidth/2; r.right += kArrowWidth/2 + kArrowWidth%2; r.bottom = r.top + kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowUp(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowUp(p, r, kBorderWidth); } else { JXFillArrowUp(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; r.top += kArrowWidth; r.bottom += kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowDown(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowDown(p, r, kBorderWidth); } else { JXFillArrowDown(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; } }
void TestWidget::HandleMouseDown ( const JPoint& pt, const JXMouseButton button, const JSize clickCount, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { if (button == kJXLeftButton && clickCount == 1 && itsHomeRect.Contains(pt)) { JString dir; if (JGetHomeDirectory(&dir)) { JPtrArray<JString> list(JPtrArrayT::kForgetAll); list.Append(&dir); // Normally, you should use the other constructor and then // override JXWidget::GetSelectionData(). JXFileSelection* data = jnew JXFileSelection(GetDisplay(), list); assert( data != NULL ); BeginDND(pt, buttonStates, modifiers, data); } } else if (button == kJXLeftButton && clickCount == 1) { JPainter* p = CreateDragInsidePainter(); p->Rect(JRect(pt, pt)); } else if (button == kJXMiddleButton && clickCount == 1) { itsAnimButton->Place(pt.x, pt.y); } else if (button == kJXRightButton && clickCount == 1 && !modifiers.meta()) { JRect r = itsAnimButton->GetFrame(); if (pt.x > r.left && pt.y > r.top) { itsAnimButton->SetSize(pt.x-r.left, pt.y-r.top); } } else if (button == kJXRightButton && clickCount == 1 && modifiers.meta()) { if (itsSecretMenu->PopUp(this, pt, buttonStates, modifiers)) { return; } else { (JGetUserNotification())->ReportError("Unable to open secret menu!"); } } else if (ScrollForWheel(button, modifiers)) { // work has been done } else if ((clickCount == 2 && its2Rect.Contains(pt)) || (clickCount == 3 && its3Rect.Contains(pt))) { GetNewSize(); } itsStartPt = itsPrevPt = pt; }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName("Times"); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(GetFontManager()->GetDefaultFont()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.ShiftOrigin(-2, 0); p.SetPenColor(colormap->GetBlueColor()); JRect r(70, 290, 150, 390); p.Rect(r); /* for (JCoordinate y=70; y<150; y++) { p.SetPenColor(colormap->GetGrayColor(y-50)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,70, x,150); } p.SetLineWidth(2); for (JCoordinate y=70; y<150; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,70, x,150); } p.SetLineWidth(1); */ p.String( 0.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 90.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(180.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(270.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 0.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String( 90.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(180.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(270.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.SetPenColor(colormap->GetBlueColor()); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetDarkGreenColor()); p.SetFilling(kJTrue); p.Rect(290, 160, 100, 80); p.SetFilling(kJFalse); /* for (JCoordinate y=160; y<240; y++) { p.SetPenColor(colormap->GetGrayColor(y-140)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,160, x,240); } p.SetLineWidth(2); for (JCoordinate y=160; y<240; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,160, x,240); } p.SetLineWidth(1); */ textPt.Set(340, 200); p.SetFontName("Times"); p.SetFontStyle(colormap->GetBlueColor()); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.SetFontStyle(colormap->GetYellowColor()); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.SetPenColor(colormap->GetYellowColor()); r.Set(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); }
TestWidget::TestWidget ( const JBoolean isMaster, const JBoolean isImage, JXMenuBar* menuBar, JXScrollbarSet* scrollbarSet, JXContainer* enclosure, const HSizingOption hSizing, const VSizingOption vSizing, const JCoordinate x, const JCoordinate y, const JCoordinate w, const JCoordinate h ) : JXScrollableWidget(scrollbarSet, enclosure, hSizing, vSizing, x,y, w,h), itsRNG() { JIndex i; itsFillFlag = kJFalse; itsRandPointCount = 10; itsResizeDialog = NULL; SetBackColor(GetColormap()->GetDefaultBackColor()); // cursors JXDisplay* display = GetDisplay(); itsTrekCursor = display->CreateBuiltInCursor("XC_trek", XC_trek); itsGumbyCursor = display->CreateBuiltInCursor("XC_gumby", XC_gumby); itsBogosityCursor = display->CreateBuiltInCursor("XC_bogosity", XC_bogosity); itsFleurCursor = display->CreateBuiltInCursor("XC_fleur", XC_fleur); SetDefaultCursor(itsTrekCursor); // menus itsActionsMenu = menuBar->AppendTextMenu(kActionsMenuTitleStr); itsActionsMenu->SetTitleFontStyle(GetColormap()->GetWhiteColor()); itsActionsMenu->SetShortcuts(kActionsMenuShortcutStr); itsActionsMenu->SetMenuItems(kActionsMenuStr); itsActionsMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsActionsMenu); itsPointMenu = jnew JXTextMenu(itsActionsMenu, kPointMenuCmd, menuBar); assert( itsPointMenu != NULL ); itsPointMenu->SetMenuItems(kPointMenuStr); itsPointMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPointMenu); // This tests the JX response to an empty menu. JXTextMenu* emptyMenu = jnew JXTextMenu(itsActionsMenu, kEmptyMenuCmd, menuBar); assert( emptyMenu != NULL ); JXMenu* prevMenu = itsActionsMenu; JIndex prevMenuIndex = kAdviceMenuCmd; for (i=1; i<=kAdviceMenuCount; i++) { JXTextMenu* adviceMenu = jnew JXTextMenu(prevMenu, prevMenuIndex, menuBar); assert( adviceMenu != NULL ); adviceMenu->SetMenuItems(kAdviceMenuStr[i-1]); adviceMenu->SetUpdateAction(JXMenu::kDisableNone); if (i == kAdviceBoldMenuIndex) { adviceMenu->SetItemFontStyle(2, JFontStyle(kJTrue, kJFalse, 0, kJFalse, GetColormap()->GetBlackColor())); } prevMenu = adviceMenu; prevMenuIndex = 2; } BuildXlsfontsMenu(itsActionsMenu, menuBar); // secret menus are a bad idea because the user can't find them! itsSecretMenu = jnew JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10); assert( itsSecretMenu != NULL ); itsSecretMenu->SetMenuItems(kSecretMenuStr); itsSecretMenu->SetUpdateAction(JXMenu::kDisableNone); itsSecretMenu->SetToHiddenPopupMenu(kJTrue); // will assert() otherwise itsSecretMenu->Hide(); ListenTo(itsSecretMenu); itsSecretSubmenu = jnew JXTextMenu(itsSecretMenu, kSecretSubmenuIndex, this); assert( itsSecretSubmenu != NULL ); itsSecretSubmenu->SetMenuItems(kSecretSubmenuStr); itsSecretSubmenu->SetUpdateAction(JXMenu::kDisableNone); // we don't ListenTo() it because it's only there for show // image from xpm itsXPMImage = jnew JXImage(GetDisplay(), JXPM(macapp_xpm)); assert( itsXPMImage != NULL ); // partial image from image itsPartialXPMImage = jnew JXImage(*itsXPMImage, JRect(5,5,14,16)); assert( itsPartialXPMImage != NULL ); // home symbol itsHomeImage = jnew JXImage(GetDisplay(), JXPM(home_xpm)); assert( itsHomeImage != NULL ); itsHomeRect = itsHomeImage->GetBounds(); itsHomeRect.Shift(120, 10); // buffer contents of Widget in JXImage itsImageBuffer = NULL; if (isImage) { CreateImageBuffer(); } // initial size SetBounds(400,400); // enclosed objects itsAnimButton = jnew JXTextButton("Start", this, JXWidget::kFixedLeft, JXWidget::kFixedTop, 37,175, 50,30); assert( itsAnimButton != NULL ); itsAnimButton->SetShortcuts("#A"); ListenTo(itsAnimButton); if (isMaster) { itsQuitButton = jnew JXTextButton(JGetString("Quit::TestWidget"), this, JXWidget::kFixedRight, JXWidget::kFixedBottom, x,y, 50,30); assert( itsQuitButton != NULL ); JXColormap* colormap = GetColormap(); itsQuitButton->CenterWithinEnclosure(kJTrue, kJTrue); itsQuitButton->SetFontStyle(JFontStyle(kJTrue, kJFalse, 0, kJFalse, colormap->GetRedColor())); itsQuitButton->SetNormalColor(colormap->GetCyanColor()); itsQuitButton->SetPushedColor(colormap->GetBlueColor()); ListenTo(itsQuitButton); } else { itsQuitButton = NULL; } ExpandToFitContent(); // drops on iconfied window JXWindowIcon* windowIcon; const JBoolean hasIconWindow = GetWindow()->GetIconWidget(&windowIcon); assert( hasIconWindow ); ListenTo(windowIcon); }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName(JXGetTimesFontName()); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(JGetDefaultFontName(), kJXDefaultFontSize, colormap->GetBlackColor()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.Rect(310, 70, 80, 80); p.String( 0.0, 310, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String( 90.0, 310,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(180.0, 390,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(270.0, 390, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetYellowColor()); JRect r(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // animated colors p.SetFilling(kJTrue); JCoordinate x = 25; const JSize animColorCount = itsAnimColorList->GetElementCount(); for (i=1; i<=animColorCount; i++) { p.SetPenColor(itsAnimColorList->GetElement(i)); p.Rect(x, 150, 10, 10); x += 10; } // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); // *NEVER* do this in your code! I do it here ONLY to test JXColormap. // (Besides, look at how messy it is!) unsigned long xPixel; if (colormap->CalcPreallocatedXPixel(62720, 56832, 45824, &xPixel)) { JXDisplay* display = GetDisplay(); Display* xdisplay = display->GetXDisplay(); GC gc = DefaultGC(xdisplay, display->GetScreen()); XSetForeground(xdisplay, gc, xPixel); XFillRectangle(xdisplay, (GetWindow())->GetXWindow(), gc, 110,40, 20,20); } }
void JSprite::SetTextureCoord( const float left, const float right, const float top, const float bottom ) { textureCoord = JRect( left, right, top, bottom ); }