Re: GTKD - CSS class color "flash" delay

2016-06-30 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 30 June 2016 at 20:11:17 UTC, Mike Wey wrote:

Is the complete source available some ware?


Yes, here: http://pastebin.com/h0Nx1mL6




Re: GTKD - CSS class color "flash" delay

2016-06-30 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 29 June 2016 at 10:41:21 UTC, TheDGuy wrote:
I tried to debug a little and what i don't understand is, that 
i get two times 'blue' on the console, even though yellow and 
blue lit up but yellow stayed at the flash color:


private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
index = i;
Button currentButton = bArr[rndButtonBlink[i]]; 
//Array holds randomized Buttons
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);

currentButton.getStyleContext().addClass(CSSClassName ~ 
"-flash");
Timeout t = new Timeout(() => 
this.timeout_delay(currentButton),1,false);

}

foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(Button currentButton){
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);

writeln(CSSClassName); //try to debug

currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");

return false;
}

The reason for the problem that buttons are flashing 
simultaneously might be, that the Timeout is running in an 
extra thread and therefore another Timeout is created by the 
mainthread in the for-loop even though the last one hasn't 
finished yet.


But what i don't understand is why the last button doesn't go 
back to the normal CSSClass and that the first button has two 
timeouts (according to my console debug text)?


It would be very much appreciated if someone who has GTKD 
installed can try my code:


http://pastebin.com/h0Nx1mL6


Okay, i am quite sure now that this is some kind of bug:

https://picload.org/image/rrrgwpgi/gtkd_timeout.png

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
index = i;
Button currentButton = bArr[rndButtonBlink[i]]; 
//Array holds randomized Buttons
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");

writeln("Creating Timeout for : " ~ CSSClassName);
Timeout t = new Timeout(() => 
this.timeout_delay(currentButton),1,false);

}

foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(Button currentButton){
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().removeClass(CSSClassName 
~ "-flash");

writeln("Removing flash CSS color for: " ~ CSSClassName);
return false;
}


Re: GTKD - CSS class color "flash" delay

2016-06-29 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 26 June 2016 at 21:06:58 UTC, TheDGuy wrote:


Thanks for your answer,

but as i said before, i want to flash each button on it's own 
(the game is kinda like 'Simon Says').


I tried to debug a little and what i don't understand is, that i 
get two times 'blue' on the console, even though yellow and blue 
lit up but yellow stayed at the flash color:


private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
index = i;
Button currentButton = bArr[rndButtonBlink[i]]; 
//Array holds randomized Buttons
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");
Timeout t = new Timeout(() => 
this.timeout_delay(currentButton),1,false);

}

foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(Button currentButton){
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);

writeln(CSSClassName); //try to debug
currentButton.getStyleContext().removeClass(CSSClassName 
~ "-flash");

return false;
}

The reason for the problem that buttons are flashing 
simultaneously might be, that the Timeout is running in an extra 
thread and therefore another Timeout is created by the mainthread 
in the for-loop even though the last one hasn't finished yet.


But what i don't understand is why the last button doesn't go 
back to the normal CSSClass and that the first button has two 
timeouts (according to my console debug text)?


It would be very much appreciated if someone who has GTKD 
installed can try my code:


http://pastebin.com/h0Nx1mL6




Re: GTKD - CSS class color "flash" delay

2016-06-26 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 26 June 2016 at 16:29:52 UTC, Mike Wey wrote:


How about this:

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName ~ 
"-flash");

}
Timeout t = new Timeout(_delay,1,false);
}

bool timeout_delay(){
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);

currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");

}
foreach(Button btn;bArr){
btn.setSensitive(true);
}
return false;
}

Sets all the buttons to the flash color and after an timeout 
removes the flash color from all the buttons.


Thanks for your answer,

but as i said before, i want to flash each button on it's own 
(the game is kinda like 'Simon Says').


Re: GTKD - CSS class color "flash" delay

2016-06-26 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 26 June 2016 at 12:30:22 UTC, Mike Wey wrote:


You should probably increment the index in the timeout_delay 
function.


This leads to a Range violation exception...


Re: GTKD - CSS class color "flash" delay

2016-06-25 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 25 June 2016 at 21:57:35 UTC, TheDGuy wrote:
But i want to flash (e.g. change the CSS class) the buttons one 
by one and not all at the sime time? How am i going to do that?


Okay, i tried it with a new private int-variable which contains 
the current index of the for-loop, like this:


private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
index = i; //index is public
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");

Timeout t = new Timeout(_delay,1,false);
}

foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(){
Button currentButton = bArr[rndButtonBlink[index]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().removeClass(CSSClassName 
~ "-flash");

return false;
}

But now the strange thing happens, that the first button lights 
up as expected but the second button remains at its "flash color" 
and doesn't go back to normal color, i don't understand why this 
happens? Any ideas?


Re: GTKD - CSS class color "flash" delay

2016-06-25 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 25 June 2016 at 20:39:53 UTC, Mike Wey wrote:


The constructor accepts an delegate, witch can access it's 
context so it has access to some of the data.


The functions from GTK are also available like Timeout.add from 
the linked tutorial: 
http://api.gtkd.org/src/glib/Timeout.html#Timeout.add



You may want to do something like this:

```
private void letButtonsFlash()
{
foreach(Button btn;bArr){
btn.setSensitive(false);
}

Timeout t = new Timeout(_delay,5,false);
}

private bool timeout_delay()
{
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName ~ 
"-flash");

}

return false;
}

```


Thanks a lot for your answer, i tried it like this and it works:

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");

}

Timeout t = new Timeout(_delay,1,false);

foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(){
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);

currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");

}
return false;
}

But i want to flash (e.g. change the CSS class) the buttons one 
by one and not all at the sime time? How am i going to do that?




Re: GTKD - CSS class color "flash" delay

2016-06-25 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 25 June 2016 at 15:26:00 UTC, TheDGuy wrote: }

But i get the error:
Error: none of the overloads of '__ctor' are callable using 
argument types (bool delegate(void* userData), int, bool), 
candidates are:


This is the correct error message:

Error: none of the overloads of '__ctor' are callable using 
argument types (bool delegate(Button currentButton), int, bool), 
candidates are:





Re: GTKD - CSS class color "flash" delay

2016-06-25 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 25 June 2016 at 13:01:09 UTC, TheDGuy wrote:

Thanks for your answer.
I have to pass the Button object to my timeout function to 
change the CSS class. But how do i do that within the Timeout 
constructor?


I mean:

I have to pass my function and delay time to the constructor, but 
i can't pass any data to the function here, also only functions 
are allowed (at least it looks like that to me) who don't have 
parameters.


If i want to add a new function i have to use the function 
.add(), with this function i can pass 'userData' (so my button 
for example). But why am i unable to do that in the constructor? 
Do i have 2 different functions for the same thing, one with the 
other one without parameter?


My current approach:

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");

//writeln(CSSClassName);
Timeout t = new Timeout(_delay,5,false); 
//error appears here

t.add(5,_delay,currentButton);
}
foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(Button currentButton){
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().removeClass(CSSClassName 
~ "-flash");

return false;
}

But i get the error:
Error: none of the overloads of '__ctor' are callable using 
argument types (bool delegate(void* userData), int, bool), 
candidates are:
glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, 
bool fireNow = false)
glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, 
GPriority priority, bool fireNow = false)
glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, bool 
fireNow = false)
glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, 
GPriority priority, bool fireNow = false)


If i take a look at GTK for C it looks like there is a function 
for that:


http://www.gtk.org/tutorial1.2/gtk_tut-17.html

Why is this so confusing?


Re: GTKD - CSS class color "flash" delay

2016-06-25 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 25 June 2016 at 11:45:40 UTC, Mike Wey wrote:



You should change the css class in the timeout_delay function.

It's called by the GTK main loop every time the amount of 
seconds passed to the constructor has passed. And return true 
if you want to continue to flash the button, and false to stop.


Also don't sleep in the timeout function, the main loop should 
take care of that, currently you are blocking the main thread 
for 5 seconds.


Thanks for your answer.
I have to pass the Button object to my timeout function to change 
the CSS class. But how do i do that within the Timeout 
constructor?


Re: GTKD - CSS class color "flash" delay

2016-06-24 Thread TheDGuy via Digitalmars-d-learn

On Friday, 24 June 2016 at 16:44:59 UTC, Gerald wrote:
Other then the obvious multi-threaded, using glib.Timeout to 
trigger the reversion of the color change could be an option.


http://api.gtkd.org/src/glib/Timeout.html


Thanks! I tried this so far:
private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");

writeln(CSSClassName);
Timeout t = new Timeout(_delay,1,true);

currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");


}
foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(){
Thread.sleep(dur!("seconds")(5));
return false;
}

and it is "working" to the extend that at least the CSSClassName 
gets written in the console but the UI again just pops up after 5 
sec. Could you give me a tip?


