DrawLine Tool of Teechart Line Disappears on Scroll Axis - activex

I want to draw a circle on LbuttonDown on Series. What I am doing is I am using DrawLine tool and adding a line on OnMouseDownTchart Event. But the Issue is as soon as i do Scroll Axis the line disappears.
Thanks
Akshay

I'm trying to reproduce the problem with the code below but it seems to work fine for me here. It adds a line in a random position each time I click on the chart. And I can still scroll the chart dragging the same with the right mouse button.
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scPoint
Dim i As Integer
For i = 0 To 20
TChart1.Series(0).Add i, "", clTeeColor
Next i
TChart1.Tools.Add tcDrawLine
TChart1.Tools.Items(0).asDrawLine.EnableDraw = False
End Sub
Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
With TChart1.Tools.Items(0).asDrawLine
.AddLine Rnd * 20, Rnd * 20, Rnd * 20, Rnd * 20
End With
End Sub
I'm using TeeChart ActiveX v2013.0.1.0.
Maybe you are doing something at OnMouseDown that enters in conflict with the scroll action.
If you still find problems with it, please, improve the question being more specific. Some code would be helpful. Also I'm not sure to understand what "LbuttonDown on Series" means.

Related

Lua get table that function is attached to

Hello I want to get the table that a function is attached to, I can't really find a nice way to explain it but I think i've explained it good enough within the code for. Basically I need to get the table that the function is attached to from another function, without passing in the table.
function DrawRect()
print(debug.getinfo(1).name) -- this gets the name of the function that is invoking DrawRect ('Paint')..
-- I want to be able to get the table that is attached to this function
-- So I can do table.x inside this function, and have it print 123
end
local r = math.random(1, 100)
_G["abc" .. r] = {
x = 123,
Paint = function(self)
DrawRect()
end
}
_G["abc" .. r]:Paint()
Example of the problem i'm trying to solve
This is my current code right now
function DrawRect(x,y,w,h)
draw.DrawRect(x,y,w,h)
end
local Button = {
Init = function(self)
self.label = gui.Label("Button")
self.label:SetPos(10, 5) -- see the position is relative to the Button's position
self.label:SetColor(255,255,255)
end,
Paint = function(self,x,y,w,h)
Color(40,40,40)
DrawRect(x,y,w,h) -- Draws dark background
end
}
As you can see paint has 4 args, x,y,w,h. I want to do away with x,y and only have w,h. I want to achieve this like this.
function DrawRect(x,y,w,h)
local relative_x = parent_table_of_paint.INTERNAL.draw_x
local relative_y = parent_table_of_paint.INTERNAL.draw_y
draw.DrawRect(relative_x + x, relative_y + y,w,h)
end
local Button = {
Init = function(self)
self.label = gui.Label("Button")
self.label:SetPos(10, 5) -- see the position is relative to the Button's position
self.label:SetColor(255,255,255)
end,
Paint = function(self,w,h)
Color(40,40,40)
DrawRect(0,0,w,h) -- Draws dark background
end
}
I know you can't see some of the properties in my example, but they are there.
Edit 2:
I am recreating the a frame, "VGUI".
https://wiki.facepunch.com/gmod/draw.RoundedBox
draw.RoundedBox( number cornerRadius, number x, number y, number width, number height, table color )
and as you can see this has the functionality I want
https://wiki.facepunch.com/gmod/PANEL:Paint
local panel = vgui.Create( "DPanel" )
panel:SetSize( 100, 100 )
panel:SetPos( ScrW() / 2 - 50, ScrH() / 2 - 50 )
function panel:Paint( w, h )
draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0 ) )
end
A function is a first class value, so there may be many tables and variables that have a reference to the same function. There is no way for that function to know what those tables and variables are.
That's not how you would implement something like that. You don't implement a function that through some magic gets its caller's container so it can access its other values.
DrawRect should just draw a rect. If you want to draw a rect somewhere else you should provide that offset through the parameters of DrawRect.
I modified your button so it will simply put the buttons x and y coordinates (if they exist) into DrawRect
local Button = {
Init = function(self)
self.label = gui.Label("Button")
self.label:SetPos(10, 5) -- see the position is relative to the Button's position
self.label:SetColor(255,255,255)
end,
Paint = function(self,w,h)
Color(40,40,40)
local x = self.x or 0
local y = self.y or 0
DrawRect(x,y,w,h) -- Draws dark background
end
}
That way you can call Button:Paint(20,30) to draw a 20 by 30 rectangle at the buttons coordinates. If you want to add an offset, do that outside of DrawRect
# Edit 2:
This is something different. The host program will call the Paint function.
vgui.Create( "DPanel" ) will return a new panel instance and the game will add a reference to it to a list. Everytime the gui is updated it will call the Paint functions of all the panels in that list. That's how the function knows width and height of the panel.

