Using FLTK API, how to find the fullscreen height? - fltk

Fl::h() excludes the height of the task bar at the bottom.
I have an Fl_Double_Window inside an FL_Window. After I make the outer window (Fl_Window) full screen using fullscreen() method, I want to make the height of the Fl_Double_Window equal to the height of the screen. If I use innerWindow->size(Fl::w(), Fl::h()); it does not extend its height all the way to the bottom of the screen.

I believe Fl::w() and Fl::h() will give you width and height of the working area. After examining the list of screen functions I believe your best option is to get the number of screens using the static int Fl::screen_count () and then use the static void Fl::screen_xywh (int &X, int &Y, int &W, int &H, int n) where n is the index of the screen you want to analyze, typically 0.
If all you care about is the screen below the mouse pointer, use the static void Fl::screen_xywh (int &X, int &Y, int &W, int &H) function.

Related

LWJGL Fullscreen while keeping aspect ratio?

I want to have a fullscreen mode that keeps the aspect ratio by adding black bars on either side. I tried just creating a display mode, but I can't make it fullscreen unless it's a pre-approved resolution, and when I use a bigger diaplay than the native resolution the pixels become messed up, and lines appeared between all of the tiles in the game for some reason.
I think I need to use FBOs to render the scenario to a texture instead of the window, and then just use a fullscreen approved resolution and render the texture properly stretched out in the center of the screen, but I just don't understand how to render to a texture in order to do that, or how to stretch an image. Could someone please help me?
EDIT
I got fullscreen working, but it makes everything all broken looking There are random lines on the edges of anything that's written to the window. There are no glitchy lines when it's in native resolution though. Here's my code:
Display.setTitle("Mega Man");
try{
Display.setDisplayMode(Display.getDesktopDisplayMode());
Display.create();
}catch(LWJGLException e){
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,WIDTH,HEIGHT,0,1,-1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
try{Display.setFullscreen(true);}catch(Exception e){}
int sh=Display.getHeight();
int sw=WIDTH*sh/HEIGHT;
GL11.glViewport(Display.getWidth()/2-sw/2, 0, sw, sh);
Screenshot of the glitchy fullscreen here: http://sta.sh/021fohgnmxwa
EDIT
Here is the texture rendering code that I use to draw everything:
public static void DrawQuadTex(Texture tex, int x, int y, float width, float height, float texWidth, float texHeight, float subx, float suby, float subd, String mirror){
if (tex==null){return;}
if (mirror==null){mirror = "";}
//subx, suby, and subd are to grab sprites from a sprite sheet. subd is the measure of both the width and length of the sprite, as only images with dimensions that are the same and are powers of 2 are properly displayed.
int xinner = 0;
int xouter = (int) width;
int yinner = 0;
int youter = (int) height;
if (mirror.indexOf("h")>-1){
xinner = xouter;
xouter = 0;
}
if (mirror.indexOf("v")>-1){
yinner = youter;
youter = 0;
}
tex.bind();
glTranslatef(x,y,0);
glBegin(GL_QUADS);
glTexCoord2f(subx/texWidth,suby/texHeight);
glVertex2f(xinner,yinner);
glTexCoord2f((subx+subd)/texWidth,suby/texHeight);
glVertex2f(xouter,yinner);
glTexCoord2f((subx+subd)/texWidth,(suby+subd)/texHeight);
glVertex2f(xouter,youter);
glTexCoord2f(subx/texWidth,(suby+subd)/texHeight);
glVertex2f(xinner,youter);
glEnd();
glLoadIdentity();
}
Just to keep it clean I give you a real answer and not just a comment.
The aspect ratio problem can be solved with help of glViewport. Using this method you can decide which area of the surface that will be rendered to. The default viewport will cover the whole surface.
Since the second problem with the corrupt rendering (also described here https://stackoverflow.com/questions/28846531/sprite-game-in-full-screen-aliasing-issue) appeared after changing viewport I will give my thought about it in this answer as well.
Without knowing exactly how the rendering code for the tile background looks. I would guess that the problem is due to any differences in the resolution between the glViewport and glOrtho calls.
Example: If the glOrtho resolution is half the viewport resolution then each openGL unit is actually 2 pixels. If you then renders a tile between x=0 and x=9 and then the next one between x=10 and x=19 you will get an empty space between them.
To solve this you can change the resolution so that they are the same. Or you can render the tile to overlap, first one x=0 to x=10 second one x=10 to x=20 and so on.
Without seeing the tile rendering code I can't verify it this is the problem though.

J2ME - How to copy area into Image in Canvas?

I want to copy any area in Canvas with x and y coordinates and then paste it to any Image.
In example:
Image image = Image.createImage(30, 20);
image.drawImage(canvas);
It is not possible to copy data from Canvas nor GameCanvas.
To achieve what you want, you have to use doublebuffering. Meaning, you have to use an Image bufferImg as your buffer to draw on, and then draw that bufferImg onto your Canvas.
That way, you can copy from the Image onto another Image like this:
bufferImg.getRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height);
and then
g.drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha);
where g is the Graphics object of the 2nd Image you want to draw onto.
Using a doublebuffer like this will slow things down a bit on some devices of course, but you can't do it any other way if you want to be able to "extract" portions of the screen.

Compositing 2 images in J2ME

