I have prepared a screen in which I am allowing user to create an account. as shown in the first image I have used an image(bg_BB.png image) as MainScreen Background, after that i have taken another VFM and painting that white Background (white_bg2.png)on that vertical field manager and ADDING ALL MY FIELD ON THAT VFM.
But the problem arises when the keyboard is pops-up. All the fields apears to be floating over the background as shown in the second pic.
Below is the code which I am using:
Bitmap backGroundImage = Bitmap.getBitmapResource("bg_BB.png");
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createBitmapBackground(backGroundImage));
final Bitmap tabBackGroundImage = Bitmap.getBitmapResource("white_bg2.png");
_mainVfm = new VerticalFieldManager(Field.USE_ALL_WIDTH) {
protected void paint(Graphics graphics) {
int y = CreateUserAccountScreen.this.getMainManager().getVerticalScroll();
graphics.drawBitmap(0, y,
tabBackGroundImage.getWidth(),
tabBackGroundImage.getHeight(),
tabBackGroundImage,
0, 0 );
super.paint( graphics );
}
};
replace your code with:
Bitmap tabBackGroundImage = Bitmap.getBitmapResource("white_bg2.png");
VerticalFieldManager _mainVfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL |
Manager.VERTICAL_SCROLLBAR|
Manager.USE_ALL_WIDTH);
_mainVfm.setBorder( BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), tabBackGroundImage
)
);
make sure that your border image have white background.
i use this method and it works perfectly.
Related
My ImageView is matching screen size on x-axis and is using remaining space on y-axis in my layout. I want to create bitmap into this ImageView with exactly the same size as the ImageView is. How to make it please? Can it be done by some automatic setting, should I call some measure function?
I tried SetAdjustViewBounds() but it didn't work for me.
Creating Bitmap big enough (I don't like much such a memory wasting) and setting SetScaleType(ImageView.ScaleType.Matrix) works, but still when I'm making drawing operations on canvas, I don't know real size of area I should paint into, both canvas and bitmap height are equal to yScreen while imgWeekView height is pretending to be 0, even though it paints whole desired area with gray color.
imgWeekView = new ImageView(context);
//imgWeekView.SetAdjustViewBounds(true);
imgWeekView.SetScaleType(ImageView.ScaleType.Matrix);
layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent,1f);
layoutParams.Height = 0;
imgWeekView.LayoutParameters = layoutParams;
Bitmap bitmap = Bitmap.CreateBitmap((int)xScreen, (int)yScreen, Bitmap.Config.Argb8888);
cnvWeekView = new Canvas(bitmap);
imgWeekView.SetImageBitmap(bitmap);
linearLayout.AddView(imgWeekView); //whole activity layout
//Test
cnvWeekView.DrawColor(new Color(128, 128, 128));
Paint paint = new Paint(PaintFlags.AntiAlias);
paint.Color = new Color(255, 255,0);
cnvWeekView.DrawCircle(50, 50, 40, paint);
Finally I found a way how to measure my ImageView and here I will post my answer.
I believed that there should be much easier solution, but maybe there isn't. From this question I took most of the important data:
How to get the width and height of an android.widget.ImageView?
Things look however a little different in my android application and I'm not experienced enough to tell why. I had to change things a little. I had to learn a bit about interfaces and this question helped too.
Implementing the View.IOnTouchListener interface
Here is how I combined things. First I created class that will do the measure.
public class MyPredrawListener : Java.Lang.Object, ViewTreeObserver.IOnPreDrawListener
{
ImageView imageView;
public MyPredrawListener(ImageView img)
{
imageView = img;
}
public bool OnPreDraw()
{
imageView.ViewTreeObserver.RemoveOnPreDrawListener(this);
int finalHeight = imageView.MeasuredHeight;
int finalWidth = imageView.MeasuredWidth;
Bitmap bitmap = Bitmap.CreateBitmap(finalWidth, finalHeight, Bitmap.Config.Argb8888);
imageView.SetImageBitmap(bitmap);
//Test to see result
Canvas cnv = new Canvas(bitmap);
Paint paint = new Paint();
paint.Color = new Color(255, 255, 0);
cnv.DrawColor(new Color(128, 128, 128));
cnv.DrawCircle(finalWidth-50, finalHeight-50, 50, paint);
return true;
}
}
And in code where I create my imageView I set the listener like this.
imgWeekView = new ImageView(context);
MyPredrawListener listener=new MyPredrawListener(imgWeekView);
imgWeekView.ViewTreeObserver.AddOnPreDrawListener(listener);
In OnPreDraw function I put test code to see the result graphically, clearing bitmap to gray color and painting yellow circle to bottom right of a view.
this.canvas = new Canvas(shell, SWT.NO_BACKGROUND);
I'm using a PaintListener:
this.canvas.addPaintListener(new PaintListener() {
#Override
public void paintControl(PaintEvent e) {
// Draw images
synchronized (imageMarks) {
for (ImageMark mark : Whiteboard.this.imageMarks)
{
Image image = Whiteboard.this.getImage(mark.id);
Point position = ScaledPoint.toSWTPoint(Whiteboard.this.getCanvasSize(), mark.getPosition());
Point bounds = mark.getUnscaledBoundaries(Whiteboard.this.getCanvasSize());
e.gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, position.x, position.y,
bounds.x, bounds.y);
}
}
// Draw pencil marks
synchronized (pencilMarks) {
e.gc.setLineWidth(LINE_WIDTH);
for (double[] line : Whiteboard.this.pencilMarks)
{
Point lastPosPoint = ScaledPoint.toSWTPoint(Whiteboard.this.getCanvasSize(), new ScaledPoint(line[0], line[2]));
Point newPosPoint = ScaledPoint.toSWTPoint(Whiteboard.this.getCanvasSize(), new ScaledPoint(line[1], line[3]));
e.gc.drawLine(lastPosPoint.x, lastPosPoint.y, newPosPoint.x, newPosPoint.y);
}
}
// Draw pointer, assuming it's there
if (pointerMark != null)
{
synchronized (pointerMark) {
Point pos = ScaledPoint.toSWTPoint(Whiteboard.this.getCanvasSize(), pointerMark.getPosition());
if (pointerMark.isFlipped())
e.gc.drawImage(Whiteboard.pointerImageFlipped, pos.x, pos.y);
else
e.gc.drawImage(Whiteboard.pointerImage, pos.x, pos.y);
}
}
}
});
and redrawing the canvas via a canvas.redraw() call. On 64-bit Linux, this seems to be working without any issues, but strangely enough, on 64-bit Windows, nothing ever ends up being erased or redrawn. For example, if the screen is resized, the pencil markings do not resize as well, they just end up being cut out of the screen. When new marks are added (in other words, when the paint listener is called again), the repositioned markings are redrawn on top of the old ones which didn't scale with the window. In other words, I believe the canvas is not being cleared upon canvas.redraw(). Is there a workaround for this?
You are specifying SWT.NO_BACKGROUND which stops the Canvas being cleared before each paint.
If you use SWT.NO_BACKGROUND it is your paint method's responsibility to draw every pixel of the Canvas.
SWT.NO_BACKGROUND JavaDoc:
By default, before a widget paints, the client area is filled with the
current background. When this style is specified, the background is
not filled, and the application is responsible for filling every pixel
of the client area. This style might be used as an alternative to
"double-buffering" in order to reduce flicker. This style does not
mean "transparent" - widgets that are obscured will not draw through.
I was searching through the Unity manual to see what they had for gradient effects and I found this:
Here is the link:
http://docs.unity3d.com/Manual/EditingValueProperties.html
However, I can't find this editor anywhere inside of Unity. I want to use this to apply a gradient to my background for a game. Does it exist!?
You do not have access to arbitrarily use color picker or gradient editor. For your purpose of making the background you have several options,
Change the Camera background color from the editor.
Use a Skybox, you can make your own skybox too.
If your game has a limited view, use a plane with a custom material.
Maybe this script shows how you can use Gradients. You need to add this script to one of your GameObject in your scene. And your Camera's tag is MainCamera .
This code based on this.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GradientHandler : MonoBehaviour {
public Camera camera;
public Gradient gradient;
// Use this for initialization
void Start () {
camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>() as Camera; //Gets Camera script from MainCamera object(Object's tag is MainCamera).
GradientColorKey[] colorKey = new GradientColorKey[2];
GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];
// Populate the color keys at the relative time 0 and 1 (0 and 100%)
colorKey[0].color = Color.red;
colorKey[0].time = 0.0f;
colorKey[1].color = Color.blue;
colorKey[1].time = 1.0f;
// Populate the alpha keys at relative time 0 and 1 (0 and 100%)
alphaKey[0].alpha = 1.0f;
alphaKey[0].time = 0.0f;
alphaKey[1].alpha = 0.0f;
alphaKey[1].time = 1.0f;
gradient.SetKeys(colorKey, alphaKey);
}
// Update is called once per frame
void Update () {
Debug.Log ("Time: "+Time.deltaTime);
camera.backgroundColor = gradient.Evaluate(Time.time%1);
}
}
I created an Outlook bar with tree controls and would like to have it auto size to always fully display the text of the tree control. Ideally the border in the picture would move so that "Healthcare Merchandising" is fully visible.
newDimbar is a CMFCOutlookBar object created in CMainFrame.
I have tried stretching it:
void CTreeDrill::OnTvnItemexpanded(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
HTREEITEM hItem = pNMTreeView->itemNew.hItem;
RECT treeRect;
GetItemRect(GetChildItem(hItem), &treeRect, FALSE);
CMainFrame *pMain = (CMainFrame*)AfxGetMainWnd();
int iStretch = treeRect.right;
pMain->m_ctlNewDimBar.StretchPane(iStretch, FALSE);
EnsureVisible(GetChildItem(hItem));
}
and using move:
void CTreeDrill::OnTvnItemexpanded(NMHDR *pNMHDR, LRESULT *pResult)
{
RECT treeRect;
RECT newRect;
RECT dimRect;
GetItemRect(GetChildItem(hItem), &treeRect, FALSE);
CMainFrame *pMain = (CMainFrame*)AfxGetMainWnd();
pMain->m_ctlNewDimBar.GetWindowRect(&dimRect);
newRect = dimRect;
newRect.right = treeRect.right;
pMain->m_ctlNewDimBar.MoveWindow(newRect);
EnsureVisible(GetChildItem(hItem));
}
without luck. What am I missing?
Solution
I'm happy i found it because this is something i would have to do too in the future, you need to use CWnd::SetWindowPos to change the CMFCOutlookBar's size, check this tutorial that has more infos, after you change the size of CMFCOutlookBar you will have to use CFrameWndEx::RecalcLayout method of the frame that contains the CMFCOutlookBar.
Why using CWnd::SetWindowPos?
i don't know, it's the only one that worked for me
Why use CFrameWndEx::RecalcLayout and not only call RecalcLayout() of the CMFCOutlookBar?
Because if you just recalculate the layout of the CMFCOutlookBar only the CMFCOutlookBar will be updated and then if you have anything attached to the CMFCOutlookBar it will not recieve the changes, so you might end with your CMFCOutlookBar overlapping some other control or your document's view, calling CFrameWndEx::RecalcLayout will make the whole frame reacalculate and so if you have tabbed document views they will be updated/resized accordingly.
Your case
you will have to calculate the whole width of the tree, not only the item, and then use the CWnd::SetWindowPos on the CMFCOutlookBar with the updated value width value but keeping the height of the CMFCOutlookBar.
newDimbar.GetWindowRect(pos);
ScreenToClient(&pos);
UINT flags = SWP_NOZORDER | SWP_NOMOVE;
newDimbar.SetWindowPos(NULL, 0, 0, iNewWidth, pos.Height(), flags);
I have drawn rectangles in picture box using paint event. When i click clear button. i want the graphics to vanish. i call paint event everytime the mouse moves. What should i do?
Code in paint event:
Graphics^ g = e->Graphics;
float PenWidth = 2;
if(msdwnflag!=-1 && count%2==1)
{
if(selecflag==0)
{
g->DrawRectangle( gcnew Pen( Color::Blue,PenWidth ), RcDraw);
}
else
{
RcDraw.Width = finalMousePos.X- RcDraw.X;
RcDraw.Height = finalMousePos.Y- RcDraw.Y;
g->DrawRectangle( gcnew Pen( Color::Red,PenWidth ), RcDraw);
}
}
If pb is your PictureBox then clear its image to clear all the graphics. Also, You can use a variable (buttonpressed) to check whether it is true (button clear pressed) or false (otherwise)
buttonpressed=1;
pb->Image = nullptr;
pb->Refresh();
In your paint method include all the graphics if Not buttonpressed:
if (buttonpressed != 1){
// all your graphics code
}
When you want the graphics to appear back when you press a button change the buttonpressed value:
buttonpressed=0;
pb->Refresh();
Draw a graphics of the transparent colour. thats wat i finally did. not a gud design but works :)