Customize TDBNavigator buttons in C++ builder - database

Is there a way how to add caption to a TDBNavigator button in C++ builder ?

This will allow you to add captions to each button in c++ builder
char *btntext[11] = {"First","Prior","Next","Last","Insert","Delete","Edit","Post","Cancel","Refresh","Apply"};
for(int x = 0; x < nav->ComponentCount; ++x)
{
TNavButton* navbutton = dynamic_cast<TNavButton *>( nav->Components[ x ] );
if( navbutton )
{
navbutton->Font->Name = "Arial";
navbutton->Font->Size = 8;
navbutton->Caption = btntext[x];
navbutton->Spacing = 0;
navbutton->Layout = blGlyphTop;
}
}

here you have a full example of how to do it
http://delphi.about.com/od/usedbvcl/l/aa090203a.htm
it is written in Delphi, but the code can easily adapted to c++ builder.

Related

How to implement Steps progress bar in Codenameone?

I would be grateful for any hints/examples on how to create a Steps Progress Bar using Codenameone and similar to:
https://github.com/YablokovDmitry/StepViewPager
You can just use toggle buttons to represent every step in either box or flow layout. Roughly something like this (didn't test it):
public Container createSteps(String[] labels, ActionListener[] actions) {
Container cnt = new Container(BoxLayout.x();
CheckBox[] steps = new CheckBox[labels.length];
for(int iter = 0 ; iter < steps.length ; iter++) {
steps[iter] = CheckBox.createToggle(labels[iter]);
steps[iter].setTextPosition(BOTTOM);
steps[iter].setMaterialIcon(FontImage.MATERIAL_CHECK_CIRCLE);
steps[iter].addActionListener(actions[iter]);
steps[iter].addActionListener(e -> {
for(int x = 0 ; x < steps.length ; x++) {
if(x != iter) {
steps[x].setSelected(x < iter);
}
}
});
if(iter > 0 && iter < steps.length - 1) {
cnt.add(new Label("---"));
}
cnt.add(steps[iter]);
}
return cnt;
}
You can determine the color via styling on the pressed and default styling. You can also have the loop above customize things like different icons for every stage.

Having an issue figuring out where to do calculations before using Upsert in mongodb

I'm using the angular-fullstack generator so there's 7 files in one endpoint (index, index.spec, orders.controller, orders.events, orders.integration, orders.model, and orders.socket). I'm not sure where to do computation to store in the fields when there is a PUT/Upsert. All the examples that I can google either use virtual fields or have generic code to do the computation. I know the computation I need to do but have no idea where to put it using this generator.
After a bit more searching this morning, I think what I want is to use getters/setters?
It's working in the controller as I presumed but i'm not sure if it's the best place to put these simple
function doCalcsSingle(res) {
var tOrderitems = 0;
var tRecitems = 0;
var tMissingitems = 0;
var today = new Date();
for(var i = 0; i < res.body.items.length; i++) {
res.body.items[i].missingItems = res.body.items[i].numOfOrdItems - res.body.items[i].numOfRecItems;
if(res.body.items[i].missingItems < 0 || !res.body.items[i].missingItems) {
res.body.items[i].missingItems = 0;
}
res.body.items[i].totalPrice = res.body.items[i].numOfOrdItems * res.body.items[i].unitPrice;
tOrderitems = tOrderitems + res.body.items[i].numOfOrdItems;
tRecitems = tRecitems + res.body.items[i].numOfRecItems;
tMissingitems = tMissingitems + res.body.items[i].missingItems;
if(tMissingitems < 0 || !tMissingitems) {
tMissingitems = 0;
}
}
res.body.totalOrdItems = tOrderitems;
res.body.totalRecItem = tRecitems;
res.body.totalItemsMissing = tMissingitems;
res.body.lastUpdated = today;
if(tMissingitems <= 0) {
res.body.activeOrder = false;
res.body.completedDate = today;
} else {
res.body.activeOrder = true;
}
return res;
}

Google sheets code for arrays

I'm trying to get a code to work to calcualte average true range. So in the spreadsheet side I have
=getATR(GoogleFinance("stock", ʺallʺ, today()-60,today()))
And the code for the app is below. However I keep getting this TypeError: cannot set property "0.0" of undefined to "7.1". The line with the problem is the first instance where trurange[i][0] is called.
Appreciate your help with this, seems something silly on the syntax side.
function getATR(arr) {
var atr = 0;
var truerange = [];
var i=39;
for (var row = arr.length-1; row >= arr.length-40; row--) {
truerange[i][0] = arr[row][3] - arr[row][4];
truerange[i][1] = Math.abs( arr[row][3] - arr[row-1][2] );
truerange[i][2] = Math.abs( arr[row][4] - arr[row-1][2] );
truerange[i][3]= Math.max(truerange[i][0],truerange[i][1],truerange[i][2]);
i=i-1;
}
for(var row2 = 1; row2<40; row2++){
truerange[row2][4] = (truerange[row2-1][4]*13+truerange[row2][3])/14;
if(row2=39) {atr = truerange[row2][4]}
}
return atr;
}
Browser: ie9
Operating System: win7
Drive on the Web / Drive for desktop: Web
I am looking for a 6 day SMA of ATR. This code works for me
function getATR(arr) {
arr[1][9] = Math.abs( arr[1][2] - arr[1][3] )
for (var row = 2; row < 41; row++)
{
arr[row][6] = arr[row][2] - arr[row][3];
arr[row][7] = Math.abs( arr[row][2] - arr[row-1][4] );
arr[row][8] = Math.abs( arr[row][3] - arr[row-1][4] );
arr[row][9] = Math.max(arr[row][6],arr[row][7],arr[row][8]);
if (row>6) { arr[row][10] = (arr[row-5][9]+arr[row-4][9]+arr[row-3][9]+arr[row-2][9]+arr[row-1][9]+arr[row][9])/6 }
}
return arr[40][10];
}

HTML5 Canvas -- Drawing a game level, overlapping previously drawn rectangles

I've been hacking away at this problem for the past three hours and cannot figure out where I went wrong. Basically, I'm trying to draw a tile-based "level" for a little game. As I understand it, the canvas should draw new rectangles on rectangles that have already been drawn.
I want to set it up so that there is one function that basically draws the background, and another function that draws the highlights on top of it. The "highlights" are the top of a wall, and the background shows the side of it. I want to draw the highlights on top because ideally I'd eventually like to draw a character in between them so the highlights would be on top of the character (as though it is behind the wall) while the background would be behind the character.
The background and shape of the level (without the highlight layer) looks like this: http://howtivity.com/leveldrawing
For some reason, I run into a lot of trouble trying to draw the highlights layer. I want to offset the layer 50px above the background layer to give the impression of a three dimension wall, and I want any blank spaces where there is no wall to be transparent so the background still shows. When I try drawing the layer with an almost identical function whose only difference is offsetting the layer 50px upward and set the no-wall fillStyle to transparent, it looks like this: http://howtivity.com/leveldrawing/highlight.html
I've set it up to print text so I could diagnose where it might be wrong, but the text has shown up correctly. I feel like I either misunderstood something about how the canvas is drawn, or have made some kind of error that I'm just not seeing.
<canvas height="600" width="1000" style="position: absolute; z-index: 0; background: transparent;" id="background">
</canvas>
<script>
var level =
[
[1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,1,0,0],
[1,0,1,0,1,1,0,1,0,1],
[0,0,0,0,0,1,0,0,0,1],
[1,0,0,0,0,0,0,1,1,1],
[1,1,1,1,1,1,1,1,1,1]
];
var bg = document.getElementById("background");
var bgContext = bg.getContext("2d");
var drawLevel = function() {
var levelDrawX = 0;
var levelDrawY = 0;
for (levelRow = 0; levelRow < 6; levelRow++)
{
for (levelCol = 0; levelCol < 10; levelCol++)
{
levelDrawX = (100 * levelCol);
if (level[levelRow][levelCol]==1)
{
bgContext.fillStyle = "#ffe680";
bgContext.fillRect(levelDrawX, levelDrawY, levelDrawX + 100, levelDrawY + 100);
} else {
bgContext.fillStyle = "#8dd35f";
bgContext.fillRect(levelDrawX, levelDrawY, levelDrawX + 100, levelDrawY + 100);
}
}
levelDrawY += 100;
}
};
var drawHighlights = function() {
var levelDrawX = 0;
var levelDrawY = 0;
for (levelRow = 0; levelRow < 6; levelRow++)
{
for (levelCol = 0; levelCol < 10; levelCol++)
{
levelDrawX = (100 * levelCol);
if (level[levelRow][levelCol]==1)
{
bgContext.fillStyle = "#000";
} else {
bgContext.fillStyle = "transparent";
}
bgContext.fillRect(levelDrawX, levelDrawY-50, levelDrawX+100, levelDrawY+50);
}
levelDrawY += 100;
}
};
drawLevel();
drawHighlights();
Any help would be really appreciated! Thank you!
I admit to being a bit confused about what you want in your finished design.
Do you want your drawHighlights() to add a semi-transparent "shadows" to your drawLevel()?
If so, you can do that by setting the context's globalAlpha which is the level of opacity.
var drawHighlights = function() {
var levelDrawX = 0;
var levelDrawY = 0;
bgContext.globalAlpha=0.8;
for (levelRow = 0; levelRow < 6; levelRow++)
{
for (levelCol = 0; levelCol < 10; levelCol++)
{
levelDrawX = (100 * levelCol);
if (level[levelRow][levelCol]==1)
{
bgContext.fillStyle = "#777";
} else {
bgContext.fillStyle = "transparent";
}
//bgContext.fillText(levelCol, levelCol*100, 10+levelRow*100);
bgContext.fillRect(levelDrawX, levelDrawY-50, levelDrawX+100, levelDrawY+50);
}
levelDrawY += 100;
}
bgContext.globalAlpha=1.0;
};
My mistake was with the values required by fillRect.
I had typed them as if they were:
fillRect(startX, startY, endX, endY);
when actually they are:
fillRect(startx, starty, width, height);

How can I prevent this arbitrary text truncation in AS3

Below is code that populates a menu. Everything seems to work great, with no errors thrown, except for one crucial part. My megaPages array has the values ["HOME","BABIES","BRIDALS","MISC","WEDDINGS","ABOUT"], but the actual text that displays on screen (which is produced by megaPages) is like this:
As you can see, some of the text is arbitrarily being truncated. I've traced the text strings as they get passed through the various functions at various stages of the menu-build, and they are always right, but somehow when each DisplayObject make it on screen, letters get ommitted (notice though that 'HOME' abd 'ABOUT' are fine). I don't even know where to start with this problem.
function buildMenu() {
var itemMCs = new Array();
for (var i = 0; i < megaPages.length; i++) {
megaPages[i] = megaPages[i].toUpperCase();
trace(megaPages[i]); // at each iteration, traces as follows "HOME","BABIES","BRIDALS","MISC","WEDDINGS","ABOUT"
var textMC = createText(megaPages[i]);
var itemMC = new MovieClip();
if (i!=0) {
var newLink = new PlateLink();
newLink.y = 0;
itemMC.addChild(newLink);
}
var newPlate = new Plate();
if (i==0) {
newPlate.y = 0;
} else {
newPlate.y = newLink.height - 2;
}
newPlate.x = 0;
newPlate.width = textMC.width + (plateMargin*2);
itemMC.addChild(newPlate);
if (i!=0) {
newLink.x = (newPlate.width/2) - (newLink.width/2);
}
textMC.x = plateMargin;
textMC.y = newPlate.y + .5;
itemMC.addChild(textMC);
itemMCs.push(itemMC);
itemMC.x = (homeplateref.x + (homeplateref.width/2)) - (itemMC.width/2);
if (i==0) {
itemMC.y = homeplateref.y;
} else {
itemMC.y = itemMCs[i-1].y + (itemMCs[i-1].height - 6);
}
menuRef.addChild(itemMC);
}
}
function createText(menuTitle) {
trace(menuTitle);
var textContainer : MovieClip = new MovieClip();
var myFont = new Font1();
var backText = instantText(menuTitle, 0x000000);
backText.x = 1;
backText.y = 1;
var frontText = instantText(menuTitle, 0xFFFFFF);
frontText.x = 0;
frontText.y = 0;
textContainer.addChild(backText);
textContainer.addChild(frontText);
return textContainer;
}
function instantText(textContent, color) {
trace(textContent); // again, traces the right text each time it is fired
var myFont = new Font1();
var myFormat:TextFormat = new TextFormat();
myFormat.size = 18;
myFormat.align = TextFormatAlign.CENTER;
myFormat.font = myFont.fontName;
var myText:TextField = new TextField();
myText.defaultTextFormat = myFormat;
myText.embedFonts = true;
myText.antiAliasType = AntiAliasType.ADVANCED;
myText.text = textContent;
myText.textColor = color;
myText.autoSize = TextFieldAutoSize.LEFT;
trace(myText.text);
return myText;
}
You need to embed all the necessary characters for the font you're using.
For textfields created in Flash:
Select the TextField, and hit the 'Embed' button in the properties panel.
For dynamically created textfields:
When you set the font to export (Font1 in your case) make sure to include all the characters you need.
You can choose to embed all uppercase characters, or just type in the ones you need for those specific menu items.

Resources