I intend to fit an image centered horizontally and vertically inside a J2ME form. However I couldn't find useful markup elements to do so. So I intend to create one totally transparent image the size of the form element and superimpose my intended image on it centered. And place the resulting image in the form (without using a canvas). I am looking for ways of doing this because my knowledge of J2ME is limited.
Any help, please?
public static Image CreateCompositeImage(Image oImage,int formWidth,int formHeight){
final int imageWidth=oImage.getWidth();
final int imageHeight=oImage.getHeight();
int[] imge=new int[imageWidth*imageHeight];
oImage.getRGB(imge,0,imageWidth,0,0,imageWidth,imageHeight);
final int topMargin=(formHeight-imageHeight)/2;
final int leftMargin=(formWidth-imageWidth)/2;
final int pixelTop=topMargin*formWidth;
int[] c=new int[formWidth*formHeight];
int p=0, r=0;
for (int i=0;i<pixelTop;i++){
c[p++]=0xff000000;
}
for (int j=0;j<imageHeight;j++){
for (int i=0;i<leftMargin;i++){
c[p++]=0x880000ff;
}
for (int i=0;i<imageWidth;i++){
c[p++]=imge[r++];
}
for (int i=0;i<leftMargin;i++){
c[p++]=0x8800ff00;
}
}
int pixelBottom=formWidth*formHeight-p;
for (int i=0;i<pixelBottom;i++){
c[p++]=0xffffffff;
}
return Image.createRGBImage(c,formWidth,formHeight,true);
}
A better approach is to create new class that inherits from CustomItem, or to use a Canvas instead of the Form.
In both cases you override the paint() method.
There you get a Graphics-Object. You use this object do do your drawing.
Especially for you it has a drawImage() method, where you can just put in the position.
You then need no pixel data manipulation.
Overriding CustomItem or Canvas is something you do often in Java-me programming, so it is worth learn it.

resize issue CListBox inside SDI application with CWnd derived child

I am having a problem with the size of the CListBox that is suppose to cover all the client area of the SDi application.
My Main Window looks as shown below:
As you can clearly see that the list box does not cover the whole client area.
The following is what I am doing in on size of the CWnd derived class:
void CLogWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
m_pWndLogList->SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER);
}
CLogWnd is the main window that fill all the area of the CMainFrame.
Give your listbox LBS_NOINTEGRALHEIGHT style. Without it, the box wants to have a height that's an exact multiple of a row height.

Creating UI dynamically in android

I want to make UI for tablet like shown in images.This UI will repeat according to number of items. And the position of each block (i.e small or big block) can change dynamically. Please give me suggestion which view,layout i should use.
Any suggestion would be appreciated...thanks in advance.
If you are targeting a API v14 or above, you can use GridLayout: http://developer.android.com/reference/android/widget/GridLayout.html
Using LinearLayout where each category is added and using RelativeLayout for each category is a good option. You should customize onlayout method of the relative layout as a function of number of products it contains.
You can use fragments, listview as well.
EDIT after image change: You can just extend relativelayout and override onLayout method. This will perform better than nested layouts and I can't think of anything else you can get away with less effort.
EDIT for elaboration:
Here is an example class I use. Basically in the onlayout method you make every decision and tell all the child views to lay them in a rectangle by calling layout method of each of them and passing the parameters of the rectangle. See how I use layout method of child view to dictate the rectangle.
public class KnockPile extends HandPile
{
private static final String TAG = "KnockPile";
static final int EXPECTED_CARDS = 3;
int mColoring; // this is the coloring group this pile is associated with.
// every card added to this pile should be set with this color.
public KnockPile(Context context, GameActivity ref , int ingroup)
{
super(context );
mColoring = ingroup;
mActivityReference = ref;
setWillNotDraw(false);
setClickable(true);
setOnDragListener(this);
mCardBorders = new ArrayList<Integer>();
final LayoutTransition transition = new LayoutTransition();
setLayoutTransition(transition );
//transition .enableTransitionType(LayoutTransition.CHANGING);
//transition .disableTransitionType(LayoutTransition.CHANGE_APPEARING);
}
/**
* this overrides the card ordering of handpile. This method lays the cards in a linear fashion.
* Possibly overlapping fashion. This is not dependent to orientation of screen.
*
* #see com.kavhe.kondi.gin.layouts.HandPile#onLayout(boolean, int, int, int, int)
*/
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int availablewidth = getMeasuredWidth() ;//this is the maximum availlable
int distance = availablewidth /Math.max(getChildCount(), 1) ; // the horizontal distance between two cards
Log.v(TAG,"available width onlayout is :" + availablewidth +"and distance is " + distance);
int cardheight = getHeight();
int cardwidth = cardheight*3/4;
if(distance > cardwidth) distance = cardwidth;
mCardBorders.clear();
for(int i = 0 ; i < mCards.size() ; i++)
{
//save this border into a global variable so that it can be used when one of the cards dragged
//by user to show that user can insert to that location
mCardBorders.add( i*distance);
mCards.get(i).layout( i*distance , 0 , cardwidth+ i*distance , cardheight);
}
}
}
and this is from documentation
protected void onLayout (boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent
It is also possible through table layout with its row span property
Are the "products" always going to fit nicely on lines as you have drawn? If then, you can use LinearLayouts (Vertical and Horizontal) nested in each other.
To design such UIs for Tablets you should use Fragments and inside the fragment add/remove your respective layouts. If you are taking Relative Layouts then proper usage of RelativeLayout.LayoutParams is required.
If you are looking for a best example which uses Fragments try Google IO app source. It uses various dynamic UI features.
Hope it helps !
With the help of StaggeredGridView I sloved my requirement.
Thanks to all for help and support.

Resources