GTKD - CSS class color "flash" delay

2016-06-24 Thread TheDGuy via Digitalmars-d-learn

Hello,

i would like to flash some buttons with CSS. My current approach:

for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName 
~ "-flash");

writeln(CSSClassName);
//some kind of delay

currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");

}

The color changing part works fine but if i use some kind of 
delay the program just starts delayed but no color changing 
happens. I am wondering why, because everything is executed in 
one thread, so the execution order looks like this to me:


1. Start GUI
2. Change Button Color to flash color
3. Wait 2 sec
4. Change Button Color back to standard

but instead it looks like this:

1. Wait 2 sec
2. Start GUI
3. Change Button Color to flash color
4. Change Button Color back to standard

Now because a delay is missing the change between the colors 
happens unnoticeable fast.


I hope i can get around it without getting into multithreading?


Re: GTKD - addOnButtonPress faulty?

2016-06-24 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 23 June 2016 at 22:00:18 UTC, Mike Wey wrote:


addOnPressed is deprecated addOnButtonPress is not.


Ah, okay. I changed the event type to addOnButtonRelease and it 
works fine now, i don't know if it's just me or if 
addOnButtonPress behaves a little bit strange.


GTKD - addOnButtonPress faulty?

2016-06-23 Thread TheDGuy via Digitalmars-d-learn

Hi,

sorry for my next thread but i did encounter a strange behaviour 
of the "Button.addOnButtnPress" - Event. Sometimes if i click 
very fast on the GTKD button, it reacts twice! I am working on a 
small game and i noticed that if i click slowly everything works 
as expected but sometimes i have to click a button more than once 
and if i do it very fast it is often recognized as 3 clicks. I 
did it like this:


Button btn_1 = new Button();
auto call1 = 
btn_1.addOnButtonPress(call1);

bool btn1ClickedEvent(Event e, Widget widget){
userInput ~= 1;
checkForWin();
return true;
}

So is it my bad code or was it recognized by others as well? I 
know that GTKD claims that this method is deprecated but i didn't 
find anything else that works.


Get specific item by index from DList

2016-06-22 Thread TheDGuy via Digitalmars-d-learn

Hi,

i am currently programming a small game with GTKD and i have to 
use a Dlist because an array is static but i want to add user 
inputs dynamically to a list. Now i am wondering how i can get a 
specific item from that list? I read that this isn't possible but 
is it possible to convert that DList temporarily to an array to 
get a specific element? My DList just contains integer values, 
anyone who could offer a short code example?

This doesn't work:

to!Array(level,int,userInput)[i])

Level is the length of the list, int is the type and userInput is 
the DList.


Re: GTKD - get CSS class for button

2016-06-22 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 22 June 2016 at 17:50:53 UTC, Mike Wey wrote:

"Type T wraps should match the type of the data"

Does string match the type of the data? What is the type of 
the data?
How do i tell the function that i want the Array as a string 
array? I am

not familiar with Types and what 'TC' or 'T' is, i am afraid.


toArray currently only works for GtkD classes, so it doesn't 
work for lists of stings.


ListG is a linked list, the data is stored in the data 
property. to iterate over the list do something like this:


```
ListG list = widget.getStyleContext().listClasses();

while(list !is null)
{
string str = to!string(cast(char*)list.data);

//do something with str.

list = list.next;
}
```


Thanks alot! Works perfectly!



Re: GTKD - get CSS class for button

2016-06-22 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 22 June 2016 at 13:47:01 UTC, Gerald wrote:

On Wednesday, 22 June 2016 at 12:57:51 UTC, TheDGuy wrote:
widget.getStyleContext().listClasses() to get a list of all 
classes assigned to the widget. If you just want to see if a 
specific class is assigned to the widget you can use 
widget.getStyleContext().hasClass()


Thanks a lot for your answer. Do you know how i can get the 
first classname as string from the widget? I don't understand 
how the return type 'GList' is organized.


ListG has a D specific method called toArray that allows you to 
convert it to a typed array, so you could use it in this case 
to get a string[] out of it.


http://api.gtkd.org/src/glib/ListG.html


"Type T wraps should match the type of the data"

Does string match the type of the data? What is the type of the 
data? How do i tell the function that i want the Array as a 
string array? I am not familiar with Types and what 'TC' or 'T' 
is, i am afraid.


Re: GTKD - get CSS class for button

2016-06-22 Thread TheDGuy via Digitalmars-d-learn
widget.getStyleContext().listClasses() to get a list of all 
classes assigned to the widget. If you just want to see if a 
specific class is assigned to the widget you can use 
widget.getStyleContext().hasClass()


Thanks a lot for your answer. Do you know how i can get the first 
classname as string from the widget? I don't understand how the 
return type 'GList' is organized.


Re: Access vialotion

2016-06-22 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote:

I have an array of buttons:

class Window : MainWindow{
private Button[4] bArr;
this(){
Button btn_1 = new Button();
Button btn_2 = new Button();
Button btn_3 = new Button();
Button btn_4 = new Button();
Button[4] bArr = [btn_1,btn_2,btn_3,btn_4];
}
private void letButtonsFlash(){
for(int i = 0; i < 4; i++){
writeln(this.bArr[i].getName());
}
}
}

i don't understand why i get an 'Access Violation' - Error in 
the 'for'-loop?


Okay, i solved it, instead of:
Button[4] bArr = [btn_1,btn_2,btn_3,btn_4];

this:
bArr = [btn_1,btn_2,btn_3,btn_4];


Access vialotion

2016-06-22 Thread TheDGuy via Digitalmars-d-learn

I have an array of buttons:

class Window : MainWindow{
private Button[4] bArr;
this(){
Button btn_1 = new Button();
Button btn_2 = new Button();
Button btn_3 = new Button();
Button btn_4 = new Button();
Button[4] bArr = [btn_1,btn_2,btn_3,btn_4];
}
private void letButtonsFlash(){
for(int i = 0; i < 4; i++){
writeln(this.bArr[i].getName());
}
}
}

i don't understand why i get an 'Access Violation' - Error in the 
'for'-loop?


GTKD - get CSS class for button

2016-06-22 Thread TheDGuy via Digitalmars-d-learn

Hello,
i would like to know if it possible to get the CSS-class which is 
asigned to a button (for example)? I didn't find any 
documentation about this, just the function 
"getStyleContext().getProperty()", my current attempt:


Value value;
bArr[0].getStyleContext().getProperty("Class",StateFlags.NORMAL,value);


(bArr is an array of buttons).

I get the error, that 'Value' is not defined, if i use 'GValue' 
(as it is described here: 
https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-get-property) i get 'function is not callable with GValue'


Any ideas? Thanks alot!



Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-22 Thread TheDGuy via Digitalmars-d-learn
I am wondering if it is possible to get the name of the current 
CSS-class the button is asigned to?


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-17 Thread TheDGuy via Digitalmars-d-learn

On Friday, 17 June 2016 at 06:18:59 UTC, Basile B. wrote:

On Thursday, 16 June 2016 at 09:18:54 UTC, TheDGuy wrote:

On Thursday, 16 June 2016 at 08:20:00 UTC, Basile B. wrote:
Yes it's "WorkingDirectory" (and not current...). But 
otherwise you can use args[0]. Actually using the cwd in a 
program is often an error because there is no guarantee that 
the cwd is the path to the application ;)


People often forget that (Generally speaking).


If i use args[0] as workingDirectory i still get the same 
error. I created a custom Tool like this:


https://picload.org/image/rgwapdac/coedit_run_options.png

if i execute it via "Custom Tools" -> "Run this project" 
nothing happens.


There was a bug I've fixed yesterday. There's a workaround: 
this would have worked when the tool option "clearMessages" is 
checked.


Thanks a lot!


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 13:12:12 UTC, Gerald wrote:


It can be done fine with on the fly changes, i.e. random 
colors, it's somewhat more work then just calling a simple 
function call but CSS gives you a lot more power as well. I do 
this in Terminix where for certain themes I want to set the 
scrollbar background to be the same color as the terminal 
background.


Essentially, add a class to the widget and then construct the 
CSS for the class with your random background color as a 
string. Create a CSSProvider and use loadFromData, same as 
captaindet's example, to load the CSS in the string. Finally, 
use the widget's style context to add the CSS provider which 
you just constructed. If you want to change the color, remove 
that provider and add a new one.


Ahhh. Thas possible for sure, thanks alot!

I finally found the solution for my background-color problem: we 
have to remove the image first, so this works for me now:


#CssName{
background-image: none;
background-color:green;
color:green;
}


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 17:44:08 UTC, Basile B. wrote:

Please Stop your comedy.


Thanks a lot for your help!
This is my solution:

import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;
import glib.GException;
import std.stdio;
import std.file;
import std.path;

class Window : MainWindow{
this(int width, int height, string title, string wd){
super(title);
setDefaultSize(width, height);
Button btn = new Button("Test");
btn.setName("CssName");

string cssPath = dirName(wd) ~ "\\" ~ "test.css";

CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);

Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


add(btn);
showAll();
}
}