Mouse cylinder behaviour (dual-screen config)

I've already asked a question about this in Unix & Linux SE and I so actually use xdotool.
The idea is that the mouse goes at the left of the left screen when it reaches the right of the right screen and vice versa.
But I recently saw the mouse.coords table in the awesome API, so I'd like to give up xdotool to set mouse coordinates as do xdotool with this possibility.
I suppose I should add a signal to the root to know when the mouse is on the edge, but I don't konw how to do this...
I give a try to my idea, and it works. Here's the code for my right wibox :
s.myjumpbox = awful.wibar({
position = "right",
screen = s,
width = 1,
opacity = 0,
ontop = true,
-- bg = beautiful.noir
})
s.myjumpbox:connect_signal("mouse::enter", function(w)
mouse.coords {
x = 2 ,
y = mouse.coords().y
}
end
)
Edit : add Uli's suggestions

How to create textbox in love2d

I have been trying to make a box for a user to input data once the user clicks the box. This is what I have so far, but clicking the box does not cause text input to be added to it. Where is the issue?
function love.load ()
txt1 = ""
columnx = { 50, 160, 260, 375, 495, 600, 710 }
columny = { 130, 230, 330, 440, 540, 640 }
if show1 == true then
function love.textinput(t)
txt1 = t
end
end
end
function love.mousepressed (x, y)
if
x >= columnx[4] and
x <= 435 and
y >= columny[1] and
y >= 145 then
show1 = true
end
end
function love.draw ()
love.graphics.print(txt1, columnx[4], columny[1])
end
You're pretty much on the way, but I'll give you some tips on how to create a basic textbox.
Firstly, consider a conceptual textbox to be a singular table, that contains everything it needs to know about itself to properly update and render. It's much easier to reason about something that is self contained.
A textbox needs to know its position, its size, whether it is active, and which text it contains. We can condense that into a table that looks like the following.
local textbox = {
x = 40,
y = 40,
width = 400,
height = 200,
text = '',
active = false,
colors = {
background = { 255, 255, 255, 255 },
text = { 40, 40, 40, 255 }
}
}
(We also store some color info.)
After that the simple way to add text is through love.textinput, as you've seen. In your code we only check if the textbox is active once, in love.load, which it of course isn't since we likely haven't taken any user input yet. Instead of attempting to overload the function, we simply check if the textbox is active or not inside the handler, and proceed accordingly.
function love.textinput (text)
if textbox.active then
textbox.text = textbox.text .. text
end
end
We've covered how to check if the user has clicked within a rectangular area in the question: Love2d cursor positions. We want to deactivate the textbox if it is currently active and the user clicks outside of its space.
function love.mousepressed (x, y)
if
x >= textbox.x and
x <= textbox.x + textbox.width and
y >= textbox.y and
y <= textbox.y + textbox.height
then
textbox.active = true
elseif textbox.active then
textbox.active = false
end
end
And finally we need to render our textbox. We use unpack to expand our color tables, and love.graphics.printf to make sure our text wraps within our textbox's space.
function love.draw ()
love.graphics.setColor(unpack(textbox.colors.background))
love.graphics.rectangle('fill',
textbox.x, textbox.y,
textbox.width, textbox.height)
love.graphics.setColor(unpack(textbox.colors.text))
love.graphics.printf(textbox.text,
textbox.x, textbox.y,
textbox.width, 'left')
end
These are the basic ideas of creating a very rough textbox. It's not perfect. Note that you will need to consider what happens when the text gets longer height-wise than we initially set our textbox's height to, as the two are only loosely related.
To make your program easier to read, and easier to extend, everything you've seen above should really be placed into their own functions that handle textbox tables, instead of cluttering the love handlers with common code. Take a look at Chapter 16 of Programming in Lua, which covers Object-Oriented Programming - a generally vital topic for game development.
See the love.textinput page on how to handle a backspace, to delete characters.
Some extra things to think about:
How can we distinguish an active textbox from an inactive one?
How can we create a list of textboxes, so we can have multiple on screen (but only one active)?
I guess, the love.textinput() callback function is what you are looking for. But as the term 'callback' implies, it will be called by the LÖVE engine, not your code. It will be called whenever the user inputs some text while your game is running. Therefore you need to put it outside the love.load() function.
In the love2d.org wiki is an example for this (the lower one).
As for your example, move the love.textinput() out of love.load() and add an if statement:
function love.load()
txt1 = ""
columnx = {50, 160, 260, 375, 495, 600, 710}
columny = {130, 230, 330, 440, 540, 640}
end
function love.textinput(t)
if (show1) then
txt1 = txt1 .. t
end
end
-- The rest of your code.
-- And maybe mix it with the 'backspace example' from the wiki...
-- But you also might want to have some function to set 'show1' back to 'false' after the text input. Maybe something like this:
function love.keypressed(key)
if (key == "return") and (show1) then
show1 = false
end
end
I hope I could help you a bit!

