Gtk.window get window width and height with VALA - window

I am trying to create a small program which displays an Image. This image will be resized to fit the window size.
Until now you can already see the image on the screen but to make it change its size when resizing the window I have to know how to get the window width and height of my Window.
The problem is, I havent found a good way to do this... and would like to know if somebody could help me with that.
(I am programming with vala in elementary os if that is necessary to know)
I can also post my code if that would help

Here is a simple example to get the width and Height of the window when it resizes. On the signal you can do stuff like resizing the child image pixbuf/image or whatever. Hope it helps.
using Gtk;
public void main (string[] args) {
Gtk.init (ref args);
var window = new Gtk.Window ();
window.configure_event.connect ((event) => {
print ("Width: %d Height: %d\n", event.width, event.height);
return false;
});
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
}

Related

zoom in one state in gicentre geomap on processing

I am using processing 3, and trying to implement an interactive map via gicentre GeoMap library. I have got the U.S. map shown and the hovering feature work i.e. highlight the hovering state. I am wondering is there any way I can zoom into the state in this GeoMap library. Maybe a mouseClick or a mouseMove event to trigger this function. I am not sure how to redraw the map to make it zoom into the selected state. Here is my starting code:
import org.gicentre.geomap.*;
GeoMap geoMap;
int id = -1;
void setup()
{
size(800, 400);
geoMap = new GeoMap(this); // Create the geoMap object.
geoMap.readFile("usContinental"); // Read shapefile.
}
void draw()
{
background(202, 226, 245); // Ocean colour
stroke(0,40); // Boundary colour
fill(206,173,146); // Land colour
//if (id == -1) {
geoMap.draw(); // Draw the entire map.
//} else {
// geoMap.draw(id);
//}
// Find the country at mouse position and draw in different color.
id = geoMap.getID(mouseX, mouseY);
if (id != -1)
{
fill(180, 120, 120); // Highlighted land colour.
geoMap.draw(id);
}
}
Any idea? Thanks!
Questions like these are best answered by looking at the docs for the library. Here are the docs for the giCentre geoMap library.
According to that, this library basically just shows shape files, without any fancy logic for zooming the map. You could implement this yourself using the scale() function or the camera functions. But you might be best off just finding a library that supports changing the zoom out of the box.

Xamarin Forms: scroll position in scrollview

Is there no possibility to read and set the position of the scrollview? For example, I would like to start the app with the scroll position at the bottom, not at the top.
You can get the X and Y position of a ScrollView from the ScrollX and ScrollY properties of the ScrollView object. Then you can set the position with the ScrollView method ScrollToAsync.
var x = scrollView.ScrollX;
var y = scrollView.ScrollY;
...
bool animate = false;
scrollView.ScrollToAsync(x, y, animate);
I've a better approach to this!
You can add this to your onAppearing() method:
protected override void OnAppearing()
{
base.OnAppearing();
/*Other stuff*/
viewModel.Messages.CollectionChanged += (sender, e) =>
{
var target = viewModel.Messages[viewModel.Messages.Count - 1];
ItemsListView.ScrollTo(target, ScrollToPosition.End, false);
};
}
This means that if your collection change, you get the target which is the last item (the one in the bottom) the you use scrollTo target, position end, with animation false.
when you get to the page it will open in the bottom, you don't see the scrolling because animation is false!
For Android, I have found a solution:
I write a custom renderer and in the OnDraw override Method, I call FullScroll(FocusSearchDirection.Down) the first time when the method is called.
What it makes easy, the Android ScrollViewRenderer is subtype of Android.Widget.ScrollView.
At the moment, I don't need an implementation for iOS, so I have no solution for iOS.

How can i use Drag method to resize my application window?

How can i use Drag () method to resize my WPF application window? I am working on TestComplete 9 using Jscript.
Thanks
The easiest way to resize a window is to call its Position method:
// JScript
var wnd = Sys.Process("notepad").Window("Notepad");
wnd.Position(150, 200, 600, 400); // top, left, width, height

Processing or Java: get Window Position?

I'm writing a sketch in Processing and I'm curious how I can get the position of the OS's window that the sketch lives in. If I use getPosition() (part of java.awt) I only get the position of the viewport within the window.
You can use the getLocationOnScreen() inherited from java.awt.Component, but you need to make sure the applet isShowing() first:
void draw(){
if(frame.isShowing()) println(frame.getLocationOnScreen());
}
or slightly more graphical:
void draw(){
if(frame.isShowing()) {
java.awt.Point pt = frame.getLocationOnScreen();
background(255);
rectMode(CENTER);
rect(map(pt.x,0,displayWidth,0,width),//use screenWidth instead of displayWidth in Processing 1.5.1 or older
map(pt.y,0,displayHeight,0,height),//use screenHeight instead of displayHeight in Processing 1.5.1 or older
10,10);
}
}
where
Frame frame = ( (PSurfaceAWT.SmoothCanvas) ((PSurfaceAWT)surface).getNative()).getFrame();
(For other renderers such as P2D or FX2D check out this answer)

draw simple rectangle in MFC Dialog-Based

I wrote this code to draw a simple rectangle in a dialog , I also added ON_WM_PAINT() to my message map. but it didnt show anything on dialog to me ! I really appreciate it if anyone could tell my mistakes in code:
void Ctest4Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = 2;
int y = 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
//I want to draw a rectangle
dc.Rectangle(10,10,50,50);
}
else
{
CDialogEx::OnPaint();
}
}
Looks like your paint code only runs when the window is iconic? Why are you doing that?
Put it in the else block, after the call to CDialogEx::OnPaint().
Your first and biggest mistake is trying to draw directly in a dialog. While it is possible to do so, it's almost always a bad idea. A dialog should usually be treated as a container for controls.

Resources