void main(string[] args){
Main.init(args);
auto win = new Window(250,250,"Tutorial", args[0]);
Main.run();
}


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 10:14:47 UTC, Basile B. wrote:


from args[0] you can get the base bath and since your css is 
relative to the base path:


string cssPath = "test.css";
CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);


add something like

import std.path;
basePath = args[0].dirName;

string cssPath = basePath ~ "\" ~ "test.css";

and you can remove all the stuff in the Run options.


But i don't call my CSS file in the main-function but instead i 
call it in the MainWindow:


import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;
import glib.GException;

class Window : MainWindow{
this(int width, int height, string title){
super(title);
setDefaultSize(width, height);
Button btn = new Button("Test");
btn.setName("CssName");

string cssPath = "test.css";

CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);

Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


add(btn);
showAll();
}
}

void main(string[] args){
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 09:27:38 UTC, Basile B. wrote:
FOrget any previous comment and in your program use the first 
argument of the command line to detect your resources, this 
will solve your problem. For the execution click compile and 
run or just run.


Okay:

void main(string[] args){
writeln(args[0]);
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}

This gives me the location of the .exe. What should i do with it 
now?


On Win and Nux, the first argument of the command line is 
always the program filename so you just have to get the 
directory for this string and you'll get what you expected with 
cwd.


I don't care about cwd i want to get rid of the error!




Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 08:20:00 UTC, Basile B. wrote:
Yes it's "WorkingDirectory" (and not current...). But otherwise 
you can use args[0]. Actually using the cwd in a program is 
often an error because there is no guarantee that the cwd is 
the path to the application ;)


People often forget that (Generally speaking).


If i use args[0] as workingDirectory i still get the same error. 
I created a custom Tool like this:


https://picload.org/image/rgwapdac/coedit_run_options.png

if i execute it via "Custom Tools" -> "Run this project" nothing 
happens.


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 22:34:05 UTC, Gerald wrote:

snip...

The text color is green but the button background color is 
still default-gray!


I don't see an obvious issue with your code, I usually use CSS 
classes personally and I know that works fine because I use 
this technique all over terminix. I would suggest using the GTK 
Inspector to debug the CSS issue, it's an awesome tool for 
figuring out GTK CSS issues as it let's you change CSS on the 
fly, see what CSS is being applied to an object, etc. You can 
see how to use it at the link below:


https://wiki.gnome.org/Projects/GTK%2B/Inspector



Do you know if this works on windows?


Personally I just add and remove classes as needed:

getStyleContext().addClass()
getStyleContext().removeClass()


So you basically have to create 2 classes? And what would you do 
if you would have to change the color randomly (for a simon says 
game)? I still think it is a bad idea to claim the way with 
function calls as deprecated but introducing a new system which 
is not as flexible (but maybe more powerfull).

C# with Visual Studio does it, PyQT does it: Function calls.



Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 00:46:44 UTC, Basile B. wrote:

On Wednesday, 15 June 2016 at 23:41:51 UTC, Basile B. wrote:


- You can create a launcher in the custom tools, excluding the 
double quote:

- as executable type ""
- as CurrentDirectory type ""
- as alias put something like "Run this project"
This will work if the binary is compiled in the same directory 
as the binary that's produced. Otherwise you can adjust by 
adding directories after the symbol. (e.g  "bin\release").



You just need to change "CurrentDirectory" in the "Run options".


Hm, i don't see "CurrentDirectory" in the run options tab:
https://picload.org/image/rgwaopad/coedit_run_options.png

- I had to verify but the cwd should really be set to the path 
where the application is output. I mean that it's written so. I 
don't know what's happening on your system right now. My 
windows is still win 7 and my dev directory is not in 
ProgramFiles.


Everything worked fine for the last projects but as soon as i 
tried to customize buttons with CSS something is wrong. I just 
store the Coedit-Program in "ProgramFiles" (because every program 
i have installed is located there). For my projects i usually use 
the "document" folder of my user where the ".exe" and ".d" - 
files are stored.


And I've tested using this simple project: 
https://gist.github.com/BBasile/2e110ed48989b53e2a53b57977a81736. You can DL it as a >zip, open the .ce file as a project and click "compile project and run" you should see >the right CWD written in the messages.


I get 'Failed to execute: 267'. Probably because a symbolic 
string is used in the run options?

https://picload.org/upload,8e3f683557a8cd3401f002304f387932.html





Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 07:50:13 UTC, TheDGuy wrote:
I get 'Failed to execute: 267'. Probably because a symbolic 
string is used in the run options?

https://picload.org/upload,8e3f683557a8cd3401f002304f387932.html


That is the correct image link: 
https://img1.picload.org/image/rgwaopli/coedit_run_options.png


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 20:49:02 UTC, Gerald wrote:

On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote:

Hello,
why does this code not work?

RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);

The color of btn_1 just doesn't change.


https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color


Thanks for your reply, i now tried to use CSS instead:

import std.stdio;
import std.file;
import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;

class Window : MainWindow{
this(int width, int height, string title){
super(title);
setDefaultSize(width, height);
Button btn = new Button("Test");
btn.setName("CssName");

string cssPath = "test.css";

CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);

Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


add(btn);
showAll();
}
}

void main(string[] args){
writeln(getcwd());
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}

This is my CSS:
GtkWindow{
background-color:blue;
}
#CssName{
-GtkWidget-focus-line-width:0;
background-color:green;
color:green;
}

The text color is green but the button background color is still 
default-gray!
I am also wondering how it is possible to change the button color 
at runtime? In my opinion i don't think that CSS-based style has 
alot of advantages over the commonly used object functions.


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 13:15:56 UTC, Rene Zwanenburg wrote:
I'm not familiar with Coedit, but the run options seem to 
contain a field for setting it:

https://github.com/BBasile/Coedit/wiki#run-options

You may be able to use the symbolic strings there:
https://github.com/BBasile/Coedit/wiki#symbolic-strings


I changed the working directory in the native project 
configuration in "Pre-build process", "Post-build process" and in 
"Run options" in "default", "debug" and "release" to:


C:\Users\Standardbenutzer\Documents\Dlang_Projects

but i still get:

glib.GException.GException@..\..\..\AppData\Roaming\dub\packages\gtk-d-3.3.1\gtk-d\src\glib\GException.d(40):
 Failed to import: No such file or directory

0x0045C39D
0x00402094
0x00402120
0x00403FC7
0x00403EC8
0x00402557
0x740F38F4 in BaseThreadInitThunk
0x76F85DE3 in RtlUnicodeStringToInteger
0x76F85DAE in RtlUnicodeStringToInteger
error: the process 
(C:\Users\Standardbenutzer\Documents\Dlang_Projects\GTKD_Test.exe) has returned the signal 1






Re: GTKD - Application crashes - or not? [Coedit]

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 10:21:20 UTC, Rene Zwanenburg wrote:

On Wednesday, 15 June 2016 at 09:48:19 UTC, TheDGuy wrote:
But if i execute the app my hand (in the windows command 
window or my double click) it works as expected (so no error)? 
Why is that?


My first guess would be that Coedit does not use the directory 
where the executable is located as working directory. You can 
check what getcwd returns:

https://dlang.org/phobos/std_file.html#.getcwd


Thanks a lot for your answer, getcwd() returns the path where 
coedit is located on my harddrive:

C:\Program Files (x86)\Coedit_32\coedit.2update6.win32

How can i change that?


GTKD - Application crashes - or not? [Coedit]

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

Hi,
this is my app:

import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;
import glib.GException;

class Window : MainWindow{
this(int width, int height, string title){
super(title);
setDefaultSize(width, height);

string cssPath = "test.css";

CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);

Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


showAll();
}
}

void main(string[] args){
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}

I use Coedit to write and execute D apps. If i execute this app i 
get the error message (it compiles fine):


glib.GException.GException@..\..\..\AppData\Roaming\dub\packages\gtk-d-3.3.1\gtk-d\src\glib\GException.d(40):
 Failed to import: No such file or directory

0x00430569
0x00402065
0x004020D8
0x0040275F
0x00402660
0x004020F7
0x740F38F4 in BaseThreadInitThunk
0x76F85DE3 in RtlUnicodeStringToInteger
0x76F85DAE in RtlUnicodeStringToInteger
error: the process 
(C:\Users\Standardbenutzer\Documents\Dlang_Projects\GTKD_Test.exe) has returned the signal 1


But if i execute the app my hand (in the windows command window 
or my double click) it works as expected (so no error)? Why is 
that?


GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

Hello,
why does this code not work?

RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);

The color of btn_1 just doesn't change.


Re: GTKD - Attach Button to Grid in specific column and row

2016-06-14 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 11 June 2016 at 21:14:43 UTC, Mike Wey wrote:
The way GTK manages width and height, usually widgets are given 
the minimum size they need. So when the button is the only 
widget in the grid the other rows and columns have a 
height/width of 0.