Rectangle Tool Image Change Run Time

I have added rectangle tool which contain an Image. The feature I want to develop is on right Click I want to change the image in it.
I tried using OnRectangleToolClick but not able to get the rectangle tool details which has been clicked.
Can someone help me with this.
Thanks
Akshay
I've made a simple example with VB6:
Private Sub Form_Load()
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues 8
TChart1.Tools.Add tcRectangle
TChart1.Tools.Items(0).asRectangle.Shape.Picture.LoadImage "C:\tmp\MyImage.jpg"
End Sub
Private Sub TChart1_OnRectangleToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
If Button = mbRight Then
MsgBox "Rectangle clicked with the right mouse button"
End If
End Sub
The above seems not to work fine, but after debugging I've seen when I click on the rectangle tool with the right mouse button and TChart1_OnRectangleToolClick is fired, the Button variable has the value 1, while mbRight is 2. So changing it for this makes it work:
Private Sub TChart1_OnRectangleToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
If Button = 1 Then
MsgBox "Rectangle clicked with the right mouse button"
End If
End Sub
EDIT:
If you want to check when the user clicks the Rectangle tool with the left mouse button, the OnRectangleToolClick event may conflict with the dragging feature.
In that case, you could still play with OnMouseMove, OnClick and OnMouseDown events as in the following example:
Dim mouseXPos, mouseYPos, mouseXDown, mouseYDown As Long
Private Sub Form_Load()
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues 8
TChart1.Tools.Add tcRectangle
TChart1.Tools.Items(0).asRectangle.Shape.Picture.LoadImage "C:\tmp\MyImage.jpg"
mouseXPos = -1
mouseYPos = -1
mouseXDown = -1
mouseYDown = -1
End Sub
Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
mouseXPos = X
mouseYPos = Y
End Sub
Private Sub TChart1_OnClick()
If mouseXDown = mouseXPos And mouseYDown = mouseYPos Then
If TChart1.Tools.Items(0).asRectangle.Clicked(mouseXPos, mouseYPos) Then
MsgBox "Rectangle clicked with the left mouse button"
End If
End If
End Sub
Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
mouseXDown = X
mouseYDown = Y
End Sub

Text alignment to left in Corona

My problem is that I can't align my text to left. I need to set a position where the text will start and it will go to the left and it wont be centered. Its like in html, you make position and it goes from that position to the right, eventually it makes another line. Maybe a picture example will make you understand better because its hard to describe it.
How it should look and where it should start all the time if I add more text it should just continue to the right.
How it looks if I add more text, and that's not how I want it
Here's a bit of the code
text = display.newText("Fair", 0, 0, "HelveticaNeue-Light", 22)
text.x = halfW - 300
text.y = halfH + 110
text.align = "left"
Are you using the Current Public Release (2014.2100) + ?
Try using text.anchorX = 0 instead of text.align = "left"
So anchorX = .5 is same as "middle" and anchorX = 1 is same as "right".

Resources