You can force the button / gird cell to the bottom left by 
setting the expand and alignment properties of the button.


this(int width, int height, string title){
super(title);
setDefaultSize(width,height);

Button btn = new Button();
btn.setSizeRequest(25,25);
btn.setLabel("Exit");
btn.setVexpand(true);
btn.setHexpand(true);
btn.setHalign(Align.END);
btn.setValign(Align.END);
auto call = 
btn.addOnEnterNotify(call);
btn.addOnLeaveNotify(call);

Grid grid = new Grid();
grid.setColumnSpacing(6);
grid.setRowSpacing(6);
grid.attach(btn,3,3,1,1);
add(grid);

showAll();
}


Thanks for your reply, but now the button is always on the bottom 
right :(


this(int width, int height, string title){
super(title);
setDefaultSize(width,height);

Button btn = new Button();
btn.setSizeRequest(25,25);
btn.setLabel("Exit");
btn.setVexpand(true);
btn.setHexpand(true);
btn.setHalign(Align.END);
btn.setValign(Align.END);

Grid grid = new Grid();
grid.setColumnSpacing(6);
grid.setRowSpacing(6);
grid.attach(btn,4,4,1,1);
add(grid);
showAll();
}


GTKD - Attach Button to Grid in specific column and row

2016-06-11 Thread TheDGuy via Digitalmars-d-learn

Hi,
i am wondering why this code doesn't work, even though i set the 
column and row position of the button it is always placed at the 
top left (so basically first row and first column):


this(int width, int height, string title){
super(title);
setDefaultSize(width,height);

Button btn = new Button();
btn.setSizeRequest(25,25);
btn.setLabel("Exit");
auto call = 
btn.addOnEnterNotify(call);
btn.addOnLeaveNotify(call);

Grid grid = new Grid();
grid.setColumnSpacing(6);
grid.setRowSpacing(6);
grid.attach(btn,3,3,1,1);
add(grid);

showAll();
}


Re: How to cast ASCII value to char?

2016-06-10 Thread TheDGuy via Digitalmars-d-learn

On Friday, 10 June 2016 at 14:27:41 UTC, Seb wrote:

On Friday, 10 June 2016 at 14:20:16 UTC, TheDGuy wrote:

Is it possible to cast an ascii value to char?


Sure!

char A = cast(char) 65; // A
char a = cast(char) 97; // a

and back again:

ubyte b = cast(ubyte) a; // 65

In general there's also an entire module 
(https://dlang.org/phobos/std_ascii.html) that might help you 
for ASCII operations ;-)


Thanks a lot!


Re: How to cast ASCII value to char?

2016-06-10 Thread TheDGuy via Digitalmars-d-learn

On Friday, 10 June 2016 at 14:20:16 UTC, TheDGuy wrote:

Is it possible to cast an ascii value to char?


Yea, basically just like that: cast(char)

*sorry*


How to cast ASCII value to char?

2016-06-10 Thread TheDGuy via Digitalmars-d-learn

Is it possible to cast an ascii value to char?


Re: Easier way to add libraries to visual d?

2016-06-07 Thread TheDGuy via Digitalmars-d-learn

On Friday, 3 June 2016 at 16:20:53 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:


colorize works. You meant "serial-port" ?


Does Coedit have the possibility to debug?


Yes / No?


Re: Easier way to add libraries to visual d?

2016-06-03 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:


colorize works. You meant "serial-port" ?


Does Coedit have the possibility to debug?


Read registry keys recursively

2016-05-29 Thread TheDGuy via Digitalmars-d-learn

Hello,
i am wondering what is wrong with my code:

import std.windows.registry;
import std.stdio;

void main(){
Key lclM = Registry.localMachine();
Key hrdw = lclM.getKey("HARDWARE");
writeRegistryKeys(hrdw);
}

void writeRegistryKeys(Key k){
foreach(Key key; k.keys){
writeRegistryKeys(key.getKey(key.name()));
}
writeln(k.name());
}

i get: 
std.windows.registry.RegistryException@std\windows\registry.d(511): Failed to open requested key: "ACPI"


Even though there is a key called 'ACPI' under 
localmachine/hardware?


Re: Easier way to add libraries to visual d?

2016-05-28 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 28 May 2016 at 15:29:36 UTC, TheDGuy wrote:


Thanks a lot for the fast hot fix, now everything works fine! 
:) Great IDE!


Do you mind implementing an option to reset the layout to 
default? Because i think i messed up and no i don't know how i 
can get the file view for the project (which was originally on 
the left side) back?


Re: Easier way to add libraries to visual d?

2016-05-28 Thread TheDGuy via Digitalmars-d-learn

On Saturday, 28 May 2016 at 13:25:14 UTC, Basile B. wrote:


I've released a hot fix yesterday and now it works with latest 
DUB tag (0.9.25).


But registering from the project that's loaded was already 
working yesterday. I think that you have forgotten to choose 
the right configuration to compile, example with serial-port:


http://imgur.com/7wAwqPz

- open the dub json
- to the left, the DUB inspector: the green arrow must be on a 
config that's dedicated to build the library

- double click to select a config
- compile the project
- to the bottom library manager: click the icon with a book and 
link on the top


Thanks a lot for the fast hot fix, now everything works fine! :) 
Great IDE!


Re: Easier way to add libraries to visual d?

2016-05-27 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 22:15:17 UTC, Basile B. wrote:

gfm doesn't yield a .lib because of this:

https://github.com/d-gamedev-team/gfm/blob/master/dub.json#L22

it should be "library" or staticLibrary or "sourceLibrary"

thus it can't be registered. Bad luck here you've chosen the 
wrong stuff to test.


Okay, i now tried requests and serial-port and with both i have 
the same problem that i can't add them to the library manager.


Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 20:25:43 UTC, Basile B. wrote:
But the procedure I described is very easy. you just have to 
clone, compile and click a button in the library manager. It's 
even better because you can choose which version to compile by 
"git checkout vx.x.x" while using the "DUB button" it's always 
the master version that get fetched (this is a limitation).


I tried this with the gfm-package. I opened the dub.json file as 
a project and clicked 'Compilation'-> 'Compile Project' then it 
did its things:


compiling C:\Users\stduser\Downloads\DUB\GFM\dub.json
Fetching derelict-util 2.0.6 (getting selected version)...
Placing derelict-util 2.0.6 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Fetching derelict-gl3 1.0.18 (getting selected version)...
Placing derelict-gl3 1.0.18 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Fetching derelict-sdl2 1.9.7 (getting selected version)...
Placing derelict-sdl2 1.9.7 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Fetching derelict-assimp3 1.0.1 (getting selected version)...
Placing derelict-assimp3 1.0.1 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Fetching gfm 6.0.2 (getting selected version)...
Placing gfm 6.0.2 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Fetching derelict-fi 2.0.2 (getting selected version)...
Placing derelict-fi 2.0.2 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Fetching colorize 1.0.5 (getting selected version)...
Placing colorize 1.0.5 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...
Performing "plain" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86.

derelict-util 2.0.6: building configuration "library"...
derelict-assimp3 1.0.1: building configuration "library"...
gfm:assimp 6.0.2: building configuration "library"...
gfm:core 6.0.2: building configuration "library"...
derelict-fi 2.0.2: building configuration "library"...
gfm:freeimage 6.0.2: building configuration "library"...
gfm:integers 6.0.2: building configuration "library"...
colorize 1.0.5: building configuration "library"...
gfm:logger 6.0.2: building configuration "library"...
gfm:math 6.0.2: building configuration "library"...
derelict-gl3 1.0.18: building configuration "library"...
gfm:opengl 6.0.2: building configuration "library"...
derelict-sdl2 1.9.7: building configuration "library"...
gfm:sdl2 6.0.2: building configuration "library"...
gfm_test ~master: building configuration "application"...
C:\Users\stduser\Downloads\DUB\GFM\dub.json has been successfully 
compiled


but if i go to 'Windows'->'Library Manager' the book icon is gray 
and not clickable.


https://picload.org/image/rgcccpci/library_manager.png


Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:25:25 UTC, Basile B. wrote:


I'm on Windows now. I'm sorry but both packages were setup 
successfully.


What you can do is the other way:
- clone the git repos.
- open the DUB json as project.
- choose the right config in the inspector.
- compile.
- while the project for the lib to reg is still open, register 
in the library manager using the book-link icon.


You have well version 2 update 5 ?


Yes. So do you have any idea how i could get this to work? It 
would be nice to link libraries directly from the IDE but for the 
time being linking the project manually with the files on my 
harddrive is no problem.


Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:

colorize works. You meant "serial-port" ?


Well, i get the same message for both packages...Even though it 
creates a new folder with all the files in 
AppData\Roaming\dub\packages


Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 16:53:42 UTC, Basile B. wrote:


- Registering a dub package from online is in the "library 
manager"
- The DUB project editor is a widget that's not docked by 
default, see in the menu "Windows", the item "Dub project 
editor".


The Native project configuration and editor is for the native 
project format (which is another format than DUB, just like 
vsprojects are another format).


Thanks, now i found it.

If i try to add for example 'colorize' as a package i get:

Fetching serial-port ~master...
Placing serial-port ~master to 
C:\Users\luc\AppData\Roaming\dub\packages\...


Neither a package description file, nor source/app.d was found in
C:\Users\luc\AppData\Roaming\dub\packages\serial-port-master
Please run DUB from the root directory of an existing package, or 
run

"dub init --help" to get information on creating a new package.

No valid root package found - aborting.
error, failed to compile the package to register




Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:02:06 UTC, TheDGuy wrote:


Thanks, now i found it.

If i try to add for example 'colorize' as a package i get:

Fetching serial-port ~master...
Placing serial-port ~master to 
C:\Users\luc\AppData\Roaming\dub\packages\...


Neither a package description file, nor source/app.d was found 
in

C:\Users\luc\AppData\Roaming\dub\packages\serial-port-master
Please run DUB from the root directory of an existing package, 
or run

"dub init --help" to get information on creating a new package.

No valid root package found - aborting.
error, failed to compile the package to register


I mean 'serial-port', sry.


Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 16:01:22 UTC, Basile B. wrote:
To register a DUB package, you can either fetch (DUB icon) or 
clone the repo, open the DUB JSON project, compile the right 
config, then in the libman there's a icon with a gray chain 
over a book. Click this icon and the library is registered.


Where? I searched for 10 minutes and can't find any DUB button 
besides the dub project editor. If i create a new DUB project it 
looks like that everything is locked (for example native project 
configuration)?





Re: Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:21:40 UTC, Basile B. wrote:


Use Coedit: the widget "library manager" allow to register 
libraries in a single click and then they are usable on the 
fly, in the projects or in a runnable modules, without 
specifying anything (except a (*) in a project setting called 
"libraryAliases".


https://github.com/BBasile/Coedit/wiki#library-manager-widget

It was especially designed because the other IDE suck a bit 
with static libraries.


Thanks for the tip. I downloaded the version for windows from 
github and it works fine so far but if i want to "run compiled 
file" i get the message 'the executino of a runnable module has 
been implicitly aborted" even though i can run the .exe file 
manually without any errors. Do you know how i can run my app 
from out of coedit?


Easier way to add libraries to visual d?

2016-05-26 Thread TheDGuy via Digitalmars-d-learn

Hi,
i use Visual D as a plugin for visual studio to create D 
applications. But what bothers me a bit is that i have to tell 
visual D the exact link to the .lib file for every lib i want to 
use in the project (!).
So these are the steps i have to make to get an external lib 
working:


1. create a new folder in D:\dmd2\src\ with the name of the 
library
2. edit the 'sc.ini' file in D:\dmd2\windows\bin\ and add 
"-I%@P%\..\..\src\[foldername]" under '[Environment]' for every 
lib i want to use

3. add the .lib file to D:\dmd2\windows\lib
4. add the path to the lib in visual studio (project properties 
-> Linker -> General -> Library Files)


Why do i have to do that? Why can i not just use one folder for 
the library files in visual d and the compiler searches the .lib 
files for each library which was imported into the project on its 
own?


Is there an easier way to use libraries?


Re: Use Requests to send data to webpage - how?

2016-05-22 Thread TheDGuy via Digitalmars-d-learn

On Friday, 20 May 2016 at 14:42:19 UTC, TheDGuy wrote:

On Friday, 20 May 2016 at 09:21:33 UTC, Kagamin wrote:

Does this work?

Request rq = Request();
Response rs = rq.exec!"GET"("http://somewebpage.org/;, 
[parameter:data]);


No :(


If i call my SQL.php function directly with:

Response rs = rq.exec!"GET"("http://site/SQL.php;, 
["action":"insertTemp","value":"7"]);


it works perfectly fine. But i don't understand why my html site 
does not get that request...Any ideas?


Re: Use Requests to send data to webpage - how?

2016-05-20 Thread TheDGuy via Digitalmars-d-learn

On Friday, 20 May 2016 at 09:21:33 UTC, Kagamin wrote:

Does this work?

Request rq = Request();
Response rs = rq.exec!"GET"("http://somewebpage.org/;, 
[parameter:data]);


No :(


Use Requests to send data to webpage - how?

2016-05-19 Thread TheDGuy via Digitalmars-d-learn

Hi,
i was sucessfull in installing requests and getting data from a 
webpage like this:


Request rq = Request();
Response rs = rq.exec!"GET"("http://somewebpage.org/SQL.php;, 
["action":"getTemp"]);


But i am not able to send data to the webpage like this:

Request rq = Request();
Response rs = rq.exec!"GET"("http://somewebpage.org;, 
[parameter:data]);


If i just type this:

http://somewebpage.org/?parameter=data

in my browser the webpage reacts as intended but with the 
Requests "GET" nothing happens. Do you know what i do wrong?




Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn
On Wednesday, 18 May 2016 at 19:49:04 UTC, Edwin van Leeuwen 
wrote:
That does mention Windows as supported. It is quite old though, 
the latest github activity is from a year ago.


Got it working, thanks a lot!




Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 20:41:13 UTC, TheDGuy wrote:

C:\Users\Standardbenutzer\Downloads\DUB>dub build
Fetching serial-port 1.1.0 (getting selected version)...
Placing serial-port 1.1.0 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Performing "debug" build using dmd for x86.
serial-port 1.1.0: building configuration "library"...
test ~master: building configuration "application"...
Linking...

C:\Users\Standardbenutzer\Downloads\DUB>cd .dub

C:\Users\Standardbenutzer\Downloads\DUB\.dub>cd build


Oh i am sorry, i see the link now where it was placed.




Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn
On Wednesday, 18 May 2016 at 19:49:04 UTC, Edwin van Leeuwen 
wrote:


The onyx README seems to suggest it only works for POSIX. Did 
you try serial-port by any chance:

http://code.dlang.org/packages/serial-port

That does mention Windows as supported. It is quite old though, 
the latest github activity is from a year ago.


Thanks a lot for your answer.

I built serial-port successfully with Dub but the only thing i 
got is a 'test.exe' and a 'test.obj' file. I don't see any 
library files even though:



C:\Users\Standardbenutzer\Downloads\DUB>dub build
Fetching serial-port 1.1.0 (getting selected version)...
Placing serial-port 1.1.0 to 
C:\Users\Standardbenutzer\AppData\Roaming\dub\packages\...

Performing "debug" build using dmd for x86.
serial-port 1.1.0: building configuration "library"...
test ~master: building configuration "application"...
Linking...

C:\Users\Standardbenutzer\Downloads\DUB>cd .dub

C:\Users\Standardbenutzer\Downloads\DUB\.dub>cd build



Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 16:13:35 UTC, Seb wrote:
May I ask why you need to get tango working? It has been 
deprecated a long time ago and phobos (the standard library) or 
alternatively other packages on dub have a look of features :)


Okay, it looks like 'onyx' is a library which handles serial 
communication in D. So tried to create a new project with DUB and 
add onyx as dependency but there are still some errors:


http://pastebin.com/4eRBt6XX

Any idea what i do wrong?



Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 16:13:35 UTC, Seb wrote:

On Wednesday, 18 May 2016 at 14:59:52 UTC, TheDGuy wrote:
On Wednesday, 18 May 2016 at 14:19:48 UTC, Jacob Carlborg 
wrote:
[1] 
https://github.com/SiegeLord/Tango-D2/blob/d2port/dub.json#L32


How can i get that line working?


May I ask why you need to get tango working? It has been 
deprecated a long time ago and phobos (the standard library) or 
alternatively other packages on dub have a look of features :)


Because the only result google gave me when i searched for "dlang 
serial read" was tango.
If there is another library out there i don't know about and 
which can do serial communication as well i am looking forward to 
it.


Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 14:19:48 UTC, Jacob Carlborg wrote:
[1] 
https://github.com/SiegeLord/Tango-D2/blob/d2port/dub.json#L32


How can i get that line working?


Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 14:19:48 UTC, Jacob Carlborg wrote:


Everything in tango/stdc/posix should be ignored when compiling 
on Windows. Seems like this line isn't working [1], fore some 
reason.


So what should i do? Delete the file?



Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 12:25:47 UTC, John Colvin wrote:


http://code.dlang.org/download


Okay, now i get this:

Performing "debug" build using dmd for x86.
tango ~master: building configuration "static"...
tango\sys\win32\WsaSock.d(31,14): Warning: instead of C-style 
syntax, use D-style syntax 'char[WSADESCRIPTION_LEN + 1] 
szDescription'
tango\sys\win32\WsaSock.d(32,14): Warning: instead of C-style 
syntax, use D-style syntax 'char[WSASYS_STATUS_LEN + 1] 
szSystemStatus'
tango\stdc\posix\unistd.d(31,9): Error: undefined identifier 
'uid_t'
tango\stdc\posix\unistd.d(31,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(43,9): Error: undefined identifier 
'uid_t'
tango\stdc\posix\unistd.d(43,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(44,9): Error: undefined identifier 
'pid_t'
tango\stdc\posix\unistd.d(48,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(49,9): Error: undefined identifier 
'uid_t'
tango\stdc\posix\unistd.d(50,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(51,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(56,9): Error: undefined identifier 
'pid_t'
tango\stdc\posix\unistd.d(57,9): Error: undefined identifier 
'pid_t'
tango\stdc\posix\unistd.d(58,9): Error: undefined identifier 
'pid_t'
tango\stdc\posix\unistd.d(59,9): Error: undefined identifier 
'uid_t'
tango\stdc\posix\unistd.d(66,9): Error: undefined identifier 
'ssize_t', did you mean alias 'size_t'?
tango\stdc\posix\unistd.d(67,9): Error: undefined identifier 
'ssize_t', did you mean alias 'size_t'?
tango\stdc\posix\unistd.d(69,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(70,9): Error: undefined identifier 
'uid_t'
tango\stdc\posix\unistd.d(71,9): Error: undefined identifier 
'gid_t'
tango\stdc\posix\unistd.d(72,9): Error: undefined identifier 
'pid_t'
tango\stdc\posix\unistd.d(72,9): Error: undefined identifier 
'pid_t'

dmd failed with exit code 1.


Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

Oh it looks like Dub is a program i have to install ^^


Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-18 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 18 May 2016 at 03:15:25 UTC, Mike Parker wrote:

That should get your library.


Thanks for your answer. I tried that on my windows console and i 
got the error that the command 'dub' can't be found.


If i try:

'dub.json build' it just opens the dub.json file in my default 
.json program.


The only reason i want to use Tango is that i would like to read 
and send data from/to a serial COM port and i don't want to mess 
around with importing C libraries.





Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-17 Thread TheDGuy via Digitalmars-d-learn
Okay i now have several ".obj" files in 
"Tango-D2-d2port\build\bin\win32" but how can i merge them to a 
library?

Anyone here who knows that?


Re: Compile Tango for DMD2 - Any instructions how to do it?

2016-05-17 Thread TheDGuy via Digitalmars-d-learn

Okay i now got a step further. If i type:
bob -vu C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port

a huge list of files comes down such as:

dmd -c -IC:\Users\Standardbenutzer\Downloads\Tango-D2-d2port 
-release -ofngo-core-Array-release.obj 
C:/Users/Standardbenutzer/Downloads/Tango-D2-d2port/tango/core/Array.d


But at the end i get this:

object.Exception@.\build\src\bob.d(632): Process exited normally 
with return code 1

C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(31):
 Error: undefined identifier 'uid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(31):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(43):
 Error: undefined identifier 'uid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(43):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(44):
 Error: undefined identifier 'pid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(48):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(49):
 Error: undefined identifier 'uid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(50):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(51):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(56):
 Error: undefined identifier 'pid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(57):
 Error: undefined identifier 'pid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(58):
 Error: undefined identifier 'pid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(59):
 Error: undefined identifier 'uid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(66):
 Error: undefined identifier 'ssize_t', did you mean alias 'size_t'?
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(67):
 Error: undefined identifier 'ssize_t', did you mean alias 'size_t'?
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(69):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(70):
 Error: undefined identifier 'uid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(71):
 Error: undefined identifier 'gid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(72):
 Error: undefined identifier 'pid_t'
C:\Users\Standardbenutzer\Downloads\Tango-D2-d2port\tango\stdc\posix\unistd.d(72):
 Error: undefined identifier 'pid_t'

If i take a look in the uninstd.d file it looks like the author 
already imported a file for these datatypes (line 14):
public import tango.stdc.posix.sys.types; // for size_t, ssize_t, 
uid_t, gid_t, off_t, pid_t, useconds_t


but it looks like it is still producing errors - why is that?



Compile Tango for DMD2 - Any instructions how to do it?

2016-05-17 Thread TheDGuy via Digitalmars-d-learn

Hi,

i am wondering if there are any instructions how to build tango 
with dmd2 on windows? I mean, if i take a look at this: 
http://dsource.org/projects/tango/wiki/WindowsInstall


"Automated Build and Install
This section is out of date.

Is there an installer at all?

Manually Build and Install
This is recommended for end users who are installing into an 
existing compiler, and for developers who wish to work on Tango 
itself.


This section is out of date.

???"

Doesn't look like this website is actually up to date?

I tried this:
https://github.com/SiegeLord/Tango-D2

But if i run:

bob.exe -vu .

i get:

"core.exception.AssertError@.\build\src\bob.d(491): 
FileFilter.exclude: Path does not exist: tango/sys/win32"


even though the path is in the same directory. Do i have to add 
an environment variable or something? If so, how should i name it 
so the compiler finds it?


Greets


Re: GTKD - Write Pixbuf back to context

2016-01-08 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 7 January 2016 at 21:35:40 UTC, Gerald wrote:

https://developer.gnome.org/gtkmm-tutorial/stable/sec-draw-images.html.en

Does this work for you?


Yes, thank you very much!

cr.paint();


GTKD - Write Pixbuf back to context

2016-01-07 Thread TheDGuy via Digitalmars-d-learn

Hello,

after i found out how i can access the pixel data in this thread:

http://forum.dlang.org/thread/ljktabqxzdjprrqca...@forum.dlang.org

i want to know how i can write the Pixbuf back to my context?

This code doesn't work because the color does not change:

cr.setSourceRgb(0,0,0);
cr.rectangle(0,0,125,125);
cr.fill();

GtkAllocation size;
Pixbuf surface;
getAllocation(size);
this.width = size.width;
this.height = size.height;

surface = 
getFromSurface(cr.getTarget(),0,0,size.width,size.height);

auto pixelArray = surface.getPixels();
for (int i = 0; i < (this.width*this.height*3);i++){
pixelArray[i] = 125;
}

setSourcePixbuf(cr,surface,0,0);



Re: GTKD Cairo get pixel color

2016-01-05 Thread TheDGuy via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 16:43:00 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 16:25:01 UTC, TheDGuy wrote:

But how do i know which line or column my pixel is in?

- study D operator overloading, I've given you the solution.


And what is 't' in 'opIndexAssign'?
- t is what you want to assign. It can be an uint or maybe a 
float[4]. Look at my bitmap class.


Okay, but what is this?

"import iz.memory, iz.streams, iz.properties;"

I dont' understand what "MemoryStream" is?


Re: GTKD Cairo get pixel color

2016-01-05 Thread TheDGuy via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 16:16:39 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 15:04:57 UTC, TheDGuy wrote:
But i get "only one index allowed to index char". So it looks 
like there is no 2D array but just a char.

If i try like this:


The data is just a contiguous memory area. You have to 
implement your own opIndexAssign()/opIndex() to write/read a 
pixel at [line, column].


This is basically `dataPtr + (line * width + column) * 4`.

---
auto opIndex(size_t line, size_t column)
{
auto ptr = basePtr + (line * width + column) * 4;
// return something at "ptr".
}

void opIndexAssign(T)(auto ref T t, size_t line, size_t column)
{
auto ptr = basePtr + (line * width + column) * 4;
// assign t at "ptr".
}
---

(assuming format is ARGB, so 32bit, so "*4").


But how do i know which line or column my pixel is in? And what 
is 't' in 'opIndexAssign'?


Re: GTKD Cairo get pixel color

2016-01-05 Thread TheDGuy via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 17:34:06 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 17:16:10 UTC, TheDGuy wrote:

On Tuesday, 5 January 2016 at 16:43:00 UTC, Basile B. wrote:

[...]


Okay, but what is this?

"import iz.memory, iz.streams, iz.properties;"

I dont' understand what "MemoryStream" is?


MemoryStream is a managed pointer with methods to read and 
write at a particlular postion. In the Bitmap class I often 
refer to .memory which is just the managed pointer.


- iz.properties is used to anotate what has to be serialiazed 
or not and it's pointless here (@Set @Get).
- iz.memory is just imported because I use (construct!T) 
instead of "new" to allocate a class instance.


But these are implementation details. Just try to imagine that 
you manage the bitmap data yourself with realloc/free...


No offense, but why is the same thing done in 3 lines in C++ but 
needs 200 lines in D?


Re: GTKD Cairo get pixel color

2016-01-05 Thread TheDGuy via Digitalmars-d-learn

On Monday, 4 January 2016 at 23:47:05 UTC, Basile B. wrote:

On Friday, 1 January 2016 at 22:00:04 UTC, TheDGuy wrote:

On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote:
On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. 
wrote:
On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy 
wrote:

Hello,

is there any way to get the pixel color of a single pixel 
by x and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same 
time, to blit your buffer to screen.



Actually I was thinking to a user defined buffer type:

struct SurfaceBuffer
{
void* data; // used as param to create the surface
Rgba[] opIndex(size_t index);
Rgba[][] scanline();
}

that you would pass as data in 
cairo_image_surface_create_for_data().


But gtk certainly has pitcure classes with the typical 
scanline method and that you could use in 
cairo_image_surface_create_for_data.


Ahm, i am not quite sure if you and [Mike Wey] talk about the 
same thing. And i posted the error message in my last post 
when i try to call "cairo_image_surface_create_for_data". I 
still don't know where i am able to call the function?


I've not followed the conversation since last time, but you can 
have a look at this:


https://github.com/BBasile/kheops/blob/master/src/kheops/bitmap.d#L143

this is how I do with Cairo only (even x11 is not implied since 
it's just a bitmap).
Then I can access pixels (for example to make shadows or blurs 
etc.) and do vectorial drawings as well with a context for the 
bitmap surface.


I tried it like in this C++ example:

http://stackoverflow.com/questions/16785886/get-pixel-value-on-gdkpixbuf-set-pixel-value-with-gdkcairo

surface = 
getFromSurface(cr.getTarget(),0,0,size.width,size.height);
int offset = 12*surface.getRowstride() + 
12*surface.getNChannels();

auto px = surface.getPixels();
px[offset][0] = 0;

But i get "only one index allowed to index char". So it looks 
like there is no 2D array but just a char.

If i try like this:

auto px = surface.getPixels()[offset];

the value of 'px' looks like this in the debugger:

http://www.pic-upload.de/view-29334489/d_value.png.html




Re: GTKD Cairo get pixel color

2016-01-05 Thread TheDGuy via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 22:02:33 UTC, Mike Wey wrote:

On 01/04/2016 11:08 PM, TheDGuy wrote:

On Monday, 4 January 2016 at 21:42:16 UTC, Mike Wey wrote:

[...]


Ups, that was my fault, sry :(

But how do i get now the color for each pixel out of the 
ubyte[]?


It looks like the array has the R, G and B values like this:

[R, G, B, R, G, B, R, G, B, R, G, B, ...]

for every pixel from left to right top to bottom,
So data[0] gives you the Red value for the pixel at 0,0.
data[1] the Blue value and data[2] the green value.
data[3] would then be Red for pixel 1,0.


Thats it, thank you very much!


Re: GTKD Cairo get pixel color

2016-01-04 Thread TheDGuy via Digitalmars-d-learn

On Monday, 4 January 2016 at 19:27:48 UTC, Mike Wey wrote:

I think you are looking for something like this.

Context.getTarget will get you the surface the Context is 
drawing to, this most likely isn't a ImageSurface.
So you will need to create an pixbuf from the returned surface, 
with the Pixbuf you can then get the raw pixel data using 
getPixelsWithLength().


```
import gdk.Pixbuf;

bool drawCallback(Scoped!Context cr, Widget widget)
{
GtkAllocation size;
Pixbuf surafce;

getAllocation(size);

//Draw something;

surface = getFromSurface(cr.getTarget(), 0, 0, size.width, 
size.height);


ubyte[] data = cast(ubyte[])surface.getPixelsWithLength();

//Do somthing with data.

return true;
}
```

getPixelsWithLength has the wrong return type, which will 
probably be fixed some time.


Thank you very much! But surface.getPixelsWithLength() only gives 
me an array with 16 fields (with a 256x256 DrawingArea)?


I also tried to save the Pixbuf with:

string[] options = ["quality"];
string[] opval = ["100"];
surface.savev("C:\\Users\\Standardbenutzer\\Desktop\test.jpeg", 
"jpeg", options, opval);


but i found absolutely NOTHING about the options or the option 
values i have to set, therefore i get an invalid argument 
exception :(


Re: GTKD Cairo get pixel color

2016-01-04 Thread TheDGuy via Digitalmars-d-learn

On Monday, 4 January 2016 at 21:42:16 UTC, Mike Wey wrote:

On 01/04/2016 09:13 PM, TheDGuy wrote:

[...]


I don't have any issues with either getPixelsWithLength and 
savev.
for the savev call there is an missing \ just before test.jpg, 
but that might be a copy and paste error?


For the options that are available for savev the documentation 
of GDK-PixBuff lists the few available options.

https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-File-saving.html#gdk-pixbuf-save

Although i'm on Linux so that might make an difference.


Ups, that was my fault, sry :(

But how do i get now the color for each pixel out of the ubyte[]?


Threading to prevent GUI Freeze

2016-01-04 Thread TheDGuy via Digitalmars-d-learn

Hello,

i use GTKD to draw some stuff on a DrawingArea. Because it needs 
some time to calculate i want to outsource those calculation so 
that the GUI doesn't freeze.


I tried it with "std.concurrency" like this:

bool drawCallback(Scoped!Context cr, Widget widget){
writeln("init");
spawn(, cr, widget);
return true;
}

void render(Context cr, Widget widget){
	Renderer renderer = new Renderer(new Vector3D(0,0,0), cr, 
widget);

int  i = 0;
while(i < 4){
renderer.renderOneStep();
i++;
}
renderer.DisplayResult();
}

But i get:

"std.concurrency.spawn(F, T...)(F fn, T args) 
if(isSpawnable!(F,T))"
"Error: template std.concurrency.spawn cannot deduce function 
from argument types!()(void delegate(Context cr, Widget widget), 
Scoped Widget), candidates are:"


Re: Threading to prevent GUI Freeze

2016-01-04 Thread TheDGuy via Digitalmars-d-learn

On Monday, 4 January 2016 at 15:07:12 UTC, Luis wrote:

On Monday, 4 January 2016 at 14:31:04 UTC, TheDGuy wrote:

[...]



Before doing anything with threads and GTK, you should read 
this : 
http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness


Okay, so i have to do it like this on every function i use from 
GTKD?


threadsInit();
threadsEnter();
GtkAllocation size;
widget.getAllocation(size);
threadsLeave();


Re: Threading to prevent GUI Freeze

2016-01-04 Thread TheDGuy via Digitalmars-d-learn
I wrote a demo for GtkD showing how multi-threading and D work 
together, it's in the demos/gtkD/DemoMultithread folder of 
GtkD, hopefully it will be helpful. However this example it is 
based on using the GTk threadIdle callback which is generally 
preferred over the locking methods you show above, obviously 
though your use case may vary but keep in mind the locking 
methods have been deprecated, see the GTK 3 reference manual 
here:


https://developer.gnome.org/gdk3/stable/gdk3-Threads.html

You also see this GtkD issue here for 
https://github.com/gtkd-developers/GtkD/issues/137 for some 
code on how to use Delgates with gdk_threads_add_idle (i.e. 
GtkD gdk.Threads.threadsAddIdle).


Thanks for your example code. Do i need those extern (C) 
function? Why is it not possible to write the value to the 
TreeView in D?





Re: Threading to prevent GUI Freeze

2016-01-04 Thread TheDGuy via Digitalmars-d-learn

On Monday, 4 January 2016 at 17:33:28 UTC, Gerald wrote:

On Monday, 4 January 2016 at 16:13:50 UTC, TheDGuy wrote:

[...]


Yes, you need it. The extern (C) function is what GDK invokes 
on idle. In any GUI application there is a lot of idle time 
waiting for events, what the addThreadIdle allows you to do is 
take advantage of this and tell GTK that whenever it's sitting 
around doing nothing, give this function a call.


[...]


Okay, thanks alot for your help. I think i will need some time to 
understand this but one last question:


Do the errors come from the fact at i didn't use those GTK thread 
mechanisms or that my function is not "spawnable"?


"std.concurrency.spawn(F, T...)(F fn, T args) 
if(isSpawnable!(F,T))"
"Error: template std.concurrency.spawn cannot deduce function 
from argument types!()(void delegate(Context cr, Widget widget), 
Scoped Widget), candidates are:"


Re: Call C function - Access violation

2016-01-03 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 3 January 2016 at 21:20:35 UTC, anonymous wrote:

On 03.01.2016 21:32, TheDGuy wrote:

If i type:
gcc -c -otest.c.o

the 'test.c.o' file is generated but if i type:

dmd main.d test.c.o i get: 'Error: unrecognized file extension 
o'?


You're probably on Windows then? dmd doesn't recognize the .o 
extension on Windows, use .obj instead.


If i rename "test.o" to "test.obj" i get:

'Error: Module or Dictionary corrupt'



Re: Call C function - Access violation

2016-01-03 Thread TheDGuy via Digitalmars-d-learn


Use an import.

import std.string;
import std.conv;

void main(string[] args) {
auto value  = toStringz("Hello World");
auto result = write(value);
auto s  = to!(string)(result);
writeln(s);
}

Also all string literals in D are zero terminated so you could 
write the call like this:


auto result = write("Hello World");


Okay, thank you very much!

But now i get the access violation error again.

If i type:
gcc -c -otest.c.o

the 'test.c.o' file is generated but if i type:

dmd main.d test.c.o i get: 'Error: unrecognized file extension o'?


Call C function - Access violation

2016-01-03 Thread TheDGuy via Digitalmars-d-learn

I get an access violation with this code:

extern(C) char* write(char* text);

void main(string[] args){
char[] text = "Hello World".dup; //.dup converts string to char[]
text ~= '\0'; //append

char* result = write(text.ptr); //you need .ptr
const(char)[] s = cstr2dstr(result);
writeln(s);
readln(); //keep the window open
}

auto cstr2dstr(inout(char)* cstr)
{
return cstr ? cstr[0 .. strlen(cstr)] : "";
}

--

#include std.stdio;

char* write(char* text){
return text;
}



Re: Call C function - Access violation

2016-01-03 Thread TheDGuy via Digitalmars-d-learn


Works for me after adding the needed imports and removing the 
wrong include from the C file. Is this really the actual code 
you're running? Doesn't your C compiler reject that include? 
gcc does.


Okay, i think this C code should work (checked with cpp.sh):

#import 
char* write(char* text){
return text;
}
int main(void){
return 0;
}


but i still get the access violation.




Re: Call C function - Access violation

2016-01-03 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 3 January 2016 at 13:25:04 UTC, Gary Willoughby wrote:
On Sunday, 3 January 2016 at 13:23:25 UTC, Gary Willoughby 
wrote:
I think I've noticed one problem with the code above. You are 
using `text.ptr`. You shouldn't do that because you are 
passing a pointer not an array. Just use `text`.


Forget this line, my mistake. Use `toStringz` and pass a 
pointer instead of an array.


Hi and thanks for your answer. My code looks now like this:

void main(string[] args){
const(char)* val = "Hello World".std.string.toStringz;
char* result = write(val);
const(char)[] s = cstr2dstr(result);
writeln(s);
readln(); //keep the window open
}

But now i get the error: "function expected before(), not package 
std of type void" (refering to line 2).


And if i define the variable 'value' as 'const(char)*' i also 
have to rewrite my C-function to accept const(char)*...


Re: GTKD Cairo get pixel color

2016-01-02 Thread TheDGuy via Digitalmars-d-learn

```
import cairo.ImageSurface;
ImageSurface.createForData(c,cairo.FORMAT_ARGB32,256,256,256*4);
```

You need to import the ImageSurface module, and the 
createForData function is in the ImageSurface class which is in 
the cairo.ImageSurface module.


Thanks, that was the problem!

Now i can read the buffer from a png image and save the buffer as 
a file:


		auto pngImage = 
ImageSurface.createFromPng("C:\\Users\\Standardbenutzer\\Desktop\\DSC00564-1.png");

auto buffer = pngImage.getData();
		auto cS = ImageSurface.createForData(buffer, 
cairo_format_t.ARGB32,pngImage.getWidth(),pngImage.getHeight(),pngImage.getStride());

cS.writeToPng("test.png");

but how do i do that with my GTKD Context in my "drawCallback()" 
function?


Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

On Friday, 1 January 2016 at 22:00:04 UTC, TheDGuy wrote:

On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote:
On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. 
wrote:

On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:

Hello,

is there any way to get the pixel color of a single pixel by 
x and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same time, 
to blit your buffer to screen.



Actually I was thinking to a user defined buffer type:

struct SurfaceBuffer
{
void* data; // used as param to create the surface
Rgba[] opIndex(size_t index);
Rgba[][] scanline();
}

that you would pass as data in 
cairo_image_surface_create_for_data().


But gtk certainly has pitcure classes with the typical 
scanline method and that you could use in 
cairo_image_surface_create_for_data.


Ahm, i am not quite sure if you and [Mike Wey] talk about the 
same thing. And i posted the error message in my last post when 
i try to call "cairo_image_surface_create_for_data". I still 
don't know where i am able to call the function?


I took a look into the source code of cairo and in the 
"ImageSurface.d"-file there is a function called "createForData" 
but if i try to use it like this:


cairo.ImageSurface.createForData(c,cairo.FORMAT_ARGB32,256,256,256*4);

i get: "undefined identifier 'createForData' in module 
'cairo.ImageSurface'


That is just one example of my experience using D:

some things are easy to understand but in other cases: even if 
you think it should work and you can proof it, it just doesn't or 
you have to do it in a really inconvenient way. I am getting 
frustrated


Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote:

On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote:

On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:

Hello,

is there any way to get the pixel color of a single pixel by 
x and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same time, 
to blit your buffer to screen.



Actually I was thinking to a user defined buffer type:

struct SurfaceBuffer
{
void* data; // used as param to create the surface
Rgba[] opIndex(size_t index);
Rgba[][] scanline();
}

that you would pass as data in 
cairo_image_surface_create_for_data().


But gtk certainly has pitcure classes with the typical scanline 
method and that you could use in 
cairo_image_surface_create_for_data.


Ahm, i am not quite sure if you and [Mike Wey] talk about the 
same thing. And i posted the error message in my last post when i 
try to call "cairo_image_surface_create_for_data". I still don't 
know where i am able to call the function?


Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

writeln("Which number should i guess?");
string input = readln();
int i = to!int(input);


Re: Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

On Friday, 1 January 2016 at 14:29:34 UTC, Tobi G. wrote:

On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote:
The solution is that readln() returns a string that also 
contains the newline

this can be solved by easily stripping the newline off

import std.string;

int i = to!int(input.strip);


Sorry my bad english.. i wrote solution but meant problem


Thank you very much! That helped me alot. It is kind of hard if 
you don't have the background knowledge...


Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote:

On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:

Hello,

is there any way to get the pixel color of a single pixel by x 
and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same time, 
to blit your buffer to screen.


Thanks for your answer. But how do i access the function via the 
context?


It does not work like this:

class DW:DrawingArea{
this(){
addOnDraw();
}
bool drawCallback(Scoped!Context cr, Widget widget){
char[] c = new char[](256*256);
		auto val = 
cr.cairo_image_surface_create_for_data(c,cairo_format_t.CAIRO_FORMAT_ARGB32, 256,256, cairo.format_stride_for_width(cairo_format_t.CAIRO_FORMAT_ARGB32,256));

return true;
}
}
"no property 'cairo_image_surface_create_for_data' for type 
'Scoped'"


Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

On Friday, 1 January 2016 at 15:22:18 UTC, Mike Wey wrote:

On 01/01/2016 01:37 PM, TheDGuy wrote:

[...]


you would either cr.getTarget(); or 
cairo.ImageSurface.ImageSurface.create.


I'm not sure how those would get you access to the pixel data.


Okay, thanks for your answer.

So which function do i call with "cr.getTarget()" and how can i 
get the rgb-values of a pixel from it?


Re: Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn

On Friday, 1 January 2016 at 15:16:36 UTC, Adam D. Ruppe wrote:

On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote:
I've battled with a few times, not having any idea what was 
going on. I now almost automatically use strip when it's not 
working.


This is one of the most frequently asked questions by new 
users.. I added a tip to my new docs:


http://dpldocs.info/experimental-docs/std.stdio.readln.html

If you were looking at that for the first time, would you 
notice it? If no, I can see about moving it or rewording it or 
something.


If i had known that blog existed. I think your example at the end 
of the page explains the problem really well.

Thanks!


GTKD Cairo get pixel color

2015-12-30 Thread TheDGuy via Digitalmars-d-learn

Hello,

is there any way to get the pixel color of a single pixel by x 
and y coordinates of a context?


Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread TheDGuy via Digitalmars-d-learn
Get used to it :) Unfortunately, DMD is not emitting the best 
debug information. The program flow is correct, but the line 
info is not, that's why the execution step will not be 
triggered in the real location of the source code.


The simplest example is this:

import std.stdio;

void foo(int x)
{
if (x > 0)  //step 1, correct
{
writeln("bigger");  //step 2, correct
}
else
{
writeln("lower");   //step 3, wrong
}
}

int main(string[] argv)
{
foo(20);   //breakpoint with step in
return 0;
}

If you really want to confuse the debugger, write some asserts 
or contracts here and there and your program will be impossible 
to debug :)


So, do you have any information if there will be a fix to this? 
It is really hard (at least for me) to work with a language which 
doesn't feature a working debugger...


Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 27 December 2015 at 16:39:18 UTC, SimonN wrote:

On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote:

Sry:
if((x1 < 0) & (x2 >= 0)){


This looks like a bug, with & instead of &&.

-- Simon


It looks like the debugger is not working correctly because i 
changed the code to this:


if(discriminant > 0){
double x1 = (-b - sqrt(discriminant)) / (2.0*a);
double x2 = (-b + sqrt(discriminant)) / (2.0*a);
if((x1 >= 0) && (x2 >= 0)){
return x1;
}
if((x1 < 0) && (x2 >= 0)){
return x2;
}
return -1.0;
} else{
return -1.0;
}

and the same problem appears.


  1   2   >